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
68ef8d02
Commit
68ef8d02
authored
5 years ago
by
rjm432
Browse files
Options
Downloads
Patches
Plain Diff
completed
parent
5f5b59a4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
2/2_a.py
+83
-0
83 additions, 0 deletions
2/2_a.py
with
83 additions
and
0 deletions
2/2_a.py
0 → 100644
+
83
−
0
View file @
68ef8d02
#By Ryan McShane
import
numpy
import
math
from
qiskit
import
*
from
qiskit
import
BasicAer
# Implement (A ^ ~S) V (B ^ S)
'''
Truth Table
R | A S B
----------
0 | 0 0 0
1 | 1 0 0
0 | 0 1 0
0 | 0 0 1
0 | 1 1 0
1 | 1 0 1
1 | 0 1 1
1 | 1 1 1
'''
#Quantum Wires
q
=
QuantumRegister
(
6
,
'
q
'
)
#Classical Wires
c
=
ClassicalRegister
(
4
,
'
c
'
)
#Build Circit
circ
=
QuantumCircuit
(
q
,
c
)
#Wire assignments
'''
q[0] = A
q[1] = S
q[2] = B
q[3] = Result of A ^ ~S
q[4] = Result of S ^ B
q[5] = Result of ~q[3] ^ ~q[4]
q[5] = Result of ~q[5]
'''
#Inputs
circ
.
x
(
q
[
0
])
#A
#circ.x(q[1]) #S
#circ.x(q[2]) #B
# Implement (A ^ ~S) V (B ^ S)
#Circuit
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
],
q
[
4
],
q
[
5
])
circ
.
x
(
q
[
1
])
# ~S
circ
.
ccx
(
q
[
0
],
q
[
1
],
q
[
3
])
# (A ^ ~S)
circ
.
x
(
q
[
1
])
# undo ~S
circ
.
ccx
(
q
[
1
],
q
[
2
],
q
[
4
])
# (S ^ B)
circ
.
x
(
q
[
3
])
# ~ (A ^ ~S)
circ
.
x
(
q
[
4
])
# ~( S ^ B)
circ
.
ccx
(
q
[
3
],
q
[
4
],
q
[
5
])
# ~q[5] ^ ~q[6]
circ
.
x
(
q
[
5
])
# ~(~q[5] ^ ~q[6])
#Measure
circ
.
barrier
(
q
[
0
],
q
[
1
],
q
[
2
],
q
[
3
],
q
[
4
],
q
[
5
])
circ
.
measure
(
q
[
0
],
c
[
0
])
circ
.
measure
(
q
[
1
],
c
[
1
])
circ
.
measure
(
q
[
2
],
c
[
2
])
circ
.
measure
(
q
[
5
],
c
[
3
])
#Picture Time
X
=
circ
.
draw
(
output
=
"
text
"
)
print
(
X
)
#Run Experiments
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