Exemple #1
0
def trace_distance_max_mixed(steps, d):
    rho = q.Qobj(np.eye(d) / d)
    for _ in range(steps):
        q.metrics.tracedist(q.rand_dm_hs(d), rho)
Exemple #2
0
def random_mixed_state(steps, d):
    for _ in range(steps):
        q.rand_dm_hs(d)
Exemple #3
0
def trace_distance_random(steps, d):
    for _ in range(steps):
        q.metrics.tracedist(q.rand_dm_hs(d), q.rand_dm_hs(d))
Exemple #4
0
            exp = meas_1_obs(obs, s_final, nb_meas=nb_m, nb_r=nb_r)
    assert np.all(np.imag(exp) < 1e-5)
    return np.squeeze(np.real(exp))


Unit = ut.HDM
test_st = qt.rand_dm(2)
decomp_1q(test_st)
obs = qt.rand_herm(2)
perf = meas(obs, Unit, test_st, np.inf)
m = meas(obs, Unit, test_st, 1000, nb_r=1000)
m_dec = meas(obs, Unit, test_st, 1000, decomp=True, nb_r=1000)
np.sqrt(np.average(np.square(m - perf)))
np.sqrt(np.average(np.square(m_dec - perf)))

dm_list = [qt.rand_dm_hs(2) for r in range(50)]
op_list = [qt.rand_herm(2) for r in range(50)]

res_perfect = np.array([[meas(obs, Unit, test_st, np.inf) for op in op_list]
                        for dm in dm_list])
res_exp = np.array(
    [[meas(obs, Unit, test_st, 1000, nb_r=1000) for op in op_list]
     for dm in dm_list])
res_exp_decompo = np.array([[
    meas(obs, Unit, test_st, 1000, decomp=True, nb_r=1000) for op in op_list
] for dm in dm_list])

std_exp = np.sqrt(
    np.average(np.square(res_exp - res_perfect[:, :, np.newaxis]), -1))
std_exp_decompo = np.sqrt(
    np.average(np.square(res_exp_decompo - res_perfect[:, :, np.newaxis]), -1))


b2 = [ket2dm(tensor(A, B)) for A, B in it.product(st, st)] #basis of input states

cnot = tensor(ket2dm(zero1), I) + tensor(ket2dm(one1), X)
U = cnot

A = np.array(proj(b1, b2))
meas = [np.sum([A[k,l] * U * b1[k] * U.dag() for k in range(A.shape[0])])  for l in range(A.shape[1])]
isherm = np.all([m.isherm for m in meas])




dm = qutip.rand_dm_hs(4, dims=[[2, 2]] * 2).full()
# reshape to do the partial trace easily using np.einsum
reshaped_dm = dm.reshape([2, 2, 2, 2])
# compute the partial trace
reduced_dm = np.einsum('ijik->jk', reshaped_dm)




### Estimation error

s_Y_plus_1 = Y.eigenstates()[1][0]
state_basis = [st * st.dag() for st in [s_zero_1, s_one_1, s_plus_1, s_Y_plus_1]]
def decomp(state, basis):
    binv = np.linalg.inv(lqo2arr(basis))
    coeffs = binv.dot(vect(state))
Exemple #6
0
def trace_distance_max_mixed(steps, d):
    rho = q.Qobj(np.eye(d) / d)
    for _ in range(steps):
        q.metrics.tracedist(q.rand_dm_hs(d), rho)
Exemple #7
0
def trace_distance_random(steps, d):
    for _ in range(steps):
        q.metrics.tracedist(q.rand_dm_hs(d), q.rand_dm_hs(d))
Exemple #8
0
def random_mixed_state(steps, d):
    for _ in range(steps):
        q.rand_dm_hs(d)