Loading python/py-qcor.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -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, Loading python/qcor.in.py +8 −1 Original line number Diff line number Diff line Loading @@ -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): Loading Loading
python/py-qcor.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -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, Loading
python/qcor.in.py +8 −1 Original line number Diff line number Diff line Loading @@ -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): Loading