Exemplo n.º 1
0
 def test_ct(self):
     """test 'ct' gate
     """
     qc = QCirc().h(0).h(1).ct(0, 1).measure(qid=[0, 1], cid=[0, 1])
     qs = QState(qubit_num=2).h(0).h(1).ct(0, 1)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 2
0
def main():

    hm = Observable("x_0")

    for i in range(21):
        t = i*0.05
        qs = QState(1)

        # time evolution
        qs.evolve(observable=hm, time=t, iteration=100)

        # quantum stat in bloch spere
        theta, phi = bloch(qs.amp[0],qs.amp[1])

        print("time = {0:.2f}, theta = {1:.2f}*PI, phi = {2:.2f}*PI"
              .format(t,theta,phi))
Exemplo n.º 3
0
 def test_h_t_dg(self):
     """test 'h-t_dg-h' gate
     """
     qc = QCirc().h(0).t_dg(0).h(0).measure(qid=[0], cid=[0])
     qs = QState(qubit_num=1).h(0).t_dg(0).h(0)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 4
0
 def test_s(self):
     """test 's' gate
     """
     qc = QCirc().s(0).measure(qid=[0], cid=[0])
     qs = QState(qubit_num=1).s(0)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 5
0
 def test_h_p_h(self):
     """test 'h-p-h' gate
     """
     qc = QCirc().h(0).p(0, phase=0.1).h(0).measure(qid=[0], cid=[0])
     qs = QState(qubit_num=1).h(0).p(0, phase=0.1).h(0)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 6
0
 def test_rz(self):
     """test 'rz' gate
     """
     qc = QCirc().rz(0, phase=0.1).measure(qid=[0], cid=[0])
     qs = QState(qubit_num=1).rz(0, phase=0.1)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 7
0
 def test_x_x_csw(self):
     """test 'csw' gate
     """
     qs = QState(qubit_num=3).x(0).x(1).csw(0, 1, 2)
     actual = qs.amp
     expect = np.array([0j, 0j, 0j, 0j, 0j, (1 + 0j), 0j, 0j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 8
0
 def test_init(self):
     """test '__new__' (qubit_num)
     """
     qs = QState(qubit_num=3)
     actual = qs.amp
     expect = np.array([1j, 0j, 0j, 0j, 0j, 0j, 0j, 0j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 9
0
 def test_sw(self):
     """test 'sw' gate
     """
     qs = QState(qubit_num=2).h(0).h(1).sw(0, 1)
     actual = qs.amp
     expect = np.array([(0.5 + 0j), (0.5 + 0j), (0.5 + 0j), (0.5 + 0j)])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 10
0
 def test_h_p(self):
     """test 'p' gate (following 'h' gate)
     """
     qs = QState(qubit_num=1).h(0).p(0, phase=0.25)
     actual = qs.amp
     expect = np.array([0.70710678, 0.5 + 0.5j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 11
0
 def test_p(self):
     """test 'p' gate
     """
     qs = QState(qubit_num=1).p(0, phase=0.25)
     actual = qs.amp
     expect = np.array([1.0, 0.0])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 12
0
 def test_xr_dg(self):
     """test 'xr_dg' gate
     """
     qs = QState(qubit_num=1).xr_dg(0)
     actual = qs.amp
     expect = np.array([0.5 - 0.5j, 0.5 + 0.5j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 13
0
 def test_ry(self):
     """test 'ry' gate
     """
     qs = QState(qubit_num=1).ry(0, phase=0.25)
     actual = qs.amp
     expect = np.array([COS_PI_8, SIN_PI_8])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 14
0
 def test_h_t_dg(self):
     """test 't_dg' gate (following 'h' gate)
     """
     qs = QState(qubit_num=1).h(0).t_dg(0)
     actual = qs.amp
     expect = np.array([1.0 / SQRT_2, 0.5 - 0.5j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 15
0
 def test_t_dg(self):
     """test 't_dg' gate
     """
     qs = QState(qubit_num=1).t_dg(0)
     actual = qs.amp
     expect = np.array([1.0, 0.0])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 16
0
 def test_h_s(self):
     """test 's' gate (following 'h' gate)
     """
     qs = QState(qubit_num=1).h(0).s(0)
     actual = qs.amp
     expect = np.array([1.0 / SQRT_2, 1.0j / SQRT_2])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 17
0
 def test_h_h(self):
     """test 'h' gate (following 'h')
     """
     qs = QState(qubit_num=1).h(0).h(0)
     actual = qs.amp
     expect = np.array([1.0, 0.0])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 18
0
 def test_mcx_3(self):
     """test 'mcx' gate (for 3-qubit)
     """
     qs = QState(qubit_num=3).x(0).x(1).mcx([0, 1, 2])
     actual = qs.amp
     expect = np.array([0j, 0j, 0j, 0j, 0j, 0j, 0j, (1 + 0j)])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 19
0
 def test_h_ry(self):
     """test 'ry' gate (following 'h' gate)
     """
     qs = QState(qubit_num=1).h(0).ry(0, phase=0.25)
     actual = qs.amp
     expect = np.array([0.38268343 + 0.j, 0.92387953 + 0.j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 20
0
 def test_y(self):
     """test 'y' gate
     """
     qs = QState(qubit_num=1).y(0)
     actual = qs.amp
     expect = np.array([0.0, 1.0j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 21
0
 def test_h_rz(self):
     """test 'rz' gate (following 'h' gate)
     """
     qs = QState(qubit_num=1).h(0).rz(0, phase=0.25)
     actual = qs.amp
     expect = np.array([0.65328148 - 0.27059805j, 0.65328148 + 0.27059805j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 22
0
 def test_x_sw(self):
     """test 'sw' gate (following 'x' gate, not 'h' gates)
     """
     qs = QState(qubit_num=2).x(0).sw(0, 1)
     actual = qs.amp
     expect = np.array([0j, (1 + 0j), 0j, 0j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
Exemplo n.º 23
0
 def test_operate_xyz(self):
     """test 'operate' (xyz)
     """
     pp = PauliProduct(pauli_str="XYZ")
     qc = QCirc().operate(pp=pp).measure(qid=[0, 1, 2], cid=[0, 1, 2])
     qs = QState(qubit_num=3).operate(pp=pp)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 24
0
 def test_operate_h_z(self):
     """test 'operate' (h-z)
     """
     pp = PauliProduct(pauli_str="Z")
     qc = QCirc().h(0).operate(pp=pp).measure(qid=[0], cid=[0])
     qs = QState(qubit_num=1).h(0).operate(pp=pp)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 25
0
 def test_csw(self):
     """test 'csw' gate
     """
     qc = QCirc().x(0).x(1).csw(0, 1, 2).measure(qid=[0, 1, 2],
                                                 cid=[0, 1, 2])
     qs = QState(qubit_num=3).x(0).x(1).csw(0, 1, 2)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 26
0
 def test_ryy(self):
     """test 'ryy' gate
     """
     qc = QCirc().h(0).h(1).ryy(0, 1, phase=0.1).measure(qid=[0, 1],
                                                         cid=[0, 1])
     qs = QState(qubit_num=2).h(0).h(1).ryy(0, 1, phase=0.1)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 27
0
 def test_operate_controlled_xyz(self):
     """test 'operate' (xyz)
     """
     pp = PauliProduct(pauli_str="XYZ", qid=[1, 2, 3])
     qc = QCirc().operate(pp=pp, ctrl=0).measure(qid=[0, 1, 2, 3], cid=[0, 1, 2, 3])
     qs = QState(qubit_num=4).operate(pp=pp, ctrl=0)
     value = evaluate(qc, qs)
     self.assertEqual(value < EPS, True)
Exemplo n.º 28
0
 def test_operate_h_z(self):
     """test 'operate' (z followed by h)
     """
     qs_expect = QState(qubit_num=1).h(0)
     qs_actual = QState(qubit_num=1).h(0)
     pp = PauliProduct(pauli_str="Z")
     qs_expect.z(0)
     qs_actual.operate(pp=pp)
     ans = equal_qstates(qs_expect, qs_actual)
     self.assertEqual(ans, True)
Exemplo n.º 29
0
 def test_operate_controlled_xyz(self):
     """test 'operate' (controlled_xyz)
     """
     qs_expect = QState(qubit_num=4)
     qs_actual = QState(qubit_num=4)
     pp = PauliProduct(pauli_str="XYZ", qid=[2, 0, 1])
     qs_expect.cx(3, 2).cy(3, 0).cz(3, 1)
     qs_actual.operate(pp=pp, ctrl=3)
     ans = equal_qstates(qs_expect, qs_actual)
     self.assertEqual(ans, True)
Exemplo n.º 30
0
 def test_operate_xyz(self):
     """test 'operate' (xyz)
     """
     qs_expect = QState(qubit_num=3)
     qs_actual = QState(qubit_num=3)
     pp = PauliProduct(pauli_str="XYZ", qid=[2, 0, 1])
     qs_expect.x(2).y(0).z(1)
     qs_actual.operate(pp=pp)
     ans = equal_qstates(qs_expect, qs_actual)
     self.assertEqual(ans, True)