Commit 71094b7a authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added PauliOperator overloads for createModel



and fixed examples

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent af61e1f7
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -91,6 +91,12 @@ public:
  //     e.g. a function to map from time to Hamiltonian operator.
  static QuatumSimulationModel createModel(Observable *obs, TdObservable td_ham,
                                           const HeterogeneousMap &params = {});
  // Pauli operator overload:
  static QuatumSimulationModel
  createModel(PauliOperator &obs, TdObservable td_ham,
              const HeterogeneousMap &params = {}) {
    return createModel(&obs, td_ham, params);
  }

  // ========  High-level model builder ==============
  // The idea here is to have contributed modules to translate problem
@@ -120,6 +126,14 @@ public:
    model.user_defined_ansatz = kernel_functor;
    return model;
  }

  template <typename... Args>
  static inline QuatumSimulationModel createModel(
      void (*quantum_kernel_functor)(std::shared_ptr<CompositeInstruction>,
                                     Args...),
      PauliOperator &obs, size_t nbQubits, size_t nbParams) {
    return createModel(quantum_kernel_functor, &obs, nbQubits, nbParams);
  }
};

// Quantum Simulation Workflow (Protocol)
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ 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 = ModelBuilder::createModel(observable, H);
  // Trotter step = 3fs, number of steps = 100 -> end time = 300fs
  auto workflow = qcor::getWorkflow(
      "td-evolution", {{"method", "trotter"}, {"dt", 3.0}, {"steps", 100}});
+4 −7
Original line number Diff line number Diff line
@@ -14,14 +14,11 @@ __qpu__ void ansatz(qreg q, double theta) {
}

int main(int argc, char **argv) {
  // Allocate 2 qubits
  auto q = qalloc(2);

  // Create the Deuteron Hamiltonian
  auto H = createObservable(
      "5.907 - 2.1433 X0X1 - 2.1433 Y0Y1 + .21829 Z0 - 6.125 Z1");

  auto problemModel = ModelBuilder::createModel(ansatz, H.get(), q.size(), 1);
  auto H = 5.907 - 2.1433*X(0)*X(1) - 2.143*Y(0)*Y(1) + 0.21829*Z(0) - 6.125*Z(1);
  const auto num_qubits = 2;
  const auto num_params = 1;
  auto problemModel = ModelBuilder::createModel(ansatz, H, num_qubits, num_params);
  auto optimizer = createOptimizer("nlopt");
  // Instantiate a VQE workflow with the nlopt optimizer
  auto workflow = qcor::getWorkflow("vqe", {{"optimizer", optimizer}});