Loading handlers/token_collector/xasm/xasm_single_visitor.hpp +3 −1 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ class xasm_single_visitor : public xasm::xasm_singleVisitor { // Get the qubit expresssions std::vector<std::string> buffer_names; int count = 1; for (int i = 0; i < required_bits; i++) { auto bit_expr = context->explist()->exp(i); auto bit_expr_str = bit_expr->getText(); Loading @@ -82,9 +83,10 @@ class xasm_single_visitor : public xasm::xasm_singleVisitor { inst->setBitExpression(i, bit_idx_expr); } else { // Indicate this is a qubit(-1) or a qreg(-2) inst->setBitExpression(-1, bit_expr_str); inst->setBitExpression(-1*count, bit_expr_str); buffer_names.push_back(bit_expr_str); } count++; } inst->setBufferNames(buffer_names); Loading runtime/CMakeLists.txt +0 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ file(GLOB HEADERS qcor.hpp kernel/quantum_kernel.hpp objectives/objective_function.hpp execution/taskInitiate.hpp #utils/eigen_qcor_unitary_addon.hpp utils/qcor_utils.hpp) install(FILES ${HEADERS} DESTINATION include/qcor) Loading runtime/kernel/quantum_kernel.hpp +37 −2 Original line number Diff line number Diff line Loading @@ -412,4 +412,39 @@ class KernelSignature { } }; template <typename Derived> using OneQubitKernel = QuantumKernel<Derived, qubit>; template <typename Derived> using TwoQubitKernel = QuantumKernel<Derived, qubit, qubit>; #define ONE_QUBIT_KERNEL_CTRL_ENABLER(CLASSNAME, QRTNAME) \ class CLASSNAME : public OneQubitKernel<class CLASSNAME> { \ public: \ CLASSNAME(qubit q) : OneQubitKernel<CLASSNAME>(q) {} \ CLASSNAME(std::shared_ptr<qcor::CompositeInstruction> _parent_kernel, qubit q) \ : OneQubitKernel<CLASSNAME>(_parent_kernel, q) { throw std::runtime_error("you cannot call this.");} \ void operator()(qubit q) { \ parent_kernel = \ qcor::__internal__::create_composite("__tmp_one_qubit_ctrl_enabler"); \ quantum::set_current_program(parent_kernel); \ if (runtime_env == QrtType::FTQC) { \ quantum::set_current_buffer(q.results()); \ } \ ::quantum::QRTNAME(q); \ return; \ } \ virtual ~CLASSNAME() {} \ }; ONE_QUBIT_KERNEL_CTRL_ENABLER(X, x) ONE_QUBIT_KERNEL_CTRL_ENABLER(Y, y) ONE_QUBIT_KERNEL_CTRL_ENABLER(Z, z) ONE_QUBIT_KERNEL_CTRL_ENABLER(H, h) ONE_QUBIT_KERNEL_CTRL_ENABLER(T, t) ONE_QUBIT_KERNEL_CTRL_ENABLER(Tdg, tdg) ONE_QUBIT_KERNEL_CTRL_ENABLER(S, s) ONE_QUBIT_KERNEL_CTRL_ENABLER(Sdg, sdg) } // namespace qcor runtime/qrt/impls/nisq/nisq_qrt.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -317,6 +317,19 @@ class NISQ : public ::quantum::QuantumRuntime, } void submit(xacc::AcceleratorBuffer **buffers, const int nBuffers) override { // What if we get an array of buffers but they // are all the same pointer std::set<xacc::AcceleratorBuffer*> ptrs; for (int i = 0; i < nBuffers; i++) { ptrs.insert(buffers[i]); } // If size is 1 here, then we only have // one pointer, like in the case of qubit.results() if (ptrs.size() == 1) { submit(buffers[0]); return; } xacc::internal_compiler::execute(buffers, nBuffers, program); } Loading runtime/qrt/qrt_mapper.hpp +19 −6 Original line number Diff line number Diff line Loading @@ -49,12 +49,25 @@ class qrt_mapper : public AllGateVisitor, } void addTwoQubitGate(const std::string name, xacc::Instruction &inst) { auto expr_src = inst.getBitExpression(0); auto expr_tgt = inst.getBitExpression(1); ss << "quantum::" + name + "(" << inst.getBufferNames()[0] << "[" << (expr_src.empty() ? std::to_string(inst.bits()[0]) : expr_src) << "], " << inst.getBufferNames()[1] << "[" << (expr_tgt.empty() ? std::to_string(inst.bits()[1]) : expr_tgt) << "]"; std::string expr_src, expr_tgt; if (!inst.getBitExpression(-1).empty()) { expr_src = inst.getBitExpression(-1) + ", "; } else { expr_src = inst.getBitExpression(0); expr_src = inst.getBufferNames()[0] + "[" + (expr_src.empty() ? std::to_string(inst.bits()[0]) : expr_src) + "], "; } if (!inst.getBitExpression(-2).empty()) { expr_tgt = inst.getBitExpression(-2); } else { expr_tgt = inst.getBitExpression(1); expr_tgt = inst.getBufferNames()[1] + "[" + (expr_tgt.empty() ? std::to_string(inst.bits()[1]) : expr_tgt) + "]"; } ss << "quantum::" + name + "(" << expr_src << expr_tgt; // Handle parameterized gate: if (inst.isParameterized()) { ss << ", " << inst.getParameter(0).toString(); Loading Loading
handlers/token_collector/xasm/xasm_single_visitor.hpp +3 −1 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ class xasm_single_visitor : public xasm::xasm_singleVisitor { // Get the qubit expresssions std::vector<std::string> buffer_names; int count = 1; for (int i = 0; i < required_bits; i++) { auto bit_expr = context->explist()->exp(i); auto bit_expr_str = bit_expr->getText(); Loading @@ -82,9 +83,10 @@ class xasm_single_visitor : public xasm::xasm_singleVisitor { inst->setBitExpression(i, bit_idx_expr); } else { // Indicate this is a qubit(-1) or a qreg(-2) inst->setBitExpression(-1, bit_expr_str); inst->setBitExpression(-1*count, bit_expr_str); buffer_names.push_back(bit_expr_str); } count++; } inst->setBufferNames(buffer_names); Loading
runtime/CMakeLists.txt +0 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ file(GLOB HEADERS qcor.hpp kernel/quantum_kernel.hpp objectives/objective_function.hpp execution/taskInitiate.hpp #utils/eigen_qcor_unitary_addon.hpp utils/qcor_utils.hpp) install(FILES ${HEADERS} DESTINATION include/qcor) Loading
runtime/kernel/quantum_kernel.hpp +37 −2 Original line number Diff line number Diff line Loading @@ -412,4 +412,39 @@ class KernelSignature { } }; template <typename Derived> using OneQubitKernel = QuantumKernel<Derived, qubit>; template <typename Derived> using TwoQubitKernel = QuantumKernel<Derived, qubit, qubit>; #define ONE_QUBIT_KERNEL_CTRL_ENABLER(CLASSNAME, QRTNAME) \ class CLASSNAME : public OneQubitKernel<class CLASSNAME> { \ public: \ CLASSNAME(qubit q) : OneQubitKernel<CLASSNAME>(q) {} \ CLASSNAME(std::shared_ptr<qcor::CompositeInstruction> _parent_kernel, qubit q) \ : OneQubitKernel<CLASSNAME>(_parent_kernel, q) { throw std::runtime_error("you cannot call this.");} \ void operator()(qubit q) { \ parent_kernel = \ qcor::__internal__::create_composite("__tmp_one_qubit_ctrl_enabler"); \ quantum::set_current_program(parent_kernel); \ if (runtime_env == QrtType::FTQC) { \ quantum::set_current_buffer(q.results()); \ } \ ::quantum::QRTNAME(q); \ return; \ } \ virtual ~CLASSNAME() {} \ }; ONE_QUBIT_KERNEL_CTRL_ENABLER(X, x) ONE_QUBIT_KERNEL_CTRL_ENABLER(Y, y) ONE_QUBIT_KERNEL_CTRL_ENABLER(Z, z) ONE_QUBIT_KERNEL_CTRL_ENABLER(H, h) ONE_QUBIT_KERNEL_CTRL_ENABLER(T, t) ONE_QUBIT_KERNEL_CTRL_ENABLER(Tdg, tdg) ONE_QUBIT_KERNEL_CTRL_ENABLER(S, s) ONE_QUBIT_KERNEL_CTRL_ENABLER(Sdg, sdg) } // namespace qcor
runtime/qrt/impls/nisq/nisq_qrt.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -317,6 +317,19 @@ class NISQ : public ::quantum::QuantumRuntime, } void submit(xacc::AcceleratorBuffer **buffers, const int nBuffers) override { // What if we get an array of buffers but they // are all the same pointer std::set<xacc::AcceleratorBuffer*> ptrs; for (int i = 0; i < nBuffers; i++) { ptrs.insert(buffers[i]); } // If size is 1 here, then we only have // one pointer, like in the case of qubit.results() if (ptrs.size() == 1) { submit(buffers[0]); return; } xacc::internal_compiler::execute(buffers, nBuffers, program); } Loading
runtime/qrt/qrt_mapper.hpp +19 −6 Original line number Diff line number Diff line Loading @@ -49,12 +49,25 @@ class qrt_mapper : public AllGateVisitor, } void addTwoQubitGate(const std::string name, xacc::Instruction &inst) { auto expr_src = inst.getBitExpression(0); auto expr_tgt = inst.getBitExpression(1); ss << "quantum::" + name + "(" << inst.getBufferNames()[0] << "[" << (expr_src.empty() ? std::to_string(inst.bits()[0]) : expr_src) << "], " << inst.getBufferNames()[1] << "[" << (expr_tgt.empty() ? std::to_string(inst.bits()[1]) : expr_tgt) << "]"; std::string expr_src, expr_tgt; if (!inst.getBitExpression(-1).empty()) { expr_src = inst.getBitExpression(-1) + ", "; } else { expr_src = inst.getBitExpression(0); expr_src = inst.getBufferNames()[0] + "[" + (expr_src.empty() ? std::to_string(inst.bits()[0]) : expr_src) + "], "; } if (!inst.getBitExpression(-2).empty()) { expr_tgt = inst.getBitExpression(-2); } else { expr_tgt = inst.getBitExpression(1); expr_tgt = inst.getBufferNames()[1] + "[" + (expr_tgt.empty() ? std::to_string(inst.bits()[1]) : expr_tgt) + "]"; } ss << "quantum::" + name + "(" << expr_src << expr_tgt; // Handle parameterized gate: if (inst.isParameterized()) { ss << ", " << inst.getParameter(0).toString(); Loading