Commit 818bf7e9 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Boilerplate for IQPE workflow



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent efb17877
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -120,6 +120,21 @@ VqeWorkflow::execute(const QuatumSimulationModel &model) {
  return {};
}

bool IterativeQpeWorkflow::initialize(const HeterogeneousMap &params) {
  // TODO:
  std::cout << "Howdy: initialize\n";
  return true;
}

QuatumSimulationResult
IterativeQpeWorkflow::execute(const QuatumSimulationModel &model) {
  // TODO:
  std::cout << "Howdy: execute\n";

  return {};
}


std::shared_ptr<QuatumSimulationWorkflow>
getWorkflow(const std::string &name, const HeterogeneousMap &init_params) {
  auto qsim_workflow = xacc::getService<QuatumSimulationWorkflow>(name);
@@ -161,6 +176,8 @@ public:
        std::make_shared<qsim::TimeDependentWorkflow>());
    context.RegisterService<qsim::QuatumSimulationWorkflow>(
        std::make_shared<qsim::VqeWorkflow>());
    context.RegisterService<qsim::QuatumSimulationWorkflow>(
        std::make_shared<qsim::IterativeQpeWorkflow>());
    context.RegisterService<qsim::CostFunctionEvaluator>(
        std::make_shared<qsim::DefaultObjFuncEval>());
  }
+16 −1
Original line number Diff line number Diff line
@@ -66,13 +66,28 @@ public:
  virtual const std::string description() const override { return ""; }

private:
  static inline TimeDependentWorkflow *instance = nullptr;
  double t_0;
  double t_final;
  double dt;
  TdObservable ham_func;
};

// Iterative QPE workflow to estimate the energy of a Hamiltonian operator.
class IterativeQpeWorkflow : public QuatumSimulationWorkflow {
public:
  virtual bool initialize(const HeterogeneousMap &params) override;
  virtual QuatumSimulationResult
  execute(const QuatumSimulationModel &model) override;
  virtual const std::string name() const override { return "iqpe"; }
  virtual const std::string description() const override { return ""; }

private:
  // Number of time slices (>=1)
  int num_steps;
  // Number of iterations (>=1)
  int num_iters;
};

class DefaultObjFuncEval : public CostFunctionEvaluator {
public:
  // Evaluate the cost
+23 −0
Original line number Diff line number Diff line
#include "qcor_qsim.hpp"

// Solving the ground-state energy of a Hamiltonian operator by the iterative
// QPE procedure.

// Compile and run with:
/// $ qcor -qpu qpp IterativeQpeWorkflow.cpp
/// $ ./a.out

int main(int argc, char **argv) {
  // Create the Deuteron 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(&H);

  // Instantiate an IQPE workflow.
  auto workflow = qsim::getWorkflow("iqpe", {});

  // Result should contain the observable expectation value along Trotter steps.
  auto result = workflow->execute(problemModel);
  return 0;
}
 No newline at end of file