Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 51k
Change from qiskit import Aer to from qiskit_aer import AerSimulator#14138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3cd52a6ec5b35b28bb84fe2d1a1f3556a5c035a5be8c4089db8ca7b3f73a30f82a1477db53c7ab67e5c6d9f091555d0ed6cf359b1395e384be55b50069d239d60b9cace2b47eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import importlib.util | ||
| import math | ||
| def grover_search(number_of_qubits: int = 2): | ||
AnshMNSoni marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide return type hint for the function: | ||
| """ | ||
| Build and simulate Grover's search algorithm. | ||
| """ | ||
| if importlib.util.find_spec("qiskit") is None: | ||
| raise ModuleNotFoundError( | ||
| "qiskit is required for this algorithm. " | ||
| "Install it with: pip install qiskit qiskit-aer" | ||
| ) | ||
| from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute | ||
| if isinstance(number_of_qubits, str): | ||
| raise TypeError("number of qubits must be an integer.") | ||
| if number_of_qubits <= 0: | ||
| raise ValueError("number of qubits must be > 0.") | ||
| if math.floor(number_of_qubits) != number_of_qubits: | ||
| raise ValueError("number of qubits must be exact integer.") | ||
| if number_of_qubits > 10: | ||
| raise ValueError("number of qubits too large to simulate (>10).") | ||
| qr = QuantumRegister(number_of_qubits, "qr") | ||
| cr = ClassicalRegister(number_of_qubits, "cr") | ||
| quantum_circuit = QuantumCircuit(qr, cr) | ||
| quantum_circuit.h(qr) | ||
| quantum_circuit.h(number_of_qubits - 1) | ||
| quantum_circuit.mcx(list(range(number_of_qubits - 1)), number_of_qubits - 1) | ||
| quantum_circuit.h(number_of_qubits - 1) | ||
| quantum_circuit.h(qr) | ||
| quantum_circuit.x(qr) | ||
| quantum_circuit.h(number_of_qubits - 1) | ||
| quantum_circuit.mcx(list(range(number_of_qubits - 1)), number_of_qubits - 1) | ||
| quantum_circuit.h(number_of_qubits - 1) | ||
| quantum_circuit.x(qr) | ||
| quantum_circuit.h(qr) | ||
| quantum_circuit.measure(qr, cr) | ||
| backend = Aer.get_backend("qasm_simulator") | ||
| job = execute(quantum_circuit, backend, shots=10000) | ||
| return job.result().get_counts(quantum_circuit) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
grover_search. If the function does not return a value, please provide the type hint as:def function() -> None: