mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Add First Quantum Qiskit Code Tutorial (#3173)
* Add First Quantum Qiskit Code Tutorial * Add Qiskit Requirement * Address Review Comments * fixup! Format Python code with psf/black push * Update q1.py * updating DIRECTORY.md * Update and rename q1.py to single_qubit_measure.py * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
50d7ed8417
commit
6e01004535
|
@ -681,6 +681,9 @@
|
|||
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_99/sol1.py)
|
||||
* [Validate Solutions](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py)
|
||||
|
||||
## Quantum
|
||||
* [Single Qubit Measure](https://github.com/TheAlgorithms/Python/blob/master/quantum/single_qubit_measure.py)
|
||||
|
||||
## Scheduling
|
||||
* [First Come First Served](https://github.com/TheAlgorithms/Python/blob/master/scheduling/first_come_first_served.py)
|
||||
* [Round Robin](https://github.com/TheAlgorithms/Python/blob/master/scheduling/round_robin.py)
|
||||
|
|
34
quantum/single_qubit_measure.py
Executable file
34
quantum/single_qubit_measure.py
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Build a simple bare-minimum quantum circuit that starts with a single
|
||||
qubit (by default, in state 0), runs the experiment 1000 times, and
|
||||
finally prints the total count of the states finally observed.
|
||||
Qiskit Docs: https://qiskit.org/documentation/getting_started.html
|
||||
"""
|
||||
|
||||
import qiskit as q
|
||||
|
||||
|
||||
def single_qubit_measure(qubits: int, classical_bits: int) -> q.result.counts.Counts:
|
||||
"""
|
||||
>>> single_qubit_measure(1, 1)
|
||||
{'0': 1000}
|
||||
"""
|
||||
# Use Aer's qasm_simulator
|
||||
simulator = q.Aer.get_backend("qasm_simulator")
|
||||
|
||||
# Create a Quantum Circuit acting on the q register
|
||||
circuit = q.QuantumCircuit(qubits, classical_bits)
|
||||
|
||||
# Map the quantum measurement to the classical bits
|
||||
circuit.measure([0], [0])
|
||||
|
||||
# Execute the circuit on the qasm simulator
|
||||
job = q.execute(circuit, simulator, shots=1000)
|
||||
|
||||
# Return the histogram data of the results of the experiment.
|
||||
return job.result().get_counts(circuit)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Total count for various states are: {single_qubit_measure(1, 1)}")
|
|
@ -7,6 +7,7 @@ numpy
|
|||
opencv-python
|
||||
pandas
|
||||
pillow
|
||||
qiskit
|
||||
requests
|
||||
scikit-fuzzy
|
||||
sklearn
|
||||
|
|
Loading…
Reference in New Issue
Block a user