예제 #1
0
def main():

    # parameters for generating random state: |psi>
    alpha, beta, gamma = random.random(), random.random(), random.random()

    # reference state: T|psi>
    qs_expect = QState(1)
    qs_expect.rz(0, phase=alpha).rx(0, phase=beta).rz(0, phase=gamma).t(0)

    # prepare initial state
    qs = QState(3)
    qs.h(0).s(0)  # |Y>
    qs.h(1).t(1)  # |A>
    qs.rz(2, phase=alpha).rx(2, phase=beta).rz(2, phase=gamma)  # |psi>

    # T gate (only with X,Z,H,CNOT and measurement)
    qs.cx(1, 2)
    mval = qs.m(qid=[2]).last
    if mval == '1':
        qs.cx(1, 0).h(0).cx(1, 0).h(0)
        qs.x(1).z(1)
    qs_actual = qs.partial(qid=[1])

    # show the result
    print("== expect ==")
    qs_expect.show()
    print("== actual ==")
    qs_actual.show()
    print("== fidelity ==")
    print("{:.6f}".format(qs_actual.fidelity(qs_expect)))
예제 #2
0
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()
예제 #3
0
def main():

    print("== hadamard gate ==")

    print("** one-way quantum computing")

    # graph state
    qs_oneway = QState(5)
    qs_oneway.h(1).h(2).h(3).h(4)
    qs_oneway.cz(0, 1).cz(1, 2).cz(2, 3).cz(3, 4)

    # measurement
    qs_oneway.mx([0], shots=1)
    qs_oneway.my([1], shots=1)
    qs_oneway.my([2], shots=1)
    qs_oneway.my([3], shots=1)

    # result state
    qs_oneway.show([4])

    print("** conventianal quantum gate")

    qs_gate = QState(1)
    qs_gate.h(0)
    qs_gate.show()
예제 #4
0
def main():

    print("== general rotation ==")

    alpha = random.uniform(0.0, 1.0)
    beta = random.uniform(0.0, 1.0)
    gamma = random.uniform(0.0, 1.0)

    print("(euler angle = {0:.4f}, {1:.4f}, {2:.4f})".format(
        alpha, beta, gamma))

    print("** one-way quantum computing")

    # graph state
    qs_oneway = QState(5)
    qs_oneway.h(1).h(2).h(3).h(4)
    qs_oneway.cz(0, 1).cz(1, 2).cz(2, 3).cz(3, 4)

    # measurement
    alpha_oneway = alpha
    beta_oneway = beta
    gamma_oneway = gamma
    s0 = qs_oneway.m([0], shots=1, angle=0.5, phase=0.0).lst
    if s0 == 1:
        alpha_oneway = -alpha_oneway
    s1 = qs_oneway.m([1], shots=1, angle=0.5, phase=alpha_oneway).lst
    if s1 == 1:
        beta_oneway = -beta_oneway
    s2 = qs_oneway.m([2], shots=1, angle=0.5, phase=beta_oneway).lst
    if (s0 + s2) % 2 == 1:
        gamma_oneway = -gamma_oneway
    s3 = qs_oneway.m([3], shots=1, angle=0.5, phase=gamma_oneway).lst

    # result state
    qs_oneway.show([4])

    print("** conventianal quantum gate")

    qs_gate = QState(1)
    qs_gate.rx(0, phase=alpha).rz(0, phase=beta).rx(0, phase=gamma)
    qs_gate.show()
예제 #5
0
def main():

    print("== CNOT gate ==")

    print("** one-way quantum computing")

    # graph state
    qs_oneway = QState(15)
    qs_oneway.h(0)
    qs_oneway.h(1).h(2).h(3).h(4).h(5).h(6).h(7)
    qs_oneway.h(9).h(10).h(11).h(12).h(13).h(14)
    qs_oneway.cz(0, 1).cz(1, 2).cz(2, 3).cz(3, 4).cz(4, 5).cz(5, 6)
    qs_oneway.cz(3, 7).cz(7, 11)
    qs_oneway.cz(8, 9).cz(9, 10).cz(10, 11).cz(11, 12).cz(12, 13).cz(13, 14)

    # measurement
    qs_oneway.mx([0], shots=1)
    qs_oneway.my([1], shots=1)
    qs_oneway.my([2], shots=1)
    qs_oneway.my([3], shots=1)
    qs_oneway.my([4], shots=1)
    qs_oneway.my([5], shots=1)
    qs_oneway.my([7], shots=1)
    qs_oneway.mx([8], shots=1)
    qs_oneway.mx([9], shots=1)
    qs_oneway.mx([10], shots=1)
    qs_oneway.my([11], shots=1)
    qs_oneway.mx([12], shots=1)
    qs_oneway.mx([13], shots=1)

    qs_oneway.show([6, 14])

    print("** conventianal quantum gate")

    qs_gate = QState(2)
    qs_gate.h(0)
    qs_gate.cx(0, 1)
    qs_gate.show()
예제 #6
0
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)
elif result == BELL_PSI_MINUS:
    print("result: psi-")
예제 #7
0
파일: t_gate.py 프로젝트: samn33/qlazy

def faulttolerant_m(qs_in):

    anc = [0, 1, 2, 3, 4, 5, 6]  # ancila
    cod = [7, 8, 9, 10, 11, 12, 13]  # steane code
    qs_anc = QState(7)
    qs_total = qs_anc.tenspro(qs_in)

    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 7)]
    [qs_total.cz(anc[i], cod[i]) for i in range(7)]
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 7)]
    qs_total.h(anc[0])
    md = qs_total.m(qid=[0], shots=10000)

    return md


if __name__ == '__main__':

    qs = QState(1).h(0).t(0).h(0)  # not fault-tolerant -HTH-
    qs.show()

    qs_ini = logical_zero()  # make initial state (logical zero)
    [qs_ini.h(i) for i in range(7)]  # operate fault-tolerant H
    qs_fin = faulttolerant_t(qs_ini)  # operate fault-tlerant T
    [qs_fin.h(i) for i in range(7)]  # operate fault-tolerant H
    md = faulttolerant_m(qs_fin)  # execute fault-tolerant measurement
    print(md.frequency)
예제 #8
0
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])