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

Ability to get term execution data when using qjit.observe()



Forward the qreg arg from python to cpp so that the child buffers are attached to it.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 1fe64ee6
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -912,6 +912,19 @@ PYBIND11_MODULE(_pyqcor, m) {
        return qcor::observe(kernel, observable, q);
      },
      "");
  m.def("internal_observe",
        [](std::shared_ptr<qcor::CompositeInstruction> kernel,
           qcor::Operator &obs, xacc::internal_compiler::qreg &q) {
          return qcor::observe(kernel, obs, q);
        },
        "");
  m.def("internal_observe",
        [](std::shared_ptr<qcor::CompositeInstruction> kernel, py::object obs,
           xacc::internal_compiler::qreg &q) {
          auto observable = convertToQCOROperator(obs);
          return qcor::observe(kernel, observable, q);
        },
        "");
  m.def(
      "internal_autograd",
      [](py::function &kernel_eval, qcor::Operator &obs,
+8 −1
Original line number Diff line number Diff line
@@ -691,6 +691,13 @@ class qjit(object):
        at the given arguments. 
        """
        program = self.extract_composite(*args)
        # If the kernel has the simple signature (qreg, params...),
        # forwards the qreg to the qcor::observe method so that users can get a handle to the qreg
        # which contains child buffer information (e.g. bitstrings/exp-val-z of each term).
        if (str(self.type_annotations[self.arg_names[0]]) == '<class \'_pyqcor.qreg\'>' and args[0].size() == observable.nBits()):
            return internal_observe(program, observable, args[0])
        else:
            # Otherwise, just qcor will use a temp. buffer and just return the expectation value.
            return internal_observe(program, observable)
    
    def autograd(self, observable, qreg, x_vec):