Loading examples/qsharp/bell_driver.cpp +2 −6 Original line number Diff line number Diff line Loading @@ -9,15 +9,11 @@ qcor_include_qsharp(XACC__TestBell__body, int64_t, int64_t) // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor bell.qs bell_driver.cpp // $ qcor -qrt ftqc bell.qs bell_driver.cpp // Run with: // $ ./a.out int main() { std::cout << "HOWDY \n"; // Manually intialize QRT... ::quantum::set_qrt("ftqc"); ::quantum::initialize("qpp", "bell"); auto oneCounts = XACC__TestBell__body(1024); std::cout << "Result = " << oneCounts << "\n"; return 0.0; return 0; } No newline at end of file examples/qsharp/ghz_nisq.qs 0 → 100644 +12 −0 Original line number Diff line number Diff line namespace XACC { open Microsoft.Quantum.Intrinsic; operation TestGhz(q : Qubit[]) : Unit { H(q[0]); CNOT(q[0],q[1]); CNOT(q[0],q[2]); let res0 = M(q[0]); let res1 = M(q[1]); let res2 = M(q[2]); } } No newline at end of file examples/qsharp/ghz_nisq_driver.cpp 0 → 100644 +66 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> #include "qcor.hpp" using Qubit = uint64_t; using QReg = std::vector<Qubit*>; // Include the external QSharp function. qcor_include_qsharp(XACC__TestGhz__body, void, Array *); class TestGhz : public qcor::QuantumKernel<class TestGhz, qreg> { private: // Use deque to prevent re-alloc std::deque<Qubit> m_qubits; friend class qcor::QuantumKernel<class TestGhz, qreg>; protected: void operator()(qreg q) { if (!parent_kernel) { parent_kernel = qcor::__internal__::create_composite(kernel_name); } quantum::set_current_program(parent_kernel); if (runtime_env == QrtType::FTQC) { quantum::set_current_buffer(q.results()); } QReg qReg; for (int i = 0; i < q.size(); ++i) { m_qubits.push_back(i); qReg.emplace_back(&m_qubits.back()); } XACC__TestGhz__body(&qReg); std::cout << "INVOKE:\n" << parent_kernel->toString(); } public: inline static const std::string kernel_name = "TestGhz"; TestGhz(qreg q) : QuantumKernel<TestGhz, qreg>(q) {} TestGhz(std::shared_ptr<qcor::CompositeInstruction> _parent, qreg q) : QuantumKernel<TestGhz, qreg>(_parent, q) {} virtual ~TestGhz() { if (disable_destructor) { return; } auto [q] = args_tuple; operator()(q); xacc::internal_compiler::execute_pass_manager(); if (optimize_only) { return; } if (is_callable) { quantum::submit(q.results()); } } }; // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qpu aer:ibmqx2 -shots 1024 ghz_nisq.qs ghz_nisq_driver.cpp // Run with: // $ ./a.out int main() { auto q = qalloc(3); qcor::set_verbose(true); { TestGhz kernel(q); } q.print(); return 0; } No newline at end of file examples/qsharp/vqe_driver.cpp +1 −5 Original line number Diff line number Diff line Loading @@ -8,14 +8,10 @@ qcor_include_qsharp(XACC__Deuteron__body, double, double, int64_t); // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor vqe_ansatz.qs vqe_driver.cpp // $ qcor -qrt ftqc vqe_ansatz.qs vqe_driver.cpp // Run with: // $ ./a.out int main() { // Manually intialize QRT... ::quantum::set_qrt("ftqc"); ::quantum::initialize("qpp", "test"); const std::vector<double> expectedResults{ 0.0, -0.324699, -0.614213, -0.837166, -0.9694, -0.996584, -0.915773, -0.735724, -0.475947, -0.164595, Loading tools/driver/qcor.in +1 −0 Original line number Diff line number Diff line Loading @@ -361,6 +361,7 @@ def main(argv=None): driver_file_name = arg sys.argv.remove(driver_file_name) cpp_compile_commands = [compiler] + defaultFlags + sHandlerArgs + baseIncludes + ['-c'] +[driver_file_name] cpp_compile_commands += sys.argv[1:] if verbose: print('[qcor-exec]: ', ' '.join([c for c in cpp_compile_commands])) try: Loading Loading
examples/qsharp/bell_driver.cpp +2 −6 Original line number Diff line number Diff line Loading @@ -9,15 +9,11 @@ qcor_include_qsharp(XACC__TestBell__body, int64_t, int64_t) // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor bell.qs bell_driver.cpp // $ qcor -qrt ftqc bell.qs bell_driver.cpp // Run with: // $ ./a.out int main() { std::cout << "HOWDY \n"; // Manually intialize QRT... ::quantum::set_qrt("ftqc"); ::quantum::initialize("qpp", "bell"); auto oneCounts = XACC__TestBell__body(1024); std::cout << "Result = " << oneCounts << "\n"; return 0.0; return 0; } No newline at end of file
examples/qsharp/ghz_nisq.qs 0 → 100644 +12 −0 Original line number Diff line number Diff line namespace XACC { open Microsoft.Quantum.Intrinsic; operation TestGhz(q : Qubit[]) : Unit { H(q[0]); CNOT(q[0],q[1]); CNOT(q[0],q[2]); let res0 = M(q[0]); let res1 = M(q[1]); let res2 = M(q[2]); } } No newline at end of file
examples/qsharp/ghz_nisq_driver.cpp 0 → 100644 +66 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> #include "qcor.hpp" using Qubit = uint64_t; using QReg = std::vector<Qubit*>; // Include the external QSharp function. qcor_include_qsharp(XACC__TestGhz__body, void, Array *); class TestGhz : public qcor::QuantumKernel<class TestGhz, qreg> { private: // Use deque to prevent re-alloc std::deque<Qubit> m_qubits; friend class qcor::QuantumKernel<class TestGhz, qreg>; protected: void operator()(qreg q) { if (!parent_kernel) { parent_kernel = qcor::__internal__::create_composite(kernel_name); } quantum::set_current_program(parent_kernel); if (runtime_env == QrtType::FTQC) { quantum::set_current_buffer(q.results()); } QReg qReg; for (int i = 0; i < q.size(); ++i) { m_qubits.push_back(i); qReg.emplace_back(&m_qubits.back()); } XACC__TestGhz__body(&qReg); std::cout << "INVOKE:\n" << parent_kernel->toString(); } public: inline static const std::string kernel_name = "TestGhz"; TestGhz(qreg q) : QuantumKernel<TestGhz, qreg>(q) {} TestGhz(std::shared_ptr<qcor::CompositeInstruction> _parent, qreg q) : QuantumKernel<TestGhz, qreg>(_parent, q) {} virtual ~TestGhz() { if (disable_destructor) { return; } auto [q] = args_tuple; operator()(q); xacc::internal_compiler::execute_pass_manager(); if (optimize_only) { return; } if (is_callable) { quantum::submit(q.results()); } } }; // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qpu aer:ibmqx2 -shots 1024 ghz_nisq.qs ghz_nisq_driver.cpp // Run with: // $ ./a.out int main() { auto q = qalloc(3); qcor::set_verbose(true); { TestGhz kernel(q); } q.print(); return 0; } No newline at end of file
examples/qsharp/vqe_driver.cpp +1 −5 Original line number Diff line number Diff line Loading @@ -8,14 +8,10 @@ qcor_include_qsharp(XACC__Deuteron__body, double, double, int64_t); // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor vqe_ansatz.qs vqe_driver.cpp // $ qcor -qrt ftqc vqe_ansatz.qs vqe_driver.cpp // Run with: // $ ./a.out int main() { // Manually intialize QRT... ::quantum::set_qrt("ftqc"); ::quantum::initialize("qpp", "test"); const std::vector<double> expectedResults{ 0.0, -0.324699, -0.614213, -0.837166, -0.9694, -0.996584, -0.915773, -0.735724, -0.475947, -0.164595, Loading
tools/driver/qcor.in +1 −0 Original line number Diff line number Diff line Loading @@ -361,6 +361,7 @@ def main(argv=None): driver_file_name = arg sys.argv.remove(driver_file_name) cpp_compile_commands = [compiler] + defaultFlags + sHandlerArgs + baseIncludes + ['-c'] +[driver_file_name] cpp_compile_commands += sys.argv[1:] if verbose: print('[qcor-exec]: ', ' '.join([c for c in cpp_compile_commands])) try: Loading