2020-10-12 19:41:05 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
2020-10-13 10:11:12 +00:00
|
|
|
Build a simple bare-minimum quantum circuit that starts with a single
|
|
|
|
qubit (by default, in state 0), runs the experiment 1000 times, and
|
2020-10-12 19:41:05 +00:00
|
|
|
finally prints the total count of the states finally observed.
|
|
|
|
Qiskit Docs: https://qiskit.org/documentation/getting_started.html
|
|
|
|
"""
|
|
|
|
|
2022-10-19 20:12:44 +00:00
|
|
|
import qiskit
|
2020-10-12 19:41:05 +00:00
|
|
|
|
|
|
|
|
2022-10-19 20:12:44 +00:00
|
|
|
def single_qubit_measure(
|
|
|
|
qubits: int, classical_bits: int
|
|
|
|
) -> qiskit.result.counts.Counts:
|
2020-10-12 19:41:05 +00:00
|
|
|
"""
|
|
|
|
>>> single_qubit_measure(1, 1)
|
|
|
|
{'0': 1000}
|
|
|
|
"""
|
2022-10-19 20:12:44 +00:00
|
|
|
# Use Aer's simulator
|
|
|
|
simulator = qiskit.Aer.get_backend("aer_simulator")
|
2020-10-12 19:41:05 +00:00
|
|
|
|
|
|
|
# Create a Quantum Circuit acting on the q register
|
2022-10-19 20:12:44 +00:00
|
|
|
circuit = qiskit.QuantumCircuit(qubits, classical_bits)
|
2020-10-12 19:41:05 +00:00
|
|
|
|
|
|
|
# Map the quantum measurement to the classical bits
|
|
|
|
circuit.measure([0], [0])
|
|
|
|
|
2022-10-19 20:12:44 +00:00
|
|
|
# Execute the circuit on the simulator
|
|
|
|
job = qiskit.execute(circuit, simulator, shots=1000)
|
2020-10-12 19:41:05 +00:00
|
|
|
|
|
|
|
# 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)}")
|