Commit fafc6a92 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixed bug with kernel evaluation in objective operator()

parent a2091ddd
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -6,14 +6,14 @@ __qpu__ void ansatz(qreg q, double theta) {
  CX(q[1], q[0]);
}


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

  // Create the Deuteron Hamiltonian (Observable)
  auto H = qcor::createObservable(
      "5.907 - 2.1433 X0X1 - 2.1433 Y0Y1 + .21829 Z0 - 6.125 Z1");
  auto H = 5.907 - 2.1433 * qcor::X(0) * qcor::X(1) -
           2.1433 * qcor::Y(0) * qcor::Y(1) + .21829 * qcor::Z(0) -
           6.125 * qcor::Z(1);

  // Create the ObjectiveFunction, here we want to run VQE
  // need to provide ansatz and the Observable
+0 −2
Original line number Diff line number Diff line
@@ -90,8 +90,6 @@ public:
    // Get Tokens as a string, rewrite code
    // with XACC api calls

    std::cout << "proto is: " << function_prototype << "\n";

    auto new_src = qcor::run_token_collector(PP, Toks, bufferNames, function_prototype );

    OS << "quantum::initialize(\"" << qpu_name << "\", \"" << kernel_name
+5 −1
Original line number Diff line number Diff line
@@ -21,11 +21,15 @@ protected:
    if (!vqe) {
      vqe = xacc::getAlgorithm("vqe");
    }
    vqe->initialize(
    auto success = vqe->initialize(
        {std::make_pair("ansatz", kernel),
         std::make_pair("accelerator", xacc::internal_compiler::get_qpu()),
         std::make_pair("observable", observable)});

    if (!success) {
        xacc::error("QCOR VQE Error - could not initialize vqe algorithm.");
    }
    
    auto tmp_child = qalloc(qreg.size());
    auto val = vqe->execute(xacc::as_shared_ptr(tmp_child.results()), {})[0];
    qreg.addChild(tmp_child);
+5 −3
Original line number Diff line number Diff line
@@ -228,12 +228,14 @@ public:
  // quantum kernel
  template <typename... ArgumentTypes>
  double operator()(ArgumentTypes... args) {
    if (!kernel) {
      auto functor =
    void (*functor)(ArgumentTypes...);
    if (pointer_to_functor) {
      functor =
          reinterpret_cast<void (*)(ArgumentTypes...)>(pointer_to_functor);
      kernel = __internal__::kernel_as_composite_instruction(functor, args...);
    }
    
    kernel = __internal__::kernel_as_composite_instruction(functor, args...);

    if (!qreg.results()) {
      // this hasn't been set, so set it
      qreg = std::get<0>(std::forward_as_tuple(args...));