50 lines
1004 B
Python
50 lines
1004 B
Python
|
# https://www.qmunity.tech/tutorials/grovers-algorithm-using-2-qubits
|
||
|
from qiskit import QuantumCircuit
|
||
|
from qiskit import BasicAer,IBMQ
|
||
|
|
||
|
from quantum_runner import setup_IBM,quantum_simulate
|
||
|
|
||
|
qb_count = 2
|
||
|
|
||
|
circuit = QuantumCircuit(qb_count)
|
||
|
|
||
|
circuit.h(0)
|
||
|
circuit.h(1)
|
||
|
|
||
|
circuit.barrier()
|
||
|
|
||
|
# создаем оракул для котроллируемого вентиля по z
|
||
|
circuit.cz(0,1)
|
||
|
circuit.barrier()
|
||
|
|
||
|
# создаем оператор гровера
|
||
|
for k in range(0,qb_count):
|
||
|
circuit.h(k)
|
||
|
for k in range(0,qb_count):
|
||
|
circuit.x(k)
|
||
|
|
||
|
circuit.h(1)
|
||
|
circuit.cx(0,1)
|
||
|
|
||
|
circuit.x(0)
|
||
|
circuit.h(1)
|
||
|
circuit.h(0)
|
||
|
circuit.x(1)
|
||
|
circuit.h(1)
|
||
|
|
||
|
circuit.barrier()
|
||
|
|
||
|
circuit.measure_all()
|
||
|
|
||
|
print(circuit)
|
||
|
|
||
|
backend = BasicAer.get_backend("qasm_simulator")
|
||
|
results = quantum_simulate(circuit,backend,True)
|
||
|
|
||
|
print(quantum_simulate(circuit,backend,True))
|
||
|
|
||
|
|
||
|
setup_IBM()
|
||
|
provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
|
||
|
quantum_simulate(circuit,provider.get_backend('ibm_lagos'),True)
|