コード例 #1
0
from converter.qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister

qr = QuantumRegister(3)
cr = ClassicalRegister(3)
qc = QuantumCircuit(qr, cr)

qc.ccx(qr[0], qr[1], qr[2])
qc.x(qr[0])
qc.ccx(qr[0], qr[1], qr[2])
qc.x(qr[1])
qc.ccx(qr[0], qr[1], qr[2])
qc.ccx(qr[0], qr[1], qr[2])
qc.ccx(qr[0], qr[1], qr[2])
qc.x(qr[0])
qc.ccx(qr[0], qr[1], qr[2])

qc.measure(qr, cr)
コード例 #2
0
from converter.qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute

qr = QuantumRegister(2)
qr2 = QuantumRegister(1)
cr = ClassicalRegister(2)
cr2 = ClassicalRegister(1)
qc = QuantumCircuit(qr, qr2, cr, cr2)

#qc.ccx(qr[0], qr[1], qr2[0])
#qc.x(qr[0])
#qc.ccx(qr[0], qr[1], qr[2])
#qc.x(qr[1])
#qc.ccx(qr[0], qr[1], qr[2])
#qc.ccx(qr[0], qr[1], qr[2])
#qc.ccx(qr[0], qr[1], qr[2])
#qc.x(qr[0])
#qc.ccx(qr[0], qr[1], qr[2])

for i in range(16):
    qc.ccx(qr[0], qr[1], qr2[0])
'''
qc.ccx(qr[0],qr[1],qr2[0])
qc.ccx(qr[1],qr[2],qr2[0])
qc.ccx(qr[0],qr[1],qr2[0])
qc.ccx(qr[0],qr[1],qr2[0])
qc.ccx(qr[0],qr[2],qr2[0])
'''
qc.measure(qr2, cr2)

execute(qc)
コード例 #3
0
from converter.qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute

qr1 = QuantumRegister(1)
qr2 = QuantumRegister(1)
cr1 = ClassicalRegister(1)
cr2 = ClassicalRegister(1)
qc = QuantumCircuit(qr1, qr2, cr1, cr2)

qc.cx(qr1[0], qr2[0])
qc.x(qr2[0])

qc.measure(qr2, cr2)

execute(qc)
コード例 #4
0
from converter.qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute

a = QuantumRegister(2)
b = QuantumRegister(2)
ci = QuantumRegister(1)
s = QuantumRegister(2)
co = QuantumRegister(1)

a_ = ClassicalRegister(2)
b_ = ClassicalRegister(2)
ci_ = ClassicalRegister(1)
s_ = ClassicalRegister(2)
co_ = ClassicalRegister(1)

circuit = QuantumCircuit(a, b, ci, s, co, a_, b_, ci_, s_, co_)

circuit.ccx(a[0], b[0], ci[0])
circuit.cx(a[0], s[0])
circuit.cx(b[0], s[0])

circuit.ccx(ci[0], a[1], co[0])
circuit.ccx(ci[0], b[1], co[0])
circuit.ccx(a[1], b[1], co[0])
circuit.cx(ci[0], s[1])
circuit.cx(a[1], s[1])
circuit.cx(b[1], s[1])

circuit.measure(ci, ci_)
circuit.measure(s, s_)
circuit.measure(co, co_)
コード例 #5
0
from converter.qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute

c = QuantumRegister(1)
t1 = QuantumRegister(1)
t2 = QuantumRegister(1)
cc = ClassicalRegister(1)
t1c = ClassicalRegister(1)
t2c = ClassicalRegister(1)

circuit = QuantumCircuit(c, t1, t2, cc, t1c, t2c)

circuit.cswap(c[0], t1[0], t2[0])

circuit.measure(c, cc)
circuit.measure(t1, t1c)
circuit.measure(t2, t2c)

execute(circuit)
from converter.qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from sys import argv

a1 = QuantumRegister(1)
a1c = ClassicalRegister(1)
a0 = QuantumRegister(1)
a0c = ClassicalRegister(1)
b1 = QuantumRegister(1)
b1c = ClassicalRegister(1)
b0 = QuantumRegister(1)
b0c = ClassicalRegister(1)

