Esempio n. 1
0
 def sum_gate():
     sum_circ = AncillaCircuit(3)
     (c0, a, b) = (sum_circ.qubits[0], sum_circ.qubits[1],
                   sum_circ.qubits[2])
     sum_circ.cx(a, b)
     sum_circ.cx(c0, b)
     return sum_circ.to_ancilla_gate()
Esempio n. 2
0
 def carry_gate():
     carry_circ = AncillaCircuit(4)
     (c0, a, b, c1) = (carry_circ.qubits[0], carry_circ.qubits[1],
                       carry_circ.qubits[2], carry_circ.qubits[3])
     carry_circ.ccx(a, b, c1)
     carry_circ.append(neg_mct_gate(), [c0, a, b, c1])
     return carry_circ.to_ancilla_gate()
Esempio n. 3
0
 def neg_mct_gate(lneg):
     neg_mct = AncillaCircuit(3)
     for i in lneg:
         neg_mct.x(i)
     neg_mct.ccx(0, 1, 2)
     for i in lneg:
         neg_mct.x(i)
     return neg_mct.to_ancilla_gate(True)
Esempio n. 4
0
def makesOracle(i, n):
    # Creates the oracle finding exactly i on n qubits (+ 1 for target)(or its lowest n bits if i >= 2^n)
    # Could use some uncomputation...
    ctrls = QuantumRegister(n)
    target = QuantumRegister(1)
    fcirc = AncillaCircuit(ctrls,
                           target,
                           name="oracle_" + str(i) + "_" + str(n))
    format_str = '{0:0' + str(n) + 'b}'
    binary_i = format_str.format(i)[::-1]
    for j in range(n):
        if binary_i[j] == '0':
            fcirc.x(ctrls[j])
    fcirc.mcx(ctrls[:], target[0])
    for j in range(n):
        if binary_i[j] == '0':
            fcirc.x(ctrls[j])
    return fcirc.to_ancilla_gate()
Esempio n. 5
0
 def neg_mct_gate():
     neg_mct = AncillaCircuit(4)
     neg_mct.cx(1, 2)
     neg_mct.ccx(0, 2, 3)
     neg_mct.cx(1, 2)
     return neg_mct.to_ancilla_gate(True)