print("== parameter ==") gamma = 0.5 H = make_hamiltonian() print("gamma =", gamma) print("== initial density operator ==") u_1 = math.sqrt(1 / 3) u_2 = math.sqrt(1 / 3) u_3 = math.sqrt(1 / 3) D = make_densop_matrix(u_1, u_2, u_3) de = DensOp(matrix=D) de.show() print("square trace =", de.sqtrace()) print("(u_1,u_2,u_3) = ({0:.3f},{1:.3f},{2:.3f})".format(u_1, u_2, u_3)) print("expect value of energy =", de.expect(matrix=H)) [M_0, M_1] = make_kraus(gamma=gamma) print("== finail density operator ==") de.instrument(kraus=[M_0, M_1]) de.show() print("square trace =", de.sqtrace()) (u_1, u_2, u_3) = get_coordinate(densop=de) print("(u_1,u_2,u_3) = ({0:.3f},{1:.3f},{2:.3f})".format(u_1, u_2, u_3)) print("expect value of energy =", de.expect(matrix=H))
return densop_est if __name__ == '__main__': # settings qubit_num = 1 mixed_num = 2 shots = 100 # quantum state ensemble (original) qstate, prob = random_qstate_ensemble(qubit_num, mixed_num) # density operator (original) densop_ori = DensOp(qstate=qstate, prob=prob) # density operator estimation only from quantum state ensemble # (quantum state tomography) densop_est = estimate_densop(prob, qstate, shots) print("** density operator (original)") densop_ori.show() print("** density operator (estimated)") densop_est.show() print("** fidelity =", densop_ori.fidelity(densop_est)) for q in qstate: q.free() densop_ori.free() densop_est.free()
from qlazypy import QState, DensOp qs_pure = QState(1).h(0) # (|0> + |1>) / sqrt(2.0) de_pure = DensOp(qstate=[qs_pure], prob=[1.0]) qs_pure_1 = QState(1) # |0> qs_pure_2 = QState(1).x(0) # |1> de_mixed = DensOp(qstate=[qs_pure_1, qs_pure_2], prob=[0.5, 0.5]) print("== pure state ==") de_pure.show() print("* trace =", de_pure.trace()) print("* square trace =", de_pure.sqtrace()) print("") print("== mixed state ==") de_mixed.show() print("* trace =", de_mixed.trace()) print("* square trace =", de_mixed.sqtrace()) qs_pure.free() qs_pure_1.free() qs_pure_2.free() de_pure.free() de_mixed.free()