|
1 |
| -import qiskit as q |
2 |
| - |
| 1 | +#!/usr/bin/env python3 |
3 | 2 | """
|
4 |
| -Build a simple bare-minimum quantum |
5 |
| -circuit that starts with a single qubit |
6 |
| -(by default in state 0), runs the experiment |
7 |
| -1000 times, and finally prints the total |
8 |
| -count of the states finally observed. |
| 3 | +Build a simple bare-minimum quantum circuit that starts with a single |
| 4 | +qubit (by default, in state 0), runs the experiment 1000 times, and |
| 5 | +finally prints the total count of the states finally observed. |
9 | 6 | """
|
10 | 7 |
|
11 |
| -# Use Aer's qasm_simulator |
12 |
| -simulator = q.Aer.get_backend('qasm_simulator') |
13 | 8 |
|
14 |
| -# Create a Quantum Circuit acting on the q register |
15 |
| -circuit = q.QuantumCircuit(1, 1) |
| 9 | +import qiskit as q |
| 10 | + |
| 11 | + |
| 12 | +def single_qubit_measure() -> q.result.counts.Counts: |
| 13 | + # Use Aer's qasm_simulator |
| 14 | + simulator = q.Aer.get_backend('qasm_simulator') |
| 15 | + |
| 16 | + # Create a Quantum Circuit acting on the q register |
| 17 | + circuit = q.QuantumCircuit(1, 1) |
| 18 | + |
| 19 | + # Map the quantum measurement to the classical bits |
| 20 | + circuit.measure([0], [0]) |
| 21 | + |
| 22 | + # Execute the circuit on the qasm simulator |
| 23 | + job = q.execute(circuit, simulator, shots=1000) |
| 24 | + |
| 25 | + # Grab results from the job |
| 26 | + result = job.result() |
16 | 27 |
|
17 |
| -# Map the quantum measurement to the classical bits |
18 |
| -circuit.measure([0], [0]) |
| 28 | + # Returns counts |
| 29 | + counts = result.get_counts(circuit) |
19 | 30 |
|
20 |
| -# Execute the circuit on the qasm simulator |
21 |
| -job = q.execute(circuit, simulator, shots=1000) |
| 31 | + return counts |
22 | 32 |
|
23 |
| -# Grab results from the job |
24 |
| -result = job.result() |
25 | 33 |
|
26 |
| -# Returns counts |
27 |
| -counts = result.get_counts(circuit) |
28 |
| -print("\nTotal count for varopis staes are:", counts) |
| 34 | +if __name__ == '__main__': |
| 35 | + counts = single_qubit_measure() |
| 36 | + print("Total count for various states are:", counts) |
0 commit comments