def test_init(self):
        eng = projectQEngine()
        self.assertEqual(eng.maxQubits, 10)
        self.assertEqual(eng.activeQubits, 0)
        self.assertEqual(len(eng.qubitReg), 0)

        eng = projectQEngine(5)
        self.assertEqual(eng.maxQubits, 5)
        self.assertEqual(eng.activeQubits, 0)
        self.assertEqual(len(eng.qubitReg), 0)
 def test_absorb_to_big(self):
     self.eng.add_fresh_qubit()
     eng2 = projectQEngine()
     for _ in range(10):
         eng2.add_fresh_qubit()
     with self.assertRaises(quantumError):
         self.eng.absorb(eng2)
 def test_absorb_parts_other_empty(self):
     num = self.eng.add_fresh_qubit()
     self.eng.apply_H(num)
     eng2 = projectQEngine()
     self.eng.absorb_parts(*eng2.get_register_RI(), eng2.activeQubits)
     self.assertEqual(self.eng.activeQubits, 1)
     self.assertEqual(len(self.eng.qubitReg), 1)
     state = self.eng.get_register_RI()
     ref = [1 / np.sqrt(2), 1 / np.sqrt(2)]
     self.assertAlmostEqual(self.abs_inner_product(state, ref), 1)
 def test_absorb_parts(self):
     self.eng.add_fresh_qubit()
     eng2 = projectQEngine()
     eng2.add_fresh_qubit()
     self.eng.absorb_parts(*eng2.get_register_RI(), eng2.activeQubits)
     self.assertEqual(self.eng.activeQubits, 2)
     self.assertEqual(len(self.eng.qubitReg), 2)
     state = self.eng.get_register_RI()
     ref = [1, 0, 0, 0]
     self.assertAlmostEqual(self.abs_inner_product(state, ref), 1)
 def test_absorb_this_empty_H(self):
     eng2 = projectQEngine()
     num = eng2.add_fresh_qubit()
     eng2.apply_H(num)
     self.eng.absorb(eng2)
     self.assertEqual(self.eng.activeQubits, 1)
     self.assertEqual(len(self.eng.qubitReg), 1)
     state = self.eng.get_register_RI()
     ref = [1 / np.sqrt(2), 1 / np.sqrt(2)]
     self.assertAlmostEqual(self.abs_inner_product(state, ref), 1)
 def test_absorb_2GHZ(self):
     n = 5
     eng2 = projectQEngine()
     for eng in [self.eng, eng2]:
         qubits = [eng.add_fresh_qubit() for _ in range(n)]
         eng.apply_H(qubits[0])
         for i in range(1, n):
             eng.apply_CNOT(qubits[0], qubits[i])
     self.eng.absorb(eng2)
     self.assertEqual(self.eng.activeQubits, 2 * n)
     self.assertEqual(len(self.eng.qubitReg), 2 * n)
 def test_absorb_parts_EPR(self):
     eng2 = projectQEngine()
     num1 = eng2.add_fresh_qubit()
     num2 = eng2.add_fresh_qubit()
     eng2.apply_H(num1)
     eng2.apply_CNOT(num1, num2)
     self.eng.absorb_parts(*eng2.get_register_RI(), eng2.activeQubits)
     self.assertEqual(self.eng.activeQubits, 2)
     self.assertEqual(len(self.eng.qubitReg), 2)
     state = self.eng.get_register_RI()
     ref = [1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)]
     self.assertAlmostEqual(self.abs_inner_product(state, ref), 1)
 def test_absorb_this_empty_GHZ(self):
     n = 5
     eng2 = projectQEngine()
     qubits = [eng2.add_fresh_qubit() for _ in range(n)]
     eng2.apply_H(qubits[0])
     for i in range(1, n):
         eng2.apply_CNOT(qubits[0], qubits[i])
     self.eng.absorb(eng2)
     self.assertEqual(self.eng.activeQubits, n)
     self.assertEqual(len(self.eng.qubitReg), n)
     state = self.eng.get_register_RI()
     ref = [1 / np.sqrt(2)] + [0] * (2 ** n - 2) + [1 / np.sqrt(2)]
     self.assertAlmostEqual(self.abs_inner_product(state, ref), 1)
 def test_absorb_parts_both_empty(self):
     eng2 = projectQEngine()
     self.eng.absorb_parts(*eng2.get_register_RI(), eng2.activeQubits)
     self.assertEqual(self.eng.activeQubits, 0)
     self.assertEqual(len(self.eng.qubitReg), 0)
 def setUp(self):
     self.eng = projectQEngine()
 def test_absorb_both_empty(self):
     eng2 = projectQEngine()
     self.eng.absorb(eng2)
     self.assertEqual(self.eng.activeQubits, 0)
     self.assertEqual(len(self.eng.qubitReg), 0)