|
11 | 11 |
|
12 | 12 |
|
13 | 13 | def single_qubit_measure() -> q.result.counts.Counts:
|
14 |
| - """ |
15 |
| - >>> single_qubit_measure() |
16 |
| - {'1': 1000} |
17 |
| - """ |
18 |
| - # Use Aer's qasm_simulator |
19 |
| - simulator = q.Aer.get_backend('qasm_simulator') |
| 14 | + """ |
| 15 | + >>> single_qubit_measure() |
| 16 | + {'1': 1000} |
| 17 | + """ |
| 18 | + # Use Aer's qasm_simulator |
| 19 | + simulator = q.Aer.get_backend("qasm_simulator") |
20 | 20 |
|
21 |
| - # Create a Quantum Circuit acting on the q register |
22 |
| - circuit = q.QuantumCircuit(1, 1) |
| 21 | + # Create a Quantum Circuit acting on the q register |
| 22 | + circuit = q.QuantumCircuit(1, 1) |
23 | 23 |
|
24 |
| - # Apply X (NOT) Gate to Qubit 0 |
25 |
| - circuit.x(0) |
| 24 | + # Apply X (NOT) Gate to Qubit 0 |
| 25 | + circuit.x(0) |
26 | 26 |
|
27 |
| - # Map the quantum measurement to the classical bits |
28 |
| - circuit.measure([0], [0]) |
| 27 | + # Map the quantum measurement to the classical bits |
| 28 | + circuit.measure([0], [0]) |
29 | 29 |
|
30 |
| - # Execute the circuit on the qasm simulator |
31 |
| - job = q.execute(circuit, simulator, shots=1000) |
| 30 | + # Execute the circuit on the qasm simulator |
| 31 | + job = q.execute(circuit, simulator, shots=1000) |
32 | 32 |
|
33 |
| - # Grab results from the job |
34 |
| - result = job.result() |
| 33 | + # Grab results from the job |
| 34 | + result = job.result() |
35 | 35 |
|
36 |
| - # Get the histogram data of an experiment. |
37 |
| - counts = result.get_counts(circuit) |
| 36 | + # Get the histogram data of an experiment. |
| 37 | + counts = result.get_counts(circuit) |
38 | 38 |
|
39 |
| - return counts |
| 39 | + return counts |
40 | 40 |
|
41 | 41 |
|
42 |
| -if __name__ == '__main__': |
43 |
| - counts = single_qubit_measure() |
44 |
| - print("Total count for various states are:", counts) |
| 42 | +if __name__ == "__main__": |
| 43 | + counts = single_qubit_measure() |
| 44 | + print("Total count for various states are:", counts) |
0 commit comments