def alter_hadamard(hada,seed): (n,n)=hada.shape theta = uniform(0.0,math.pi*2.0) #pick a rotation any rotation phaser=randint(0,3) if phaser ==0: gate=qt.phasegate(theta) elif phaser == 1: gate=qt.rz(theta) elif phaser==2: gate = qt.ry(theta) else: gate=qt.globalphase(theta) #alter gate if seed == 0: u1=gate else: u1=id2 i=1 while u1.shape != (n,n): if i ==seed: #set a alteration on specified qubit u1=qt.tensor(u1,gate) u1=tensor_fix(u1) else: u1=qt.tensor(u1,id2) u1=tensor_fix(u1) i+=1 final_gate=u1*hada return final_gate
def rando(orig): (n, n) = orig.shape theta = uniform(0.0, math.pi * 2.0) #pick a rotation any rotation phaser = randint(0, 3) if phaser == 0: gate = qt.phasegate(theta) elif phaser == 1: gate = qt.rz(theta) elif phaser == 2: gate = qt.ry(theta) else: gate = qt.globalphase(theta) (m, m) = gate.shape cc = 0 while n != m and cc < 10: pick = randint(0, 1) if not pick: gate = qt.tensor(gate, id2) gate = tensor_fix(gate) else: gate = tensor_fix(qt.tensor(id2, gate)) (m, m) = gate.shape cc += 1 gate = gate * orig return gate
def multi_qubit_hadamard(regular_hadamard_gate): theta = uniform(0.0,math.pi*2.0) (n,n) = regular_hadamard_gate.shape N = np.int(((np.log(n))/(np.log(2)))) phase=qt.globalphase(theta,N) phase=tensor_fix(phase) reg=tensor_fix(regular_hadamard_gate) multi_qubit_hadamard = phase*reg multi_qubit_hadamard = tensor_fix(multi_qubit_hadamard) return multi_qubit_hadamard