def main(): a = random.uniform(0.0, 1.0) b = random.uniform(0.0, 1.0) phi = random.uniform(0.0, 1.0) print("a,b = {0:.4f}, {1:.4f}".format(a,b)) print("phi = {0:.4f}".format(phi)) print("** one-way quantum computing") # graph state qs_oneway = QState(2) qs_oneway.ry(0, phase=a).rz(0, phase=b) # input state (random) qs_oneway.h(1) qs_oneway.cz(0,1) # measurement s = qs_oneway.m([0], shots=1, angle=0.5, phase=phi) # result state qs_oneway.show([1]) print("** conventianal quantum gate") qs_gate = QState(1) qs_gate.ry(0, phase=a).rz(0, phase=b) # input state (random) qs_gate.rz(0, phase=-phi).h(0) qs_gate.show()
from qlazy import QState BELL_PHI_PLUS = 0 BELL_PHI_MINUS = 3 BELL_PSI_PLUS = 1 BELL_PSI_MINUS = 2 qs = QState(3) # prepare qubit (id=0) that Alice want to send to Bob by rotating around X,Z qs.ry(0,phase=0.3).rz(0,phase=0.4) # make entangled 2 qubits (id=1 for Alice, id=2 for Bob) qs.h(1).cx(1,2) # initial state (before teleportation) print("== Alice (initial) ==") qs.show([0]) print("== Bob (initial) ==") qs.show([2]) # Alice execute Bell-measurement to her qubits 0,1 print("== Bell measurement ==") result = qs.mb([0,1],shots=1).lst # Bob operate his qubit (id=2) according to the result if result == BELL_PHI_PLUS: print("result: phi+") elif result == BELL_PSI_PLUS: print("result: psi+") qs.x(2)