Loading examples/ctrl-gates/ccx.cpp 0 → 100644 +24 −0 Original line number Diff line number Diff line __qpu__ void ccnot(qreg q) { // set initial state to 111 X(q); X::ctrl({q[0], q[1]}, q[2]); Measure(q); } int main() { // allocate 3 qubits auto q = qalloc(3); ccnot::print_kernel(std::cout, q); // Run the unitary evolution. ccnot(q); // should see 011 (msb) for toffoli input 111 q.print(); } examples/grover/general_grover.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line using GroverPhaseOracle = KernelSignature<qreg>; __qpu__ void reflect_about_uniform(qreg q) { compute { H(q); X(q); } action { std::vector<qubit> ctrl_qubits; for (int i = 0; i < q.size() - 1; i++) { std::cout << "adding qubit " << q[i].second << "\n"; ctrl_qubits.push_back(q[i]); } auto last_qubit = q[2]; Z::ctrl(ctrl_qubits, last_qubit); } return; } __qpu__ void run_grover(qreg q, GroverPhaseOracle oracle, const int iterations) { H(q); for (int i = 0; i < iterations; i++) { oracle(q); reflect_about_uniform(q); } Measure(q); } __qpu__ void oracle(qreg q) { CZ(q[0], q[2]); CZ(q[1], q[2]); } __qpu__ void ccz(qreg q) { Z::ctrl({q[0], q[1]}, q[2]); } int main() { auto q = qalloc(3); run_grover(q, oracle, 1); q.print(); run_grover::print_kernel(q, oracle, 1); auto m = ccz::as_unitary_matrix(q); std::cout << m << "\n"; std::cout << run_grover::openqasm(q, oracle, 1) << "\n"; } No newline at end of file handlers/qcor_syntax_handler.cpp +23 −13 Original line number Diff line number Diff line Loading @@ -48,13 +48,23 @@ void QCORSyntaxHandler::GetReplacement(Preprocessor &PP, Declarator &D, } else if (type == "qcor::qreg") { bufferNames.push_back(ident->getName().str()); type = "qreg"; } else if (type.find("xacc::internal_compiler::qubit") != std::string::npos) { } else if (type.find("xacc::internal_compiler::qubit") != std::string::npos) { bufferNames.push_back(ident->getName().str()); type = "qubit"; } program_arg_types.push_back(type); program_parameters.push_back(var); // If this was a passed kernel as a KernelSignature, then // we need to add to the kernels in translation unit if (auto t = dyn_cast<TypedefType>(parm_var_decl->getType())) { auto d = t->desugar(); if (d.getAsString().find("KernelSignature") != std::string::npos) { qcor::append_kernel(var, {}, {}); } } } GetReplacement(PP, kernel_name, program_arg_types, program_parameters, Loading Loading @@ -88,17 +98,17 @@ void QCORSyntaxHandler::GetReplacement( // with XACC api calls qcor::append_kernel(kernel_name, program_arg_types, program_parameters); for (int i = 0; i < program_arg_types.size(); i++) { if (program_arg_types[i].find("CallableKernel") != std::string::npos) { // we have a kernel we can call, need to add it to // append_kernel call. qcor::append_kernel(program_parameters[i], {}, {}); } } // for (int i = 0; i < program_arg_types.size(); i++) { // if (program_arg_types[i].find("CallableKernel") != std::string::npos) { // // we have a kernel we can call, need to add it to // // append_kernel call. // qcor::append_kernel(program_parameters[i], {}, {}); // } // } std::string src_to_prepend; auto new_src = qcor::run_token_collector(PP, Toks, src_to_prepend, kernel_name, program_arg_types, auto new_src = qcor::run_token_collector(PP, Toks, src_to_prepend, kernel_name, program_arg_types, program_parameters, bufferNames); if (!src_to_prepend.empty()) OS << src_to_prepend; 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 Loading
examples/ctrl-gates/ccx.cpp 0 → 100644 +24 −0 Original line number Diff line number Diff line __qpu__ void ccnot(qreg q) { // set initial state to 111 X(q); X::ctrl({q[0], q[1]}, q[2]); Measure(q); } int main() { // allocate 3 qubits auto q = qalloc(3); ccnot::print_kernel(std::cout, q); // Run the unitary evolution. ccnot(q); // should see 011 (msb) for toffoli input 111 q.print(); }
examples/grover/general_grover.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line using GroverPhaseOracle = KernelSignature<qreg>; __qpu__ void reflect_about_uniform(qreg q) { compute { H(q); X(q); } action { std::vector<qubit> ctrl_qubits; for (int i = 0; i < q.size() - 1; i++) { std::cout << "adding qubit " << q[i].second << "\n"; ctrl_qubits.push_back(q[i]); } auto last_qubit = q[2]; Z::ctrl(ctrl_qubits, last_qubit); } return; } __qpu__ void run_grover(qreg q, GroverPhaseOracle oracle, const int iterations) { H(q); for (int i = 0; i < iterations; i++) { oracle(q); reflect_about_uniform(q); } Measure(q); } __qpu__ void oracle(qreg q) { CZ(q[0], q[2]); CZ(q[1], q[2]); } __qpu__ void ccz(qreg q) { Z::ctrl({q[0], q[1]}, q[2]); } int main() { auto q = qalloc(3); run_grover(q, oracle, 1); q.print(); run_grover::print_kernel(q, oracle, 1); auto m = ccz::as_unitary_matrix(q); std::cout << m << "\n"; std::cout << run_grover::openqasm(q, oracle, 1) << "\n"; } No newline at end of file
handlers/qcor_syntax_handler.cpp +23 −13 Original line number Diff line number Diff line Loading @@ -48,13 +48,23 @@ void QCORSyntaxHandler::GetReplacement(Preprocessor &PP, Declarator &D, } else if (type == "qcor::qreg") { bufferNames.push_back(ident->getName().str()); type = "qreg"; } else if (type.find("xacc::internal_compiler::qubit") != std::string::npos) { } else if (type.find("xacc::internal_compiler::qubit") != std::string::npos) { bufferNames.push_back(ident->getName().str()); type = "qubit"; } program_arg_types.push_back(type); program_parameters.push_back(var); // If this was a passed kernel as a KernelSignature, then // we need to add to the kernels in translation unit if (auto t = dyn_cast<TypedefType>(parm_var_decl->getType())) { auto d = t->desugar(); if (d.getAsString().find("KernelSignature") != std::string::npos) { qcor::append_kernel(var, {}, {}); } } } GetReplacement(PP, kernel_name, program_arg_types, program_parameters, Loading Loading @@ -88,17 +98,17 @@ void QCORSyntaxHandler::GetReplacement( // with XACC api calls qcor::append_kernel(kernel_name, program_arg_types, program_parameters); for (int i = 0; i < program_arg_types.size(); i++) { if (program_arg_types[i].find("CallableKernel") != std::string::npos) { // we have a kernel we can call, need to add it to // append_kernel call. qcor::append_kernel(program_parameters[i], {}, {}); } } // for (int i = 0; i < program_arg_types.size(); i++) { // if (program_arg_types[i].find("CallableKernel") != std::string::npos) { // // we have a kernel we can call, need to add it to // // append_kernel call. // qcor::append_kernel(program_parameters[i], {}, {}); // } // } std::string src_to_prepend; auto new_src = qcor::run_token_collector(PP, Toks, src_to_prepend, kernel_name, program_arg_types, auto new_src = qcor::run_token_collector(PP, Toks, src_to_prepend, kernel_name, program_arg_types, program_parameters, bufferNames); if (!src_to_prepend.empty()) OS << src_to_prepend; 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