예제 #1
0
# easy Shor case
Useq = [ \
    U.R(U.H, N, 0), \
    U.R(U.H, N, 1), \
    U.R(U.H, N, 2), \
    # target qubits 3,4,5,6, control on 0,1,2
    U.control(N, U.X, 2, 4), \
    U.control(N, U.X, 2, 5), \
    # Uqft part
    U.R(U.H, N, 0), \
    U.control(N, U.S, 1, 0), \
    U.R(U.H, N, 1), \
    U.control(N, U.T, 2, 0), \
    U.control(N, U.S, 2, 1), \
    U.R(U.H, N, 2) ]
Ushor11 = np.around(U.dotN(Useq), 10)

# hard Shor case
Useq = [ \
    U.R(U.H, N, 0), \
    U.R(U.H, N, 1), \
    U.R(U.H, N, 2), \
    # target qubits 3,4,5,6, control on 0,1,2
    U.control(N, U.X, 2, 4), \
    U.control(N, U.X, 2, 5), \
    # what we want here: Fredkin(N, 0, swap(3,5)), Fredkin(N, 0, swap(4,6))
    U.CNOT(N, 3, 5), \
    U.Toffoli(N, 1, 5, 3), \
    U.CNOT(N, 3, 5), \
    U.CNOT(N, 6, 4), \
    U.Toffoli(N, 1, 4, 6), \
예제 #2
0
파일: cnot.py 프로젝트: sxwang/TIQC-SPICE
N = 3 #number of qubits

# the Innsbruck pulse sequence
Useq = [ \
    U.Ux(pi/2, N),
    U.Uz(pi/2, N, 0),
    U.MS(pi/4, 0, N),
    U.Ux(pi/4, N),
    U.Uz(pi, N, 2),
    U.Ux(pi/4, N),
    U.MS(pi/4, 0, N),
    U.Uz(pi/2, N, 0),
    U.Ux(pi/2, N),
    U.Uz(pi, N, 2) ]

Ucnot = U.dotN(Useq)
Ucnot = np.around(Ucnot, 10)

# calculate the states
psi = np.zeros(2**N, np.complex64)
psi[-1] = 1
psi = psi.T

# time evolution
Y = np.zeros([2**N, len(Useq)+1], np.complex128)
Y[:,0] = psi.T
i=1
while i<=len(Useq):
  Y[:,i] = np.dot(Useq[i-1], Y[:,i-1])
  i = i+1
예제 #3
0
N = 3  #number of qubits

# the Innsbruck pulse sequence
Useq = [ \
    U.Ux(pi/2, N),
    U.Uz(pi/2, N, 0),
    U.MS(pi/4, 0, N),
    U.Ux(pi/4, N),
    U.Uz(pi, N, 2),
    U.Ux(pi/4, N),
    U.MS(pi/4, 0, N),
    U.Uz(pi/2, N, 0),
    U.Ux(pi/2, N),
    U.Uz(pi, N, 2) ]

Ucnot = U.dotN(Useq)
Ucnot = np.around(Ucnot, 10)

# calculate the states
psi = np.zeros(2**N, np.complex64)
psi[-1] = 1
psi = psi.T

# time evolution
Y = np.zeros([2**N, len(Useq) + 1], np.complex128)
Y[:, 0] = psi.T
i = 1
while i <= len(Useq):
    Y[:, i] = np.dot(Useq[i - 1], Y[:, i - 1])
    i = i + 1
예제 #4
0
  U.control(5, U.S, 2, 1), \
  U.R(U.H, 5, 2)]#, \
  #U.swap(5, 0, 2)  ]

Uqft = [ \
  U.R(U.H, 5, 0), \
  U.control(5, U.S, 1, 0), \
  U.R(U.H, 5, 1), \
  U.control(5, U.T, 2, 0), \
  U.control(5, U.S, 2, 1), \
  U.R(U.H, 5, 2), \
  U.swap(5, 0, 2)  ]


# calculate overall unitary
Uof = U.dotN(Useq)
Uof = np.around(Uof, 10)


### batch process a set of 4 states
psilist = [0, 8, 16, 24] # binary for 00000,01000,10000,11000
for ind in psilist:
    # calculate the states
    psi = np.zeros(32, np.complex64)
    psi[ind] = 1
    psi = psi.T

    # time evolution
    [Y,YR,rho] = U.calculateevolution(Useq, 5, y0=psi.T)

    # final state
예제 #5
0
  U.control(5, U.T, 2, 0), \
  U.control(5, U.S, 2, 1), \
  U.R(U.H, 5, 2)]#, \
#U.swap(5, 0, 2)  ]

Uqft = [ \
  U.R(U.H, 5, 0), \
  U.control(5, U.S, 1, 0), \
  U.R(U.H, 5, 1), \
  U.control(5, U.T, 2, 0), \
  U.control(5, U.S, 2, 1), \
  U.R(U.H, 5, 2), \
  U.swap(5, 0, 2)  ]

# calculate overall unitary
Uof = U.dotN(Useq)
Uof = np.around(Uof, 10)

### batch process a set of 4 states
psilist = [0, 8, 16, 24]  # binary for 00000,01000,10000,11000
for ind in psilist:
    # calculate the states
    psi = np.zeros(32, np.complex64)
    psi[ind] = 1
    psi = psi.T

    # time evolution
    [Y, YR, rho] = U.calculateevolution(Useq, 5, y0=psi.T)

    # final state
    psiout = np.dot(Uof, psi)