Example #1
0
    def test_init(self):
        eng = stabilizerEngine()
        self.assertEqual(eng.maxQubits, 10)
        self.assertEqual(eng.activeQubits, 0)
        self.assertEqual(len(eng.qubitReg), 0)

        eng = stabilizerEngine(5)
        self.assertEqual(eng.maxQubits, 5)
        self.assertEqual(eng.activeQubits, 0)
        self.assertEqual(len(eng.qubitReg), 0)
Example #2
0
 def test_absorb_to_big(self):
     self.eng.add_fresh_qubit()
     eng2 = stabilizerEngine()
     for _ in range(10):
         eng2.add_fresh_qubit()
     with self.assertRaises(quantumError):
         self.eng.absorb(eng2)
Example #3
0
 def test_absorb_parts_other_empty(self):
     num = self.eng.add_fresh_qubit()
     self.eng.apply_H(num)
     eng2 = stabilizerEngine()
     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()
     self.assertTrue(StabilizerState(state) == StabilizerState([[1, 0]]))
Example #4
0
 def test_absorb_this_empty_H(self):
     eng2 = stabilizerEngine()
     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()
     self.assertTrue(StabilizerState(state) == StabilizerState([[1, 0]]))
Example #5
0
 def test_absorb_parts(self):
     self.eng.add_fresh_qubit()
     eng2 = stabilizerEngine()
     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()
     self.assertTrue(
         StabilizerState(state) == StabilizerState([[0, 0, 1, 0],
                                                    [0, 0, 0, 1]]))
Example #6
0
 def test_absorb_2GHZ(self):
     n = 5
     eng2 = stabilizerEngine()
     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)
Example #7
0
 def test_absorb_parts_EPR(self):
     eng2 = stabilizerEngine()
     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()
     self.assertTrue(
         StabilizerState(state) == StabilizerState([[1, 1, 0, 0],
                                                    [0, 0, 1, 1]]))
Example #8
0
 def test_absorb_this_empty_GHZ(self):
     n = 5
     eng2 = stabilizerEngine()
     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)]
     ref = [[1] * n + [0] * n]
     for i in range(n - 1):
         ref += [[0] * n + [0] * i + [1] * 2 + [0] * (n - i - 2)]
     self.assertTrue(StabilizerState(state) == StabilizerState(ref))
Example #9
0
 def test_absorb_parts_both_empty(self):
     eng2 = stabilizerEngine()
     self.eng.absorb_parts(*eng2.get_register_RI(), eng2.activeQubits)
     self.assertEqual(self.eng.activeQubits, 0)
     self.assertEqual(len(self.eng.qubitReg), 0)
Example #10
0
 def setUp(self):
     self.eng = stabilizerEngine()
Example #11
0
 def test_absorb_both_empty(self):
     eng2 = stabilizerEngine()
     self.eng.absorb(eng2)
     self.assertEqual(self.eng.activeQubits, 0)
     self.assertEqual(len(self.eng.qubitReg), 0)