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