eaglelandsonce commited on
Commit
f8e7df2
·
verified ·
1 Parent(s): d474adf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -14
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 a 2-qubit oracle that marks the state |01> as a solution
120
- def oracle(circuit):
121
- circuit.cz(0, 1) # Apply a controlled-Z gate for the |01> state
122
-
123
- # Initialize a 2-qubit quantum circuit
124
- qc = QuantumCircuit(2)
125
-
126
- # Apply the oracle
127
- oracle(qc)
128
-
129
- # Use GroverOperator to amplify the marked solution
130
- problem = AmplificationProblem(oracle_circuit=qc)
131
- grover_circuit = GroverOperator(problem)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()