eaglelandsonce
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -111,25 +111,33 @@ counts = result.get_counts()
|
|
111 |
print(counts)
|
112 |
""",
|
113 |
"8. DNA Sequence Matching with Grover's Algorithm": """
|
114 |
-
from qiskit import QuantumCircuit,
|
115 |
from qiskit_aer import AerSimulator
|
116 |
from qiskit.circuit.library import GroverOperator
|
117 |
from qiskit.algorithms import AmplificationProblem
|
118 |
|
119 |
-
#
|
120 |
def oracle(circuit):
|
121 |
-
circuit.cz(0, 1) #
|
122 |
|
|
|
123 |
qc = QuantumCircuit(2)
|
|
|
|
|
124 |
oracle(qc)
|
125 |
|
126 |
-
#
|
127 |
-
problem = AmplificationProblem(qc)
|
128 |
grover_circuit = GroverOperator(problem)
|
|
|
|
|
129 |
simulator = AerSimulator()
|
130 |
|
|
|
131 |
compiled_circuit = transpile(grover_circuit, simulator)
|
132 |
result = simulator.run(compiled_circuit, shots=1024).result()
|
|
|
|
|
133 |
counts = result.get_counts()
|
134 |
print(counts)
|
135 |
""",
|
|
|
111 |
print(counts)
|
112 |
""",
|
113 |
"8. DNA Sequence Matching with Grover's Algorithm": """
|
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()
|
135 |
|
136 |
+
# Transpile and execute the circuit
|
137 |
compiled_circuit = transpile(grover_circuit, simulator)
|
138 |
result = simulator.run(compiled_circuit, shots=1024).result()
|
139 |
+
|
140 |
+
# Retrieve and print the counts
|
141 |
counts = result.get_counts()
|
142 |
print(counts)
|
143 |
""",
|