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

Added ability to pass CompositeInstruction kernel to the qsim model



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent b2aa20a5
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -25,11 +25,17 @@ protected:

public:
  KernelFunctor(qreg qReg) : q(qReg){};
  // Direct construction via a Composite Instruction
  KernelFunctor(std::shared_ptr<CompositeInstruction> composite) {
    kernel = composite;
    q = qalloc(composite->nPhysicalBits());
    nbParams = composite->nParameters();
  }
  qreg &getQreg() { return q; }
  size_t nParams() const { return nbParams; }
  virtual std::shared_ptr<CompositeInstruction>
  evaluate_kernel(const std::vector<double> &in_params) {
    return nullptr;
    return kernel ? kernel->operator()(in_params) : nullptr;
  }
};

@@ -100,4 +106,9 @@ std::shared_ptr<KernelFunctor> createKernelFunctor(
  return std::make_shared<KernelFunctorImpl<Args...>>(
      kernel_ptr, args_translator, helper, q, nParams);
}

inline std::shared_ptr<KernelFunctor>
createKernelFunctor(std::shared_ptr<CompositeInstruction> composite) {
  return std::make_shared<KernelFunctor>(composite);
}
} // namespace qcor
 No newline at end of file
+16 −0
Original line number Diff line number Diff line
@@ -140,6 +140,22 @@ public:
      PauliOperator &obs, size_t nbQubits, size_t nbParams) {
    return createModel(quantum_kernel_functor, &obs, nbQubits, nbParams);
  }

  // Passing the state-preparation ansatz as a CompositeInstruction
  static inline QuantumSimulationModel
  createModel(std::shared_ptr<CompositeInstruction> composite,
              Observable *obs) {
    QuantumSimulationModel model;
    model.observable = obs;
    model.user_defined_ansatz = createKernelFunctor(composite);
    return model;
  }

  static inline QuantumSimulationModel
  createModel(std::shared_ptr<CompositeInstruction> composite,
              PauliOperator &obs) {
    return createModel(composite, &obs);
  }
};

// Quantum Simulation Workflow (Protocol)