FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python-2/quantum/not_gate.py at master · https-github-com-nzysoft/Python-2 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
https-github-com-nzysoft
/
Python-2
Public
forked from
TheAlgorithms/Python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python-2
/
quantum
/
not_gate.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (33 loc) · 1.22 KB
Breadcrumbs
Python-2
/
quantum
/
not_gate.py
Copy path
File metadata and controls
43 lines (33 loc) · 1.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
"""
Build a simple bare-minimum quantum circuit that starts with a single
qubit (by default, in state 0) and inverts it. Run the experiment 1000
times and print the total count of the states finally observed.
Qiskit Docs: https://qiskit.org/documentation/getting_started.html
"""
import
qiskit
def
single_qubit_measure
(
qubits
:
int
,
classical_bits
:
int
)
->
qiskit
.
result
.
counts
.
Counts
:
"""
>>> single_qubit_measure(2, 2)
{'11': 1000}
>>> single_qubit_measure(4, 4)
{'0011': 1000}
"""
# Use Aer's simulator
simulator
=
qiskit
.
Aer
.
get_backend
(
"aer_simulator"
)
# Create a Quantum Circuit acting on the q register
circuit
=
qiskit
.
QuantumCircuit
(
qubits
,
classical_bits
)
# Apply X (NOT) Gate to Qubits 0 & 1
circuit
.
x
(
0
)
circuit
.
x
(
1
)
# Map the quantum measurement to the classical bits
circuit
.
measure
([
0
,
1
], [
0
,
1
])
# Execute the circuit on the qasm simulator
job
=
qiskit
.
execute
(
circuit
,
simulator
,
shots
=
1000
)
# Return the histogram data of the results of the experiment.
return
job
.
result
().
get_counts
(
circuit
)
if
__name__
==
"__main__"
:
counts
=
single_qubit_measure
(
2
,
2
)
print
(
f"Total count for various states are:
{
counts
}
"
)
Back
|
FazBrowse Home
|
New Git URL