Loading lib/qsim/base/qcor_qsim.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include "xacc_service.hpp" namespace qcor { namespace qsim { bool CostFunctionEvaluator::initialize(Observable *observable, const HeterogeneousMap ¶ms) { target_operator = observable; Loading Loading @@ -56,4 +57,5 @@ getObjEvaluator(Observable *observable, const std::string &name, // ERROR: unknown CostFunctionEvaluator or invalid initialization options. return nullptr; } } // namespace qsim } // namespace qcor No newline at end of file lib/qsim/base/qcor_qsim.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ using Accelerator = xacc::Accelerator; using Identifiable = xacc::Identifiable; namespace qcor { namespace qsim { // Struct captures a state-preparation circuit. struct Ansatz { std::shared_ptr<CompositeInstruction> circuit; Loading Loading @@ -160,4 +161,5 @@ getWorkflow(const std::string &name, const HeterogeneousMap &init_params); std::shared_ptr<CostFunctionEvaluator> getObjEvaluator(Observable *observable, const std::string &name = "default", const HeterogeneousMap &init_params = {}); } // namespace qsim } // namespace qcor No newline at end of file lib/qsim/impls/qsim_impl.cpp +10 −7 Original line number Diff line number Diff line #include "qsim_impl.hpp" #include "xacc_service.hpp" #include "xacc.hpp" #include "xacc_service.hpp" namespace qcor { namespace qsim { Ansatz TrotterEvolution::create_ansatz(Observable *obs, const HeterogeneousMap ¶ms) { Ansatz result; Loading Loading @@ -141,6 +142,7 @@ DefaultObjFuncEval::evaluate(std::shared_ptr<CompositeInstruction> state_prep) { auto energy = vqe->execute(xacc::as_shared_ptr(tmp_child.results()), {})[0]; return energy; } } // namespace qsim } // namespace qcor #include "cppmicroservices/BundleActivator.h" Loading @@ -154,12 +156,13 @@ public: QuatumSimulationActivator() {} void Start(BundleContext context) { context.RegisterService<qcor::QuatumSimulationWorkflow>( std::make_shared<qcor::TimeDependentWorkflow>()); context.RegisterService<qcor::QuatumSimulationWorkflow>( std::make_shared<qcor::VqeWorkflow>()); context.RegisterService<qcor::CostFunctionEvaluator>( std::make_shared<qcor::DefaultObjFuncEval>()); using namespace qcor; context.RegisterService<qsim::QuatumSimulationWorkflow>( std::make_shared<qsim::TimeDependentWorkflow>()); context.RegisterService<qsim::QuatumSimulationWorkflow>( std::make_shared<qsim::VqeWorkflow>()); context.RegisterService<qsim::CostFunctionEvaluator>( std::make_shared<qsim::DefaultObjFuncEval>()); } void Stop(BundleContext) {} Loading lib/qsim/impls/qsim_impl.hpp +9 −6 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include "qcor_qsim.hpp" namespace qcor { namespace qsim { // ========== Prototype Impl. ======================== // Example implementation: Loading @@ -26,7 +27,6 @@ public: // other methods. // Estimate the cost function based on bitstring distribution, // e.g. actual quantum hardware. // Note: we can sub-class CostFunctionEvaluator to add post-processing or Loading @@ -45,24 +45,26 @@ private: class VqeWorkflow : public QuatumSimulationWorkflow { public: virtual bool initialize(const HeterogeneousMap ¶ms) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual const std::string name() const override { return "vqe"; } virtual const std::string description() const override { return ""; } private: std::shared_ptr<Optimizer> optimizer; }; // Time-dependent evolution workflow which can handle // time-dependent Hamiltonian operator. class TimeDependentWorkflow : public QuatumSimulationWorkflow { public: virtual bool initialize(const HeterogeneousMap ¶ms) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual const std::string name() const override { return "td-evolution"; } virtual const std::string description() const override { return ""; } private: static inline TimeDependentWorkflow *instance = nullptr; double t_0; Loading @@ -79,4 +81,5 @@ public: virtual const std::string name() const override { return "default"; } virtual const std::string description() const override { return ""; } }; } // namespace qsim } // namespace qcor No newline at end of file lib/qsim/impls/tests/TrotterTdWorkflow.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ int main(int argc, char **argv) { // Define the time-dependent Hamiltonian and observable operator using the // QCOR API Time-dependent Hamiltonian TdObservable H = [](double t) { qsim::TdObservable H = [](double t) { // Parameters: const double Jz = 2 * M_PI * 2.86265 * 1e-3; const double epsilon = Jz; // Values: 0.2Jz, 0.5Jz, Jz, 5Jz Loading @@ -24,9 +24,9 @@ int main(int argc, char **argv) { // Example: build model and TD workflow for Fig. 2 of // https://journals.aps.org/prb/pdf/10.1103/PhysRevB.101.184305 auto problemModel = ModelBuilder::createModel(observable, H); auto problemModel = qsim::ModelBuilder::createModel(observable, H); // Trotter step = 3fs, number of steps = 100 -> end time = 300fs auto workflow = qcor::getWorkflow( auto workflow = qsim::getWorkflow( "td-evolution", {{"method", "trotter"}, {"dt", 3.0}, {"steps", 100}}); // Result should contain the observable expectation value along Trotter steps. Loading Loading
lib/qsim/base/qcor_qsim.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include "xacc_service.hpp" namespace qcor { namespace qsim { bool CostFunctionEvaluator::initialize(Observable *observable, const HeterogeneousMap ¶ms) { target_operator = observable; Loading Loading @@ -56,4 +57,5 @@ getObjEvaluator(Observable *observable, const std::string &name, // ERROR: unknown CostFunctionEvaluator or invalid initialization options. return nullptr; } } // namespace qsim } // namespace qcor No newline at end of file
lib/qsim/base/qcor_qsim.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ using Accelerator = xacc::Accelerator; using Identifiable = xacc::Identifiable; namespace qcor { namespace qsim { // Struct captures a state-preparation circuit. struct Ansatz { std::shared_ptr<CompositeInstruction> circuit; Loading Loading @@ -160,4 +161,5 @@ getWorkflow(const std::string &name, const HeterogeneousMap &init_params); std::shared_ptr<CostFunctionEvaluator> getObjEvaluator(Observable *observable, const std::string &name = "default", const HeterogeneousMap &init_params = {}); } // namespace qsim } // namespace qcor No newline at end of file
lib/qsim/impls/qsim_impl.cpp +10 −7 Original line number Diff line number Diff line #include "qsim_impl.hpp" #include "xacc_service.hpp" #include "xacc.hpp" #include "xacc_service.hpp" namespace qcor { namespace qsim { Ansatz TrotterEvolution::create_ansatz(Observable *obs, const HeterogeneousMap ¶ms) { Ansatz result; Loading Loading @@ -141,6 +142,7 @@ DefaultObjFuncEval::evaluate(std::shared_ptr<CompositeInstruction> state_prep) { auto energy = vqe->execute(xacc::as_shared_ptr(tmp_child.results()), {})[0]; return energy; } } // namespace qsim } // namespace qcor #include "cppmicroservices/BundleActivator.h" Loading @@ -154,12 +156,13 @@ public: QuatumSimulationActivator() {} void Start(BundleContext context) { context.RegisterService<qcor::QuatumSimulationWorkflow>( std::make_shared<qcor::TimeDependentWorkflow>()); context.RegisterService<qcor::QuatumSimulationWorkflow>( std::make_shared<qcor::VqeWorkflow>()); context.RegisterService<qcor::CostFunctionEvaluator>( std::make_shared<qcor::DefaultObjFuncEval>()); using namespace qcor; context.RegisterService<qsim::QuatumSimulationWorkflow>( std::make_shared<qsim::TimeDependentWorkflow>()); context.RegisterService<qsim::QuatumSimulationWorkflow>( std::make_shared<qsim::VqeWorkflow>()); context.RegisterService<qsim::CostFunctionEvaluator>( std::make_shared<qsim::DefaultObjFuncEval>()); } void Stop(BundleContext) {} Loading
lib/qsim/impls/qsim_impl.hpp +9 −6 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ #include "qcor_qsim.hpp" namespace qcor { namespace qsim { // ========== Prototype Impl. ======================== // Example implementation: Loading @@ -26,7 +27,6 @@ public: // other methods. // Estimate the cost function based on bitstring distribution, // e.g. actual quantum hardware. // Note: we can sub-class CostFunctionEvaluator to add post-processing or Loading @@ -45,24 +45,26 @@ private: class VqeWorkflow : public QuatumSimulationWorkflow { public: virtual bool initialize(const HeterogeneousMap ¶ms) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual const std::string name() const override { return "vqe"; } virtual const std::string description() const override { return ""; } private: std::shared_ptr<Optimizer> optimizer; }; // Time-dependent evolution workflow which can handle // time-dependent Hamiltonian operator. class TimeDependentWorkflow : public QuatumSimulationWorkflow { public: virtual bool initialize(const HeterogeneousMap ¶ms) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual QuatumSimulationResult execute(const QuatumSimulationModel &model) override; virtual const std::string name() const override { return "td-evolution"; } virtual const std::string description() const override { return ""; } private: static inline TimeDependentWorkflow *instance = nullptr; double t_0; Loading @@ -79,4 +81,5 @@ public: virtual const std::string name() const override { return "default"; } virtual const std::string description() const override { return ""; } }; } // namespace qsim } // namespace qcor No newline at end of file
lib/qsim/impls/tests/TrotterTdWorkflow.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ int main(int argc, char **argv) { // Define the time-dependent Hamiltonian and observable operator using the // QCOR API Time-dependent Hamiltonian TdObservable H = [](double t) { qsim::TdObservable H = [](double t) { // Parameters: const double Jz = 2 * M_PI * 2.86265 * 1e-3; const double epsilon = Jz; // Values: 0.2Jz, 0.5Jz, Jz, 5Jz Loading @@ -24,9 +24,9 @@ int main(int argc, char **argv) { // Example: build model and TD workflow for Fig. 2 of // https://journals.aps.org/prb/pdf/10.1103/PhysRevB.101.184305 auto problemModel = ModelBuilder::createModel(observable, H); auto problemModel = qsim::ModelBuilder::createModel(observable, H); // Trotter step = 3fs, number of steps = 100 -> end time = 300fs auto workflow = qcor::getWorkflow( auto workflow = qsim::getWorkflow( "td-evolution", {{"method", "trotter"}, {"dt", 3.0}, {"steps", 100}}); // Result should contain the observable expectation value along Trotter steps. Loading