Unverified Commit 809007f7 authored by Thien Nguyen's avatar Thien Nguyen Committed by GitHub
Browse files

Merge pull request #244 from tnguyen-ornl/tnguyen/py-qcor-observe-retrieve-term-data

Ability to get term execution data when using qjit.observe()
parents 49a05cc5 01bf0964
Pipeline #178663 passed with stage
in 60 minutes and 47 seconds
......@@ -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):
"""
......
Markdown is supported
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