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: Nguyen, Thien Minh's avatarThien Nguyen <nguyentm@ornl.gov>
parent 1fe64ee6
......@@ -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,
......
......@@ -691,7 +691,14 @@ class qjit(object):
at the given arguments.
"""
program = self.extract_composite(*args)
return internal_observe(program, observable)
# 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):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment