예제 #1
0
 def test_simultaneous_gates(self):
     qubit_list = ['q0', 'q1']
     with pytest.warns(UserWarning):
         # We did not provide any seed
         setup = quick_setup(qubit_list)
     b = Builder(setup)
     b < ('RY', 'q0', np.pi/2)
     b < (('RY', 'q0', np.pi/2), ('RY', 'q1', np.pi/2))
     assert b.circuit.gates[-2].time == b.circuit.gates[-1].time
     assert b.times['q0'] == b.times['q1']
예제 #2
0
    def test_T1T2(self):

        qubit_dic = {'q_test': {'t1': 10, 't2': 20}}
        gate_dic = {}
        gate_set = {}
        b = Builder(qubit_dic=qubit_dic,
                    gate_dic=gate_dic,
                    gate_set=gate_set,
                    circuit_title='Test')
        assert b.circuit.qubits[0].t1 == 10
        assert b.circuit.qubits[0].t2 == 20
예제 #3
0
    def test_override(self):
        qubit_list = ['swap', 'cp']
        with pytest.warns(UserWarning):
            # We did not provide any seed
            setup = quick_setup(qubit_list, noise_flag=False)
        b = Builder(setup)
        b < ('RotateY', 'swap', np.pi/2)
        b < ('RotateY', 'cp', np.pi/2)
        b < ('CZ', 'cp', 'swap')
        b < ('RotateY', 'cp', -np.pi/2)
        b.finalize()

        bell_circuit = b.circuit
        bell_state = SparseDM(bell_circuit.get_qubit_names())
        bell_circuit.apply_to(bell_state)
        diag = np.diag(bell_state.full_dm.to_array())

        assert np.abs(diag[0]-0.5) < 1e-10
        assert np.abs(diag[3]-0.5) < 1e-10
        assert np.abs(diag[1]) < 1e-10
        assert np.abs(diag[2]) < 1e-10
예제 #4
0
 def test_T1T2_kwarginit(self):
     qubit_dic = {'q_test': {}}
     gate_dic = {}
     gate_set = {}
     b = Builder(qubit_dic=qubit_dic,
                 gate_dic=gate_dic,
                 gate_set=gate_set,
                 circuit_title='Test',
                 t1=20,
                 t2=30)
     assert b.circuit.qubits[0].t1 == 20
     assert b.circuit.qubits[0].t2 == 30
예제 #5
0
 def test_artificial_time(self):
     qubit_list = ['q0']
     with pytest.warns(UserWarning):
         # We did not provide any seed
         setup = quick_setup(qubit_list)
     b = Builder(setup)
     b.add_gate('RY', ['q0'], angle=np.pi/2)
     b.add_gate('RY', ['q0'], angle=np.pi/2, time=0)
     assert b.times['q0'] == setup.gate_set[('RY', 'q0')][1]['gate_time']
     assert b.circuit.gates[-1].time == 0
예제 #6
0
    def test_init(self):

        qubit_dic = {'q_test': {}}
        gate_dic = {}
        gate_set = {}
        b = Builder(qubit_dic=qubit_dic,
                    gate_dic=gate_dic,
                    gate_set=gate_set,
                    circuit_title='Test')
        assert len(b.qubit_dic.keys()) == 1
        assert b.gate_dic == {}
        assert b.gate_set == {}
        assert len(b.times.keys()) == 1
        assert b.circuit.title == 'Test'
        assert len(b.circuit.qubits) == 1
        assert b.circuit.qubits[0].name == 'q_test'
        assert b.circuit.qubits[0].t1 == np.inf
        assert b.circuit.qubits[0].t2 == np.inf
예제 #7
0
    def test_qasm(self):
        qubit_list = ['swap', 'cp']
        with pytest.warns(UserWarning):
            # We did not provide any seed
            setup = quick_setup(qubit_list, noise_flag=False)
        b = Builder(setup)
        qasm0 = 'Ry 1.57079632679 swap'
        qasm1 = 'Ry 1.57079632679 cp'
        qasm2 = 'CZ cp swap'
        qasm3 = 'Ry -1.57079632679 cp'
        qasm_list = [qasm0, qasm1, qasm2, qasm3]
        b.add_qasm(qasm_list, qubits_first=False)
        b.finalize()

        bell_circuit = b.circuit
        bell_state = SparseDM(bell_circuit.get_qubit_names())
        bell_circuit.apply_to(bell_state)
        diag = np.diag(bell_state.full_dm.to_array())

        assert np.abs(diag[0]-0.5) < 1e-10
        assert np.abs(diag[3]-0.5) < 1e-10
        assert np.abs(diag[1]) < 1e-10
        assert np.abs(diag[2]) < 1e-10
예제 #8
0
    def test_make_imperfect_bell(self):
        qubit_list = ['swap', 'cp']
        with pytest.warns(UserWarning):
            # We did not provide any seed
            setup = quick_setup(qubit_list)
        b = Builder(setup)
        b.add_gate('RotateY', ['swap'], angle=np.pi/2)
        b.add_gate('RotateY', ['cp'], angle=np.pi/2)
        b.add_gate('CZ', ['cp', 'swap'])
        b.add_gate('RotateY', ['cp'], angle=-np.pi/2)
        b.finalize()

        bell_circuit = b.circuit
        bell_state = SparseDM(bell_circuit.get_qubit_names())
        bell_circuit.apply_to(bell_state)
        diag = np.diag(bell_state.full_dm.to_array())

        assert np.abs(diag[0]-0.5) < 1e-2
        assert np.abs(diag[3]-0.5) < 1e-2
        assert np.abs(diag[1]) < 3e-2
        assert np.abs(diag[2]) < 3e-2