Loading lib/qsim/impls/qsim_impl.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ QuantumSimulationResult IterativeQpeWorkflow::execute(const QuantumSimulationModel &model) { ham_converter.fromObservable(model.observable); auto stretchedObs = ham_converter.stretchObservable(model.observable); // std::cout << "Stretched Obs: " << stretchedObs->toString() << "\n"; auto provider = xacc::getIRProvider("quantum"); // Iterative Quantum Phase Estimation: // We're using XACC IR construction API here, since using QCOR kernels here Loading lib/qsim/impls/tests/IterativeQpeVqe.cpp 0 → 100644 +40 −0 Original line number Diff line number Diff line #include "qcor_qsim.hpp" // Validate the ground-state energy of the Deuteron Hamiltonian operator by the // iterative QPE procedure. // Compile and run with: /// $ qcor -qpu qpp IterativeQpeVqe.cpp /// $ ./a.out /// Ansatz to bring the state into an eigenvector state of the Hamiltonian. /// This optimized ansatz was found by VQE. __qpu__ void eigen_state_prep(qreg q) { X(q[0]); // Theta angle found by VQE. double opt_theta = 0.297113; auto exponent_op = X(0) * Y(1) - Y(0) * X(1); exp_i_theta(q, opt_theta, exponent_op); } int main(int argc, char **argv) { // Create Hamiltonian: auto H = 5.907 - 2.1433 * X(0) * X(1) - 2.143 * Y(0) * Y(1) + 0.21829 * Z(0) - 6.125 * Z(1); auto problemModel = qsim::ModelBuilder::createModel(eigen_state_prep, H, 2, 0); // Instantiate an IQPE workflow. auto workflow = qsim::getWorkflow("iqpe", {{"time-steps", 8}, {"iterations", 8}}); auto result = workflow->execute(problemModel); const double phaseValue = result.get<double>("phase"); const double energy = result.get<double>("energy"); std::cout << "Final phase = " << phaseValue << "\n"; // Expect: ~ -1.7 (due to limited bit precision) std::cout << "Energy = " << energy << "\n"; return 0; } No newline at end of file Loading
lib/qsim/impls/qsim_impl.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ QuantumSimulationResult IterativeQpeWorkflow::execute(const QuantumSimulationModel &model) { ham_converter.fromObservable(model.observable); auto stretchedObs = ham_converter.stretchObservable(model.observable); // std::cout << "Stretched Obs: " << stretchedObs->toString() << "\n"; auto provider = xacc::getIRProvider("quantum"); // Iterative Quantum Phase Estimation: // We're using XACC IR construction API here, since using QCOR kernels here Loading
lib/qsim/impls/tests/IterativeQpeVqe.cpp 0 → 100644 +40 −0 Original line number Diff line number Diff line #include "qcor_qsim.hpp" // Validate the ground-state energy of the Deuteron Hamiltonian operator by the // iterative QPE procedure. // Compile and run with: /// $ qcor -qpu qpp IterativeQpeVqe.cpp /// $ ./a.out /// Ansatz to bring the state into an eigenvector state of the Hamiltonian. /// This optimized ansatz was found by VQE. __qpu__ void eigen_state_prep(qreg q) { X(q[0]); // Theta angle found by VQE. double opt_theta = 0.297113; auto exponent_op = X(0) * Y(1) - Y(0) * X(1); exp_i_theta(q, opt_theta, exponent_op); } int main(int argc, char **argv) { // Create Hamiltonian: auto H = 5.907 - 2.1433 * X(0) * X(1) - 2.143 * Y(0) * Y(1) + 0.21829 * Z(0) - 6.125 * Z(1); auto problemModel = qsim::ModelBuilder::createModel(eigen_state_prep, H, 2, 0); // Instantiate an IQPE workflow. auto workflow = qsim::getWorkflow("iqpe", {{"time-steps", 8}, {"iterations", 8}}); auto result = workflow->execute(problemModel); const double phaseValue = result.get<double>("phase"); const double energy = result.get<double>("energy"); std::cout << "Final phase = " << phaseValue << "\n"; // Expect: ~ -1.7 (due to limited bit precision) std::cout << "Energy = " << energy << "\n"; return 0; } No newline at end of file