def test_concurrence(self):
     psi1 = [1, 0, 0, 0]
     rho1 = [[0.5, 0, 0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]]
     rho2 = [[0, 0, 0, 0], [0, 0.5, -0.5j, 0], [0, 0.5j, 0.5, 0],
             [0, 0, 0, 0]]
     rho3 = 0.5 * np.array(rho1) + 0.5 * np.array(rho2)
     rho4 = 0.75 * np.array(rho1) + 0.25 * np.array(rho2)
     test_pass = (concurrence(psi1) == 0.0 and concurrence(rho1) == 1.0
                  and concurrence(rho2) == 1.0 and concurrence(rho3) == 0.0
                  and concurrence(rho4) == 0.5)
     self.assertTrue(test_pass)
 def test_concurrence(self):
     psi1 = [1, 0, 0, 0]
     rho1 = [[0.5, 0, 0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]]
     rho2 = [[0, 0, 0, 0], [0, 0.5, -0.5j, 0], [0, 0.5j, 0.5, 0], [0, 0, 0, 0]]
     rho3 = 0.5 * np.array(rho1) + 0.5 * np.array(rho2)
     rho4 = 0.75 * np.array(rho1) + 0.25 * np.array(rho2)
     test_pass = concurrence(psi1) == 0.0 and \
         concurrence(rho1) == 1.0 and \
         concurrence(rho2) == 1.0 and \
         concurrence(rho3) == 0.0 and \
         concurrence(rho4) == 0.5
     self.assertTrue(test_pass)
Beispiel #3
0
 def test_concurrence(self):
     psi1 = [1, 0, 0, 0]
     rho1 = [[0.5, 0, 0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]]
     rho2 = [[0, 0, 0, 0], [0, 0.5, -0.5j, 0], [0, 0.5j, 0.5, 0],
             [0, 0, 0, 0]]
     rho3 = 0.5 * np.array(rho1) + 0.5 * np.array(rho2)
     rho4 = 0.75 * np.array(rho1) + 0.25 * np.array(rho2)
     concurrences = [
         concurrence(state) for state in [psi1, rho1, rho2, rho3, rho4]
     ]
     targets = [0.0, 1.0, 1.0, 0.0, 0.5]
     self.assertTrue(np.allclose(concurrences, targets))
print('Created State tomography circuits:')
for name in bell_tomo_circuit_names:
    print(name)

# Use the local simulator# Use t
backend = 'local_qasm_simulator'

# Take 5000 shots for each measurement basis
shots = 5000

# Run the simulation
bell_tomo_result = Q_program.execute(bell_tomo_circuit_names,
                                     backend=backend,
                                     shots=shots)
print(bell_tomo_result)

bell_tomo_data = tomo.tomography_data(bell_tomo_result, 'bell', bell_tomo_set)

rho_fit = tomo.fit_tomography_data(bell_tomo_data)

# calculate fidelity, concurrence and purity of fitted state# calcul
F_fit = state_fidelity(rho_fit, bell_psi)
con = concurrence(rho_fit)
pur = purity(rho_fit)

# plot
plot_state(rho_fit, 'paulivec')
plot_state(rho_fit, 'city')
print('Fidelity =', F_fit)
print('concurrence = ', str(con))
print('purity = ', str(pur))