c0 = QuantumRegister(1)
c0c = ClassicalRegister(1)

t0 = QuantumRegister(1)
t0c = ClassicalRegister(1)

c1 = QuantumRegister(1)
c1c = ClassicalRegister(1)

c2 = QuantumRegister(1)
c2c = ClassicalRegister(1)

t1 = QuantumRegister(1)
t1c = ClassicalRegister(1)

c3 = QuantumRegister(1)
c3c = ClassicalRegister(1)

#beginning of the circuit
コード例 #7
0
from converter.qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from sys import argv

qin1 = QuantumRegister(1)
cin1 = ClassicalRegister(1)
qin2 = QuantumRegister(1)
cin2 = ClassicalRegister(1)

#output bit: function XORed onto this
qz = QuantumRegister(1)
cz = ClassicalRegister(1)

#output bit: function XORed onto this
tmp = QuantumRegister(1)

#beginning of the circuit
circuit = QuantumCircuit(qin1,qin2,qz,tmp,cin1,cin2,cz)

#initialize temp
circuit.x(tmp)

circuit.cx(tmp, qz)
circuit.ccx(qin1, tmp, qz)
circuit.ccx(qin2, tmp, qz)

#reversing tmp
circuit.x(tmp)

#circuit.measure(qin1, cin1)
#circuit.measure(qin2, cin2)
circuit.measure(qz, cz)
from converter.qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute

n = 4
a = QuantumRegister(n)
b = QuantumRegister(n)

C = QuantumRegister(n)
S = QuantumRegister(n)

ac = ClassicalRegister(n)
bc = ClassicalRegister(n)
Cc = ClassicalRegister(n)
Sc = ClassicalRegister(n)

circuit = QuantumCircuit(a, b, C, S, ac, bc, Cc, Sc)

circuit.ccx(a[n-1], b[n-1], C[n-1])
circuit.cx(a[n-1], S[n-1])
circuit.cx(b[n-1], S[n-1])

for i in range(1,n):
    circuit.ccx(a[n-1-i],b[n-1-i],C[n-1-i])
    circuit.ccx(b[n-1-i],C[n-1-(i-1)],C[n-1-i])
    circuit.ccx(a[n-1-i],C[n-1-(i-1)],C[n-1-i])
    circuit.cx(a[n-1-i], S[n-1-i])
    circuit.cx(b[n-1-i], S[n-1-i])
    circuit.cx(C[n-1-(i-1)], S[n-1-i])

circuit.measure(C, Cc)
circuit.measure(S, Sc)
コード例 #9
0
from converter.qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute

qi = QuantumRegister(3) # a = qi[0]; b = qi[1]; ci = qi[2]
qo = QuantumRegister(2) # so = qo[0]; co = qo[1]
ci = ClassicalRegister(3)
co = ClassicalRegister(2)

circuit = QuantumCircuit(qi,qo,ci,co)


for idx in range(3):
    circuit.ccx(qi[idx], qi[(idx+1)%3], qo[1])
for idx in range(3):
    circuit.cx(qi[idx], qo[0])

circuit.measure(qo, co)

execute(circuit)
        qc.cx(temp[0], t[0])
        qc.ccx(qx[n - 1], temp[0], t[0])
        qc.ccx(qy[n - 1], temp[0], t[0])
        equal_nway(qx, qy, t, qz, n - 1, qc)

        #reversing t
        qc.ccx(qy[n - 1], temp[0], t[0])
        qc.ccx(qx[n - 1], temp[0], t[0])
        qc.cx(temp[0], t[0])
    return qc


#5 inputs with  n-bits each : to be compared
n = 5
qin1 = QuantumRegister(n)
cin1 = ClassicalRegister(n)
qin2 = QuantumRegister(n)
cin2 = ClassicalRegister(n)

#output bit: function XORed onto this
qz = QuantumRegister(1)
cz = ClassicalRegister(1)

#output bit: function XORed onto this
tmp = QuantumRegister(1)
tmpc = ClassicalRegister(1)

#beginning of the circuit
circuit = QuantumCircuit(qin1, qin2, qz, tmp, cin1, cin2, cz, tmpc)

#initialize example values