Commit 80e383a0 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Merge branch 'master' into tnguyen/mirror-mlir

parents 0b33dd6c 809007f7
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
// Compile to run with validation mode: 
// Qpp (noiseless)
// qcor -validate deuteron_validation.cpp -shots 1024
// Aer (noisy)
// qcor -validate deuteron_validation.cpp -shots 1024 -qpu aer[noise-model:noise_model.json]
__qpu__ void deuteron(qreg q, double theta) {
  X(q[0]);
  Ry(q[1], theta);
  CNOT(q[1], q[0]);
  // for (int i = 0; i < 20; i++) {
  //   CNOT(q[1], q[0]);
  // }
  H(q[0]);
  H(q[1]);
  Measure(q[0]);
  Measure(q[1]);
}

int main() {
  qcor::set_verbose(true);
  const double angle = 0.297113;
  auto q = qalloc(2);
  deuteron(q, angle);
  q.print();
  std::cout << "<XX> = " << q.exp_val_z() << "\n";
}
 No newline at end of file
+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):