Esempio n. 1
0
def make_target(nf, nq, ptype, n_bit, n_bits):
    id_list = lambda: [qutip.qeye(2) for _ in range(n_bits + 1)]
    x_ops = [id_list() for _ in range(n_bits)]
    z_ops = [id_list() for _ in range(n_bits)]
    h_ops = [id_list() for _ in range(n_bits)]
    ih_ops = [id_list() for _ in range(n_bits)]
    cx_ops = []
    m_cz_ops = []
    m_cx_ops = []
    m_cy_ops = []

    for i in range(n_bits):
        z_ops[i][i + 1] = qutip.sigmaz()
        x_ops[i][i + 1] = qutip.sigmax()
        h_ops[i][i + 1] = qutip.hadamard_transform()
        ih_ops[i][i + 1] = qutip.Qobj([[-1, 1], [-1j, -1j]]) / sqrt(2)
        z_ops[i] = qutip.tensor(*z_ops[i])
        x_ops[i] = qutip.tensor(*x_ops[i])
        h_ops[i] = qutip.tensor(*h_ops[i])
        ih_ops[i] = qutip.tensor(*ih_ops[i])
        cx_ops.append(
            qutip.controlled_gate(qutip.hadamard_transform(), n_bits + 1,
                                  i + 1, 0))
        m_cz_ops.append(
            qutip.controlled_gate(qutip.sigmax(), n_bits + 1, i + 1, 0))
        m_cx_ops.append(h_ops[i] * m_cz_ops[i] * h_ops[i])
        m_cy_ops.append(ih_ops[i] * m_cz_ops[i] * ih_ops[i])

    for ops in (x_ops, z_ops, h_ops, m_cz_ops, m_cx_ops, m_cy_ops):
        ops.reverse()

    bits_n = 2**n_bits
    flip_target = id_list()
    flip_target[0] = qutip.sigmax()
    flip_target = qutip.tensor(*flip_target)
    if ptype == 'i':
        targ = qutip.tensor(*id_list())
    elif ptype == 'mz':
        targ = m_cz_ops[n_bit - 1] * flip_target
    elif ptype == 'mx':
        targ = m_cx_ops[n_bit - 1]
    elif ptype == 'my':
        targ = m_cy_ops[n_bit - 1]
    elif ptype == 'x':
        targ = x_ops[n_bit - 1]
    elif ptype == 'z':
        targ = z_ops[n_bit - 1]
    U = np.zeros((nq * nf, nq * nf), dtype=np.complex)
    U[:bits_n, :bits_n] = targ[:bits_n, :bits_n]
    U[nf:nf + bits_n, :bits_n] = targ[bits_n:, :bits_n]
    U[:bits_n, nf:nf + bits_n] = targ[:bits_n, bits_n:]
    U[nf:nf + bits_n, nf:nf + bits_n] = targ[bits_n:, bits_n:]
    mask_c = np.zeros(nf)
    mask_c[:bits_n] = 1
    mask_q = np.zeros(nq)
    mask_q[:2] = 1
    mask = np.kron(mask_q, mask_c)
    mask = np.arange(len(mask))[mask == 1]
    return U, mask
Esempio n. 2
0
def circuitDecodingSimulation(psi0, c_ops=[]):
    N = 8
    schedule = []
    # decoding, stage 1, 2
    schedule += [snot(N=N, target=i) for i in [5, 7]]
    # decoding, stage 3
    schedule += [
        controlled_gate(sigmaz(), N=N, control=4, target=5),
        controlled_gate(sigmaz(), N=N, control=6, target=7)
    ]
    # decoding, stage 4, 5
    schedule += [snot(N=N, target=i) for i in [4, 5, 6]]
    # perform time evolution and return the final state
    return scheduledUnitaryEvolution(psi0, schedule)
 def testCZHamiltonianMore(self):
     t = np.pi
     H1 = constructCZH(4, [0], [1])
     H2 = constructCZH(4, [2], [3])
     U1 = controlled_gate(sigmaz(), N=4, control=0, target=1)
     U2 = controlled_gate(sigmaz(), N=4, control=2, target=3)
     for psiA in [z0, z1]:
         for psiB in [xp, xm]:
             for psiC in [z0, z1]:
                 for psiD in [xp, xm]:
                     psi0 = tensor([psiA, psiB, psiC, psiD])
                     psiu = U2*U1*psi0
                     psic = evolve(H1, t/2., psi0)
                     psic = evolve(H2, t/2., psic)
                     overl = psiu.overlap(psic)
                     assert are_close(overl, 1., atol=1e-04)
     assert H1.isherm
     assert H2.isherm
 def testCZHamiltonian(self):
     t = np.pi
     H = constructCZH(2, [0], [1])
     U = controlled_gate(sigmaz(), N=2, control=0, target=1)
     states = [z0, z1, xp, xm, yp, ym, rand_ket(2)]
     for psiA in states:
         for psiB in states:
             psi0 = tensor([psiA, psiB])
             psiu = U*psi0
             psic = evolve(H, t/2., psi0)
             overl = psiu.overlap(psic)
             assert are_close(overl, 1., atol=1e-04)
     assert H.isherm
