6
6
Qiskit Docs: https://qiskit.org/documentation/getting_started.html
7
7
"""
8
8
9
-
10
9
import qiskit as q
11
10
12
11
13
- def single_qubit_measure () -> q .result .counts .Counts :
12
+ def single_qubit_measure (qubits : int , classical_bits : int ) -> q .result .counts .Counts :
14
13
"""
15
- >>> single_qubit_measure()
14
+ >>> single_qubit_measure(1, 1 )
16
15
{'1': 1000}
17
16
"""
18
17
# Use Aer's qasm_simulator
19
- simulator = q .Aer .get_backend (" qasm_simulator" )
18
+ simulator = q .Aer .get_backend (' qasm_simulator' )
20
19
21
20
# Create a Quantum Circuit acting on the q register
22
- circuit = q .QuantumCircuit (1 , 1 )
21
+ circuit = q .QuantumCircuit (qubits , classical_bits )
23
22
24
23
# Apply X (NOT) Gate to Qubit 0
25
24
circuit .x (0 )
@@ -30,15 +29,10 @@ def single_qubit_measure() -> q.result.counts.Counts:
30
29
# Execute the circuit on the qasm simulator
31
30
job = q .execute (circuit , simulator , shots = 1000 )
32
31
33
- # Grab results from the job
34
- result = job .result ()
35
-
36
- # Get the histogram data of an experiment.
37
- counts = result .get_counts (circuit )
38
-
39
- return counts
32
+ # Return the histogram data of the results of the experiment.
33
+ return job .result ().get_counts (circuit )
40
34
41
35
42
- if __name__ == " __main__" :
43
- counts = single_qubit_measure ()
44
- print (" Total count for various states are:" , counts )
36
+ if __name__ == ' __main__' :
37
+ counts = single_qubit_measure (1 , 1 )
38
+ print (f' Total count for various states are: { counts } ' )
0 commit comments