Loading .gitignore +4 −0 Original line number Diff line number Diff line Loading @@ -49,3 +49,7 @@ __pycache__/ # IDE files .vscode/* .theia/* # LLVM files *.ll *.bc No newline at end of file examples/qsharp/FTQC/Bell/bell.qs 0 → 100644 +30 −0 Original line number Diff line number Diff line namespace QCOR { // Using QCOR Intrinsic instruction set // see QirTarget.qs open QCOR.Intrinsic; operation TestBell(count : Int) : Int { // Simple bell test mutable numOnes = 0; mutable agree = 0; use q = Qubit[2]; for test in 1..count { H(q[0]); CNOT(q[0],q[1]); let res0 = M(q[0]); let res1 = M(q[1]); if res0 == res0 { set agree += 1; } // Count the number of ones we saw: if res0 == One { set numOnes += 1; } Reset(q[0]); Reset(q[1]); } return numOnes; } } No newline at end of file examples/qsharp/FTQC/Bell/bell_driver.cpp 0 → 100644 +18 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> // Include the external QSharp function. qcor_include_qsharp(QCOR__TestBell__body, int64_t, int64_t) // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qrt ftqc bell.qs bell_driver.cpp // Run with: // $ ./a.out int main() { auto oneCounts = QCOR__TestBell__body(1024); std::cout << "Result = " << oneCounts << "\n"; return 0; } No newline at end of file examples/qsharp/FTQC/Deuteron/vqe_ansatz.qs 0 → 100644 +31 −0 Original line number Diff line number Diff line namespace QCOR { open QCOR.Intrinsic; // Estimate energy value in a FTQC manner. operation Deuteron(theta : Double, shots: Int) : Double { mutable numParityOnes = 0; use (qubits = Qubit[2]) { for test in 1..shots { X(qubits[0]); Ry(theta, qubits[1]); CNOT(qubits[1], qubits[0]); // Let's measure <X0X1> H(qubits[0]); H(qubits[1]); if M(qubits[0]) != M(qubits[1]) { set numParityOnes += 1; } if M(qubits[0]) == One { X(qubits[0]); } if M(qubits[1]) == One { X(qubits[1]); } } } let res = IntAsDouble(shots - numParityOnes)/IntAsDouble(shots) - IntAsDouble(numParityOnes)/IntAsDouble(shots); return res; } } No newline at end of file examples/qsharp/FTQC/Deuteron/vqe_driver.cpp 0 → 100644 +29 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> // Include the external QSharp function. qcor_include_qsharp(QCOR__Deuteron__body, double, double, int64_t); // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qrt ftqc vqe_ansatz.qs vqe_driver.cpp // Run with: // $ ./a.out int main() { 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, 0.164595, 0.475947, 0.735724, 0.915773, 0.996584, 0.9694, 0.837166, 0.614213, 0.324699, 0.0}; const auto angles = qcor::linspace(-M_PI, M_PI, 20); for (size_t i = 0; i < angles.size(); ++i) { const double angle = angles[i]; const double exp_val_xx = QCOR__Deuteron__body(angle, 1024); std::cout << "<X0X1>(" << angle << ") = " << exp_val_xx << " vs. expected = " << expectedResults[i] << "\n"; } return 0; } No newline at end of file Loading
.gitignore +4 −0 Original line number Diff line number Diff line Loading @@ -49,3 +49,7 @@ __pycache__/ # IDE files .vscode/* .theia/* # LLVM files *.ll *.bc No newline at end of file
examples/qsharp/FTQC/Bell/bell.qs 0 → 100644 +30 −0 Original line number Diff line number Diff line namespace QCOR { // Using QCOR Intrinsic instruction set // see QirTarget.qs open QCOR.Intrinsic; operation TestBell(count : Int) : Int { // Simple bell test mutable numOnes = 0; mutable agree = 0; use q = Qubit[2]; for test in 1..count { H(q[0]); CNOT(q[0],q[1]); let res0 = M(q[0]); let res1 = M(q[1]); if res0 == res0 { set agree += 1; } // Count the number of ones we saw: if res0 == One { set numOnes += 1; } Reset(q[0]); Reset(q[1]); } return numOnes; } } No newline at end of file
examples/qsharp/FTQC/Bell/bell_driver.cpp 0 → 100644 +18 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> // Include the external QSharp function. qcor_include_qsharp(QCOR__TestBell__body, int64_t, int64_t) // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qrt ftqc bell.qs bell_driver.cpp // Run with: // $ ./a.out int main() { auto oneCounts = QCOR__TestBell__body(1024); std::cout << "Result = " << oneCounts << "\n"; return 0; } No newline at end of file
examples/qsharp/FTQC/Deuteron/vqe_ansatz.qs 0 → 100644 +31 −0 Original line number Diff line number Diff line namespace QCOR { open QCOR.Intrinsic; // Estimate energy value in a FTQC manner. operation Deuteron(theta : Double, shots: Int) : Double { mutable numParityOnes = 0; use (qubits = Qubit[2]) { for test in 1..shots { X(qubits[0]); Ry(theta, qubits[1]); CNOT(qubits[1], qubits[0]); // Let's measure <X0X1> H(qubits[0]); H(qubits[1]); if M(qubits[0]) != M(qubits[1]) { set numParityOnes += 1; } if M(qubits[0]) == One { X(qubits[0]); } if M(qubits[1]) == One { X(qubits[1]); } } } let res = IntAsDouble(shots - numParityOnes)/IntAsDouble(shots) - IntAsDouble(numParityOnes)/IntAsDouble(shots); return res; } } No newline at end of file
examples/qsharp/FTQC/Deuteron/vqe_driver.cpp 0 → 100644 +29 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> // Include the external QSharp function. qcor_include_qsharp(QCOR__Deuteron__body, double, double, int64_t); // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qrt ftqc vqe_ansatz.qs vqe_driver.cpp // Run with: // $ ./a.out int main() { 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, 0.164595, 0.475947, 0.735724, 0.915773, 0.996584, 0.9694, 0.837166, 0.614213, 0.324699, 0.0}; const auto angles = qcor::linspace(-M_PI, M_PI, 20); for (size_t i = 0; i < angles.size(); ++i) { const double angle = angles[i]; const double exp_val_xx = QCOR__Deuteron__body(angle, 1024); std::cout << "<X0X1>(" << angle << ") = " << exp_val_xx << " vs. expected = " << expectedResults[i] << "\n"; } return 0; } No newline at end of file