def test_process_tomography_2qubit(self):
     # Tomography set
     tomo_set = tomo.process_tomography_set([0, 1])
     # Get test circuits
     qp, qr, cr = _test_circuits_2qubit()
     # Test simulation and fitting
     shots = 1000
     threshold = 1e-2
     ref_X1Id0 = np.array([0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0])
     choi = _tomography_test_data(qp, 'X1Id0', qr, cr, tomo_set, shots)
     self.assertTrue(_tomography_test_fit(choi, ref_X1Id0, threshold))
 def test_process_tomography_2qubit(self):
     # Tomography set
     tomo_set = tomo.process_tomography_set([0, 1])
     # Get test circuits
     qp, qr, cr = _test_circuits_2qubit()
     # Test simulation and fitting
     shots = 1000
     threshold = 0.015
     ref_X1Id0 = np.array(
         [0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0]) / 2
     choi = _tomography_test_data(qp, 'X1Id0', qr, cr, tomo_set, shots)
     self.assertTrue(_tomography_test_fit(choi, ref_X1Id0, threshold))
 def test_process_tomography_1qubit(self):
     # Tomography set
     tomo_set = tomo.process_tomography_set([0])
     # Get test circuits
     circuits, qr, cr = _test_circuits_1qubit()
     # Test simulation and fitting
     shots = 2000
     threshold = 1e-2
     choi = _tomography_test_data(circuits['Zp'], qr, cr, tomo_set, shots)
     self.assertTrue(
         _tomography_test_fit(choi, [1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)],
                              threshold))
     choi = _tomography_test_data(circuits['Xp'], qr, cr, tomo_set, shots)
     self.assertTrue(
         _tomography_test_fit(choi, [0.5, 0.5, 0.5, -0.5], threshold))
 def test_process_tomography_1qubit(self):
     # Tomography set
     tomo_set = tomo.process_tomography_set([0])
     # Get test circuits
     qp, qr, cr = _test_circuits_1qubit()
     # Test simulation and fitting
     shots = 2000
     threshold = 1e-2
     choi = _tomography_test_data(qp, 'Zp', qr, cr, tomo_set, shots)
     self.assertTrue(
         _tomography_test_fit(choi, [1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)],
                              threshold))
     choi = _tomography_test_data(qp, 'Xp', qr, cr, tomo_set, shots)
     self.assertTrue(
         _tomography_test_fit(choi, [0.5, 0.5, 0.5, -0.5], threshold))
def create_tomo_circuits(Quantum_program,
                         circuit_name,
                         quantum_register,
                         classical_register,
                         qubit_list,
                         meas_basis='Pauli',
                         prep_basis='Pauli'):
    # Create tomo set and tomo circuits; put them in the quantum program
    tomo_set = tomo.process_tomography_set(qubit_list, meas_basis, prep_basis)
    tomo_circuits = tomo.create_tomography_circuits(Quantum_program,
                                                    circuit_name,
                                                    quantum_register,
                                                    classical_register,
                                                    tomo_set)
    return [Quantum_program, tomo_set, tomo_circuits]
Beispiel #6
0
def create_tomo_circuits(Quantum_program,
                         circuit_name,
                         quantum_register,
                         classical_register,
                         qubit_list,
                         meas_basis='Pauli',
                         prep_basis='Pauli'):
    '''
    Create tomo set and tomo circuits for the circuit circuit_name in quantum_program.
    The circuits are put in the quantum program, and their names are returned as a list tomo_circuits
    The measurement basis and the preperation basis for the tomography circuits can be specified
    Standard is a Pauli basis for both meas and prep.
    The set of tomography experiments is also returned as tomo_set.
    This function is basically a wrapper for two qiskit:
    functions 'process_tomography_set' and 'create_tomograpy_circuits' in qiskit.tools.qcvv.tomography
    For more information on the containments of tomo_set and tomo_circuits see the documentation of these two functions
    '''
    tomo_set = tomo.process_tomography_set(qubit_list, meas_basis, prep_basis)
    tomo_circuits = tomo.create_tomography_circuits(Quantum_program,
                                                    circuit_name,
                                                    quantum_register,
                                                    classical_register,
                                                    tomo_set)
    return [Quantum_program, tomo_set, tomo_circuits]
Beispiel #7
0
cr = Q_program.create_classical_register("cr", 2)

# hadamard on qubit-1 only
had = Q_program.create_circuit("had", [qr], [cr])
had.h(qr[1])

# CNOT gate with qubit 1 control, qubit 0 target (target for ibmqx4)
cnot = Q_program.create_circuit("cnot", [qr], [cr])
cnot.cx(qr[1], qr[0])

U_had = np.array([[1, 1], [1, -1]])/np.sqrt(2)
# compute Choi-matrix from unitary
had_choi = outer(vectorize(U_had))
plot_state(had_choi)

had_tomo_set = tomo.process_tomography_set([1],'Pauli','Pauli')
had_tomo_circuits = tomo.create_tomography_circuits(Q_program, 'had',qr,cr,had_tomo_set)


backend  =  'local_qasm_simulator'
shots = 1000
had_tomo_results = Q_program.execute(had_tomo_circuits, shots=shots, backend=backend)

had_process_data = tomo.tomography_data(had_tomo_results,'had', had_tomo_set)
had_choi_fit = tomo.fit_tomography_data(had_process_data,'leastsq',options={'trace':2})
plot_state(had_choi_fit,'paulivec')


#unitary matrix for CNOT with qubit 1 as control and qubit 0 as target.
U_cnot = np.array([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]])
# compute Choi-matrix from unitary
 def test_process_tomography_set_default(self):
     tomo_set = tomo.process_tomography_set([0])
     default_set = tomo.process_tomography_set([0],
                                               meas_basis='Pauli',
                                               prep_basis='SIC')
     self.assertEqual(tomo_set['circuits'], default_set['circuits'])
 def test_process_tomography_set_default(self):
     tomo_set = tomo.process_tomography_set([0])
     default_set = tomo.process_tomography_set(
         [0], meas_basis='Pauli', prep_basis='SIC')
     self.assertEqual(tomo_set['circuits'], default_set['circuits'])