Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Classical to Quantum
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rjm432
Classical to Quantum
Commits
64569d4c
Commit
64569d4c
authored
5 years ago
by
rjm432
Browse files
Options
Downloads
Patches
Plain Diff
Baby steps
parent
9420b4aa
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
1/1_a.py
+50
-0
50 additions, 0 deletions
1/1_a.py
1/1_b.py
+53
-0
53 additions, 0 deletions
1/1_b.py
1/1_c.py
+35
-0
35 additions, 0 deletions
1/1_c.py
Lectures/basic_logic.py
+65
-0
65 additions, 0 deletions
Lectures/basic_logic.py
with
203 additions
and
0 deletions
1/1_a.py
0 → 100644
+
50
−
0
View file @
64569d4c
import
numpy
import
math
from
qiskit
import
*
from
qiskit
import
BasicAer
#Program NNAND gate using X and CCX Gates
'''
NAND
1 | 0 0
1 | 0 1
1 | 1 0
0 | 1 1
'''
#Quantum Wire
q
=
QuantumRegister
(
3
,
'
q
'
)
#Classical Wire
c
=
ClassicalRegister
(
3
,
'
c
'
)
#Build the Circuit
circ
=
QuantumCircuit
(
q
,
c
)
#Inputs
circ
.
x
(
q
[
0
])
#circ.x(q[1])
#NAND
circ
.
ccx
(
q
[
0
],
q
[
1
],
q
[
2
])
circ
.
x
(
q
[
2
])
#circ.ccx(q[0],q[2],q[1])
#Measure
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
])
circ
.
measure
(
q
[
0
],
c
[
0
])
circ
.
measure
(
q
[
1
],
c
[
1
])
circ
.
measure
(
q
[
2
],
c
[
2
])
#Picture Time
X
=
circ
.
draw
(
output
=
"
text
"
)
print
(
X
)
#Run an experiment
backend_sim
=
BasicAer
.
get_backend
(
'
qasm_simulator
'
)
job_sim
=
execute
(
circ
,
backend_sim
,
shots
=
2048
)
result_sim
=
job_sim
.
result
()
counts
=
result_sim
.
get_counts
()
print
(
counts
)
This diff is collapsed.
Click to expand it.
1/1_b.py
0 → 100644
+
53
−
0
View file @
64569d4c
import
numpy
import
math
from
qiskit
import
*
from
qiskit
import
BasicAer
#Program NOR gate using X and CCX Gates
'''
NOR
1 | 0 0
0 | 0 1
0 | 1 0
0 | 1 1
'''
Qu
#Quantum Wire
q
=
QuantumRegister
(
3
,
'
q
'
)
#Classical Wire
c
=
ClassicalRegister
(
3
,
'
c
'
)
#Build the Circuit
circ
=
QuantumCircuit
(
q
,
c
)
#Inputs
circ
.
x
(
q
[
0
])
#circ.x(q[1])
#Circuit
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
])
circ
.
x
(
q
[
0
])
circ
.
x
(
q
[
1
])
circ
.
ccx
(
q
[
0
],
q
[
1
],
q
[
2
])
#Undo ~A ^ B
circ
.
x
(
q
[
0
])
circ
.
x
(
q
[
1
])
#Measure
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
])
circ
.
measure
(
q
[
0
],
c
[
0
])
circ
.
measure
(
q
[
1
],
c
[
1
])
circ
.
measure
(
q
[
2
],
c
[
2
])
#Picture Time
X
=
circ
.
draw
(
output
=
"
text
"
)
print
(
X
)
#Run an experiment
backend_sim
=
BasicAer
.
get_backend
(
'
qasm_simulator
'
)
job_sim
=
execute
(
circ
,
backend_sim
,
shots
=
2048
)
result_sim
=
job_sim
.
result
()
counts
=
result_sim
.
get_counts
()
print
(
counts
)
This diff is collapsed.
Click to expand it.
1/1_c.py
0 → 100644
+
35
−
0
View file @
64569d4c
import
numpy
import
math
from
qiskit
import
*
from
qiskit
import
BasicAer
# Program XOR using Quantum Gates
'''
XOR
0 | 0 0
1 | 0 1
1 | 1 0
0 | 1 1
'''
#Quantum Wires
q
=
QuantumRegister
(
3
,
'
q
'
)
#Classical Wires
c
=
ClassicalRegister
(
3
,
'
c
'
)
#Build Circuit
circ
=
QuantumCircuit
(
q
,
c
)
#Inputs
#Circuit
#Text Representation
x
=
#Test and Results
This diff is collapsed.
Click to expand it.
Lectures/basic_logic.py
0 → 100644
+
65
−
0
View file @
64569d4c
#We need to load the Libraries
import
numpy
import
math
from
qiskit
import
*
from
qiskit
import
BasicAer
#We need 5 quantum wires
q
=
QuantumRegister
(
5
,
'
q
'
)
#We only need 4 classical bits (3 inputs + 1 output)
c
=
ClassicalRegister
(
4
,
'
c
'
)
#Build the Circuit
circ
=
QuantumCircuit
(
q
,
c
)
#We are Building
#(A v B) & (~C)
#Wires:
#q[0] = A
#q[1] = B
#q[2] = C
#q[3] = Temp Result
#q[4] = Final Result
#Lets set Values
#A=1,B=0,C=1
circ
.
x
(
q
[
0
])
circ
.
x
(
q
[
2
])
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
],
q
[
4
])
#A v B = ~(~A & ~B)
circ
.
x
(
q
[
0
])
circ
.
x
(
q
[
1
])
circ
.
ccx
(
q
[
0
],
q
[
1
],
q
[
3
])
#Res in q[3]
circ
.
x
(
q
[
0
])
#undo temp change
circ
.
x
(
q
[
1
])
#undo temp change
circ
.
x
(
q
[
3
])
#Apply not to result
#~C
circ
.
x
(
q
[
2
])
#(A v B) & ~C
#The barrier makes it look prettier
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
],
q
[
4
])
circ
.
ccx
(
q
[
2
],
q
[
3
],
q
[
4
])
circ
.
x
(
q
[
2
])
#Undo the not
#Measure the Bits we care about
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
],
q
[
4
])
circ
.
measure
(
q
[
0
],
c
[
0
])
circ
.
measure
(
q
[
1
],
c
[
1
])
circ
.
measure
(
q
[
2
],
c
[
2
])
circ
.
measure
(
q
[
4
],
c
[
3
])
#Throw are q[3]
X
=
circ
.
draw
(
output
=
"
text
"
)
print
(
X
)
#Run an experiment!
backend_sim
=
BasicAer
.
get_backend
(
'
qasm_simulator
'
)
job_sim
=
execute
(
circ
,
backend_sim
,
shots
=
2048
)
result_sim
=
job_sim
.
result
()
counts
=
result_sim
.
get_counts
()
print
(
counts
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment