matrix = densop.get_elm() eigvals = eigh(matrix, eigvals_only=True) eigvals_out = [eigvals[i] for i in range(len(eigvals)) if eigvals[i] > MIN_DOUBLE] return eigvals_out if __name__ == '__main__': # whole quantum state qubit_num = 5 qs = random_qstate(qubit_num) de = DensOp(qstate=[qs], prob=[1.0]) # pure state # partial density operators (system A and B) id_A, id_B = random_qubit_id(qubit_num) de_A = de.patrace(id_B) de_B = de.patrace(id_A) # eigen-values of density operators (system A and B) eval_A = eigen_values(de_A) eval_B = eigen_values(de_B) print("== system A ==") print("- qubit id =", id_A) print("- square trace = ", de_A.sqtrace()) print("- eigen values =", eval_A) print("- rank =", len(eval_A)) print("== system B ==") print("- qubit id =", id_B) print("- square trace = ", de_B.sqtrace())
from qlazy import QState, DensOp qs = QState(4) qs.h(0).h(1) # unitary operation for 0,1-system qs.x(2).z(3) # unitary operation for 2,3-system de1 = DensOp(qstate=[qs], prob=[1.0]) # product state de1_reduced = de1.patrace([0,1]) # trace-out 0,1-system print("== partial trace of product state ==") print(" * trace = ", de1_reduced.trace()) print(" * square trace = ", de1_reduced.sqtrace()) qs.cx(1,3).cx(0,2) # entangle between 0,1-system and 2,3-system de2 = DensOp(qstate=[qs], prob=[1.0]) # entangled state de2_reduced = de2.patrace([0,1]) # trace-out 0,1-system print("== partial trace of entangled state ==") print(" * trace = ", de2_reduced.trace()) print(" * square trace = ", de2_reduced.sqtrace()) print("== partial state of entangled state ==") qs.show([2,3])