-
-
Notifications
You must be signed in to change notification settings - Fork 50k
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
base: master
Are you sure you want to change the base?
Changes from all commits
3cd52a6
ec5b35b
28bb84f
e2d1a1f
3556a5c
035a5be
8c4089d
b8ca7b3
f73a30f
82a1477
db53c7a
b67e5c6
d9f0915
55d0ed6
cf359b1
395e384
be55b50
069d239
d60b9ca
ce2b47e
File filter
Filter by extension
Conversations
Jump to
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.
Show resolved
Hide resolved
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: