def wireswitch(wire1, wire2, nbits): """ Switch two wires (given by the wire1 and wire2 arguments ) in a n qubit circuit NUmbering starts from zero """ N = np.power(2,nbits) w1 = np.power(2,wire1) w2 = np.power(2,wire2) M = np.asmatrix(np.zeros((N,N), dtype = complex)) for i in range(N): ev = np.zeros(nbits,dtype = int) reg1 = qr.getbasis(nbits,i) binlist = np.array(list(bin(i)[2:]), dtype = int) ev[nbits-binlist.size:] = binlist j = i - ev[wire1]*w1 - ev[wire2]*w2 + ev[wire1]*w2 + ev[wire2]*w1 reg2 = qr.getbasis(nbits,j) M = M + outerprod(reg2,reg1) return qo.Qoperator(nbits,M)
def wireswitch(wire1, wire2, nbits): """ Switch two wires (given by the wire1 and wire2 arguments ) in a n qubit circuit NUmbering starts from zero """ N = np.power(2, nbits) w1 = np.power(2, wire1) w2 = np.power(2, wire2) M = np.asmatrix(np.zeros((N, N), dtype=complex)) for i in range(N): ev = np.zeros(nbits, dtype=int) reg1 = qr.getbasis(nbits, i) binlist = np.array(list(bin(i)[2:]), dtype=int) ev[nbits - binlist.size:] = binlist j = i - ev[wire1] * w1 - ev[wire2] * w2 + ev[wire1] * w2 + ev[ wire2] * w1 reg2 = qr.getbasis(nbits, j) M = M + outerprod(reg2, reg1) return qo.Qoperator(nbits, M)
def switchop(nxbits, nybits): """ Go from row major order to column major order by wire switching """ nbits = nxbits + nybits N = np.power(2, nbits) arr = np.arange(nbits - 1, -1, -1) powarr = pow(2, arr) M = np.asmatrix(np.zeros((N, N), dtype=complex)) for i in range(N): ev = np.zeros(nbits, dtype=int) reg1 = qr.getbasis(nbits, i) binlist = np.array(list(bin(i)[2:]), dtype=int) ev[nbits - binlist.size:] = binlist newbin = np.zeros(nbits, dtype=int) #TODO CHECK CORRECTNESS OF SWAPPINGS newbin[nxbits:] = ev[:nybits] newbin[:nxbits] = ev[nybits:] j = np.inner(powarr, newbin) reg2 = qr.getbasis(nbits, j) M = M + qr.outerprod(reg2, reg1) return qo.Qoperator(nbits, M)
def switchop(nxbits,nybits): """ Go from row major order to column major order by wire switching """ nbits = nxbits + nybits N = np.power(2,nbits) arr = np.arange(nbits-1,-1,-1) powarr = pow(2,arr) M = np.asmatrix(np.zeros((N,N), dtype = complex)) for i in range(N): ev = np.zeros(nbits,dtype = int) reg1 = qr.getbasis(nbits,i) binlist = np.array(list(bin(i)[2:]), dtype = int) ev[nbits-binlist.size:] = binlist newbin = np.zeros(nbits,dtype =int) #TODO CHECK CORRECTNESS OF SWAPPINGS newbin[nxbits:] = ev[:nybits] newbin[:nxbits] = ev[nybits:] j = np.inner(powarr,newbin) reg2 = qr.getbasis(nbits,j) M = M + qr.outerprod(reg2,reg1) return qo.Qoperator(nbits,M)