Update app.py
Browse files
app.py
CHANGED
@@ -114,21 +114,39 @@ print(counts)
|
|
114 |
from qiskit import QuantumCircuit, transpile
|
115 |
from qiskit_aer import AerSimulator
|
116 |
from qiskit.circuit.library import GroverOperator
|
117 |
-
from qiskit.algorithms import AmplificationProblem
|
118 |
|
119 |
-
# Define
|
120 |
-
def
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
oracle(
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
grover_circuit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
# Use AerSimulator as the backend
|
134 |
simulator = AerSimulator()
|
|
|
114 |
from qiskit import QuantumCircuit, transpile
|
115 |
from qiskit_aer import AerSimulator
|
116 |
from qiskit.circuit.library import GroverOperator
|
|
|
117 |
|
118 |
+
# Define the oracle circuit to mark the solution state |01>
|
119 |
+
def create_oracle():
|
120 |
+
oracle_circuit = QuantumCircuit(2)
|
121 |
+
oracle_circuit.cz(0, 1) # Mark |01> as the solution
|
122 |
+
return oracle_circuit
|
123 |
+
|
124 |
+
# Define the full Grover search circuit
|
125 |
+
def create_grover_circuit():
|
126 |
+
oracle = create_oracle()
|
127 |
+
grover_circuit = QuantumCircuit(2, 2)
|
128 |
+
|
129 |
+
# Apply Hadamard to all qubits
|
130 |
+
grover_circuit.h([0, 1])
|
131 |
+
|
132 |
+
# Apply the oracle
|
133 |
+
grover_circuit.append(oracle.to_gate(), [0, 1])
|
134 |
+
|
135 |
+
# Apply Grover diffusion operator
|
136 |
+
grover_circuit.h([0, 1])
|
137 |
+
grover_circuit.x([0, 1])
|
138 |
+
grover_circuit.h(1)
|
139 |
+
grover_circuit.cz(0, 1)
|
140 |
+
grover_circuit.h(1)
|
141 |
+
grover_circuit.x([0, 1])
|
142 |
+
grover_circuit.h([0, 1])
|
143 |
+
|
144 |
+
# Measure the qubits
|
145 |
+
grover_circuit.measure([0, 1], [0, 1])
|
146 |
+
return grover_circuit
|
147 |
+
|
148 |
+
# Create the Grover circuit
|
149 |
+
grover_circuit = create_grover_circuit()
|
150 |
|
151 |
# Use AerSimulator as the backend
|
152 |
simulator = AerSimulator()
|