Perm4 = np.dot(Perm2, Perm2) # define the gate sequence # currently counting qubits from the RIGHT # i.e. "01000" == |y> = |01>, H and QFT on |000>, input state = int(01000,2) = 8 Useq = [ \ U.R(U.H, 5, 0), \ U.R(U.H, 5, 1), \ U.R(U.H, 5, 2), \ # target qubits 3,4, control on 0,1,2 U.controlMN(5, Perm, 2, 1, 3, 2), \ U.controlMN(5, Perm2, 1, 1, 3, 2), \ U.controlMN(5, Perm4, 0, 1, 3, 2), \ # Uqft part 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) ] 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) ]
import PyTIQC.core.gates as U import numpy as np import matplotlib.pyplot as pl pi = np.pi N = 7 # 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), \
# define the gate sequence # currently counting qubits from the RIGHT # i.e. "01000" == |y> = |01>, H and QFT on |000>, input state = int(01000,2) = 8 Useq = [ \ U.R(U.H, 5, 0), \ U.R(U.H, 5, 1), \ U.R(U.H, 5, 2), \ # target qubits 3,4, control on 0,1,2 U.controlMN(5, Perm, 2, 1, 3, 2), \ U.controlMN(5, Perm2, 1, 1, 3, 2), \ U.controlMN(5, Perm4, 0, 1, 3, 2), \ # Uqft part 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) ] 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) ]