Loading examples/hybrid/adapt_h2.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -10,14 +10,20 @@ __qpu__ void initial_state(qreg q) { int main() { // Define the Hamiltonian using the QCOR API std::string opstr = "(0.1202,0) Z0 Z1 + (0.168336,0) Z0 Z2 + (0.1202,0) Z2 Z3 + (0.17028,0) Z2 + (0.17028,0) Z0 + (0.165607,0) Z0 Z3 + (0.0454063,0) Y0 Y1 X2 X3 + (-0.106477,0) + (-0.220041,0) Z3 + (0.174073,0) Z1 Z3 + (0.0454063,0) Y0 Y1 Y2 Y3 + (-0.220041,0) Z1 + (0.165607,0) Z1 Z2 + (0.0454063,0) X0 X1 Y2 Y3 + (0.0454063,0) X0 X1 X2 X3"; std::string opstr = "(0.1202,0) Z0 Z1 + (0.168336,0) Z0 Z2 + (0.1202,0) Z2 Z3 + (0.17028,0) " "Z2 + (0.17028,0) Z0 + (0.165607,0) Z0 Z3 + (0.0454063,0) Y0 Y1 X2 X3 + " "(-0.106477,0) + (-0.220041,0) Z3 + (0.174073,0) Z1 Z3 + (0.0454063,0) " "Y0 Y1 Y2 Y3 + (-0.220041,0) Z1 + (0.165607,0) Z1 Z2 + (0.0454063,0) X0 " "X1 Y2 Y3 + (0.0454063,0) X0 X1 X2 X3"; auto H = qcor::createObservable(opstr); // optimizer auto optimizer = qcor::createOptimizer("nlopt"); // Create ADAPT-VQE instance // Run H2 with the singlet-adapted-uccsd pool qcor::ADAPT adapt(initial_state, H, 2, "singlet-adapted-uccsd", "vqe", optimizer); qcor::ADAPT adapt(initial_state, H, 2, "singlet-adapted-uccsd", "vqe", optimizer); // Execute! auto energy = adapt.execute(); Loading lib/hybrid/qcor_hybrid.hpp +11 −12 Original line number Diff line number Diff line Loading @@ -468,7 +468,6 @@ public: } }; // namespace qcor void execute_adapt(qreg q, const HeterogeneousMap &&m); template <typename... KernelArgs> class ADAPT { Loading @@ -484,9 +483,11 @@ protected: public: ADAPT(void (*state_prep_kernel)(std::shared_ptr<CompositeInstruction>, qreg, KernelArgs...), std::shared_ptr<Observable> obs, const int _ne, const std::string _pool, const std::string _subAlgo, std::shared_ptr<Optimizer> opt) std::shared_ptr<Observable> obs, const int _ne, const std::string _pool, const std::string _subAlgo, std::shared_ptr<Optimizer> opt) : state_prep_ptr(reinterpret_cast<void *>(state_prep_kernel)), observable(obs), nElectrons(_ne), pool(_pool), subAlgo(_subAlgo), optimizer(opt) { observable(obs), nElectrons(_ne), pool(_pool), subAlgo(_subAlgo), optimizer(opt) { q = qalloc(obs->nBits()); } Loading @@ -511,8 +512,6 @@ public: } }; void execute_qite(qreg q, const HeterogeneousMap &&m); // Next, QITE template <typename... KernelArgs> class QITE { Loading Loading
examples/hybrid/adapt_h2.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -10,14 +10,20 @@ __qpu__ void initial_state(qreg q) { int main() { // Define the Hamiltonian using the QCOR API std::string opstr = "(0.1202,0) Z0 Z1 + (0.168336,0) Z0 Z2 + (0.1202,0) Z2 Z3 + (0.17028,0) Z2 + (0.17028,0) Z0 + (0.165607,0) Z0 Z3 + (0.0454063,0) Y0 Y1 X2 X3 + (-0.106477,0) + (-0.220041,0) Z3 + (0.174073,0) Z1 Z3 + (0.0454063,0) Y0 Y1 Y2 Y3 + (-0.220041,0) Z1 + (0.165607,0) Z1 Z2 + (0.0454063,0) X0 X1 Y2 Y3 + (0.0454063,0) X0 X1 X2 X3"; std::string opstr = "(0.1202,0) Z0 Z1 + (0.168336,0) Z0 Z2 + (0.1202,0) Z2 Z3 + (0.17028,0) " "Z2 + (0.17028,0) Z0 + (0.165607,0) Z0 Z3 + (0.0454063,0) Y0 Y1 X2 X3 + " "(-0.106477,0) + (-0.220041,0) Z3 + (0.174073,0) Z1 Z3 + (0.0454063,0) " "Y0 Y1 Y2 Y3 + (-0.220041,0) Z1 + (0.165607,0) Z1 Z2 + (0.0454063,0) X0 " "X1 Y2 Y3 + (0.0454063,0) X0 X1 X2 X3"; auto H = qcor::createObservable(opstr); // optimizer auto optimizer = qcor::createOptimizer("nlopt"); // Create ADAPT-VQE instance // Run H2 with the singlet-adapted-uccsd pool qcor::ADAPT adapt(initial_state, H, 2, "singlet-adapted-uccsd", "vqe", optimizer); qcor::ADAPT adapt(initial_state, H, 2, "singlet-adapted-uccsd", "vqe", optimizer); // Execute! auto energy = adapt.execute(); Loading
lib/hybrid/qcor_hybrid.hpp +11 −12 Original line number Diff line number Diff line Loading @@ -468,7 +468,6 @@ public: } }; // namespace qcor void execute_adapt(qreg q, const HeterogeneousMap &&m); template <typename... KernelArgs> class ADAPT { Loading @@ -484,9 +483,11 @@ protected: public: ADAPT(void (*state_prep_kernel)(std::shared_ptr<CompositeInstruction>, qreg, KernelArgs...), std::shared_ptr<Observable> obs, const int _ne, const std::string _pool, const std::string _subAlgo, std::shared_ptr<Optimizer> opt) std::shared_ptr<Observable> obs, const int _ne, const std::string _pool, const std::string _subAlgo, std::shared_ptr<Optimizer> opt) : state_prep_ptr(reinterpret_cast<void *>(state_prep_kernel)), observable(obs), nElectrons(_ne), pool(_pool), subAlgo(_subAlgo), optimizer(opt) { observable(obs), nElectrons(_ne), pool(_pool), subAlgo(_subAlgo), optimizer(opt) { q = qalloc(obs->nBits()); } Loading @@ -511,8 +512,6 @@ public: } }; void execute_qite(qreg q, const HeterogeneousMap &&m); // Next, QITE template <typename... KernelArgs> class QITE { Loading