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

Added an example and a test of control bit from a different qreg



Also, add qubit type to PyQJIT arg type and operator[] binding.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent f7ede468
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
__qpu__ void bell(qubit q, qubit r) {
  H(q);
  X::ctrl(q,r);
  Measure(q);
  Measure(r);
}

int main() {
  auto q = qalloc(1);
  auto r = qalloc(1);
  bell(q[0],r[0]);
  q.print();
  r.print();
}
 No newline at end of file
+7 −3
Original line number Diff line number Diff line
@@ -58,9 +58,9 @@ namespace {
// Here we enumerate them as a Variant
using AllowedKernelArgTypes =
    xacc::Variant<bool, int, double, std::string, xacc::internal_compiler::qreg,
                  std::vector<double>, std::vector<int>, qcor::PauliOperator,
                  qcor::FermionOperator, qcor::PairList<int>,
                  std::vector<qcor::PauliOperator>,
                  xacc::internal_compiler::qubit, std::vector<double>,
                  std::vector<int>, qcor::PauliOperator, qcor::FermionOperator,
                  qcor::PairList<int>, std::vector<qcor::PauliOperator>,
                  std::vector<qcor::FermionOperator>>;

// We will take as input a mapping of arg variable names to the argument itself.
@@ -539,6 +539,10 @@ PYBIND11_MODULE(_pyqcor, m) {
          [](xacc::internal_compiler::qreg &q, const std::string &key) {
            return q.results()->getInformation(key);
          },
          "")
      .def(
          "__getitem__",
          [](xacc::internal_compiler::qreg &q, int index) { return q[index]; },
          "");
  // m.def("createObjectiveFunction", [](const std::string name, ))
  py::class_<qcor::QJIT, std::shared_ptr<qcor::QJIT>>(m, "QJIT", "")
+20 −0
Original line number Diff line number Diff line
@@ -211,6 +211,26 @@ class TestKernelJIT(unittest.TestCase):
        
        self.assertEqual(comp.nInstructions(), counter)
    
    def test_multi_qregs(self):
        set_qpu('qpp', {'shots':1024})
        
        @qjit 
        def bell_qubits(q: qubit, r: qubit):
            H(q)
            X.ctrl(q, r)
            Measure(q)
            Measure(r)
        
        q = qalloc(1)
        r = qalloc(1)
        bell_qubits(q[0], r[0])
        q.print()
        r.print()
        self.assertEqual(len(q.counts()), 2)
        self.assertEqual(len(r.counts()), 2)
        # entangled
        self.assertEqual(q.counts()["0"], r.counts()["0"])
        self.assertEqual(q.counts()["1"], r.counts()["1"])

if __name__ == '__main__':
  unittest.main()
 No newline at end of file