Esempio n. 5
0
def circuitZBraidingCorrectionSimulation(psi0, c_ops=[]):
    N = 8
    schedule = []
    for i in range(2):
        # Z braiding, stage 1
        schedule += [rx(np.pi / 2., N=N, target=i) for i in [4, 5]]
        # Z braiding, stage 2
        schedule += [rz(-np.pi / 2., N=N, target=i) for i in [4, 5]]
        # Z braiding, stage 3
        schedule += [controlled_gate(sigmaz(), N=N, control=4, target=5)]
        # Z braiding, stage 4
        schedule += [rx(-np.pi / 2., N=N, target=i) for i in [4, 5]]
    # perform time evolution and return the final state
    return scheduledUnitaryEvolution(psi0, schedule)
Esempio n. 6
0
def circuitTeleportationSimulation(psi, c_ops=[]):
    N = 8
    psi0 = tensor([basis(2, 0), psi] + [basis(2, 0) for i in range(N - 2)])
    schedule = []
    # encoding, Hadamards stage 1, 2
    schedule += [snot(N=N, target=i) for i in range(N)]
    # encoding, CZs, stage 3
    schedule += [
        controlled_gate(sigmaz(), N=N, control=0, target=1),
        controlled_gate(sigmaz(), N=N, control=2, target=3),
        controlled_gate(sigmaz(), N=N, control=4, target=5)
    ]
    # encoding, Hadamards, stage 4, 5
    schedule += [snot(N=N, target=i) for i in [1, 3, 5]]
    # teleportation, stage 6
    schedule += [ry(np.pi / 2., N=N, target=i) for i in [1, 2, 3, 4]]
    # teleportation, stage 7
    schedule += [rz(-np.pi / 2., N=N, target=i) for i in [1, 2, 3, 4]]
    # teleportation, stage 8
    schedule += [
        controlled_gate(sigmaz(), N=N, control=1, target=2),
        controlled_gate(sigmaz(), N=N, control=3, target=4)
    ]
    # teleportation, stage 9
    schedule += [ry(-np.pi / 2., N=N, target=i) for i in [1, 2, 3, 4]]
    # decoding, stage 10, 11
    schedule += [snot(N=N, target=i) for i in [1, 3]]
    # decoding, stage 12
    schedule += [
        controlled_gate(sigmaz(), N=N, control=0, target=1),
        controlled_gate(sigmaz(), N=N, control=2, target=3)
    ]
    # decoding, stage 13, 14
    schedule += [snot(N=N, target=i) for i in [0, 1, 2, 3]]
    # perform time evolution and return the final state
    return scheduledUnitaryEvolution(psi0, schedule)
Esempio n. 7
0
tgt3_W = {n: op.matrix_element(W, W) for n, op in zip(tp_name3, tp_op3)}

for k, v in tgt3_W.items():
    if np.abs(v)>1e-6:
        print(k, v)

## 4 qubits
ghz4 = 1/np.sqrt(2) * (qt.tensor(zero, zero, zero,zero) - qt.tensor(one, one, one,one))
tp_name4, tp_op4 = tensor_paulis(4)
tgt4 = {n: op.matrix_element(ghz4, ghz4) for n, op in zip(tp_name4, tp_op4)}

for k, v in tgt4.items():
    if np.abs(v)>1e-6:
        print(k, v)
        
cluster4 = qt.controlled_gate(qt.sigmaz(), 4, 2, 3) * qt.controlled_gate(qt.sigmaz(), 4, 1, 2) * qt.controlled_gate(qt.sigmaz(), 4, 0, 3) *qt.controlled_gate(qt.sigmaz(), 4, 0, 1) * qt.tensor(plus, plus, plus, plus)
tgt4_cluster = {n: op.matrix_element(cluster4, cluster4) for n, op in zip(tp_name4, tp_op4)}

for k, v in tgt4_cluster.items():
    if np.abs(v)>1e-6:
        print(k, v)

### ====================================================================== ###
### STUDY 0: Replicate some of the models
###          
###          
### ====================================================================== ###



### ====================================================================== ###
 def testCZUnitary(self):
     H = constructCZH(2, [0], [1])
     U = controlled_gate(sigmaz(), N=2, control=0, target=1)
     U2 = deriveUnitary(H, np.pi)
     assert U == U2
     assert H.isherm