def parityCircuitCheating(cheating=False, cheatingType=0): if cheating: # Cheating operator c1 = cheatingMatrices()[cheatingType] else: c1 = np.identity(2) id_op = Operator(c1) truthtable = "10011001" oracle = TruthTableOracle(truthtable) or_cx = oracle.construct_circuit() # print(oracle.output_register) v = oracle.variable_register o = oracle.output_register cr1 = ClassicalRegister(3) cr2 = ClassicalRegister(1) cx_circ = QuantumCircuit(v, cr2) or_cx.add_register(cr1) cx_circ.h(v[1]) cx_circ.cx(v[1], v[0]) cx_circ.unitary(id_op, v[cheatingType+1:cheatingType+2], label='idop') total_cx = cx_circ + or_cx total_cx.measure(v, cr1) total_cx.measure(o, cr2) return total_cx
def parityCircuit(theta1=0, theta2=0): # Noise rotation matrix. n1 = rotationMatrix(theta1) n2 = rotationMatrix(theta2) n = np.kron(n1, n2) # Noise operator id_op = Operator(n) truthtable = "10011001" oracle = TruthTableOracle(truthtable) or_cx = oracle.construct_circuit() # print(oracle.output_register) v = oracle.variable_register o = oracle.output_register cr1 = ClassicalRegister(3) cr2 = ClassicalRegister(1) cx_circ = QuantumCircuit(v, cr2) or_cx.add_register(cr1) cx_circ.h(v[1]) cx_circ.cx(v[1], v[0]) cx_circ.unitary(id_op, v[1:3], label='idop') total_cx = cx_circ + or_cx total_cx.measure(v, cr1) total_cx.measure(o, cr2) return total_cx