Archived
1
0
This repository has been archived on 2023-07-24. You can view files and clone it, but cannot push or open issues or pull requests.
qalg/bench-qiskit/grover_algorithm.py

50 lines
1004 B
Python
Raw Permalink Normal View History

2023-07-24 16:56:29 +05:30
# 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)