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
9800f45b
Commit
9800f45b
authored
4 years ago
by
rjm432
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
07d60570
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
junction.py
+54
-0
54 additions, 0 deletions
junction.py
logic_gates.py
+22
-18
22 additions, 18 deletions
logic_gates.py
with
76 additions
and
18 deletions
junction.py
0 → 100644
+
54
−
0
View file @
9800f45b
# Ryan McShane
from
qiskit
import
*
def
conjunction
(
circuit
,
q
,
L
,
R
,
T
):
# Implements X1 /\ X3 /\ X5 /\ X6 = X7
circuit
.
ccx
(
q
[
0
],
q
[
1
],
q
[
T
[
0
]])
tIndex
=
0
lIndex
=
2
circuit
.
barrier
(
q
)
while
lIndex
<
(
len
(
L
)
-
1
):
circuit
.
ccx
(
q
[
L
[
lIndex
]],
q
[
T
[
tIndex
]],
q
[
T
[
tIndex
+
1
]])
lIndex
+=
1
tIndex
+=
1
circuit
.
barrier
(
q
)
circuit
.
ccx
(
q
[
L
[
lIndex
]],
q
[
T
[
tIndex
]],
q
[
R
])
# Undo
while
lIndex
>
2
:
lIndex
-=
1
tIndex
-=
1
circuit
.
ccx
(
q
[
L
[
lIndex
]],
q
[
T
[
tIndex
]],
q
[
T
[
tIndex
+
1
]])
circuit
.
barrier
(
q
)
circuit
.
ccx
(
q
[
0
],
q
[
1
],
q
[
T
[
0
]])
def
disjunction
(
circuit
,
q
,
L
,
R
,
T
):
circuit
.
x
(
q
[
0
])
circuit
.
x
(
q
[
1
])
circuit
.
ccx
(
q
[
0
],
q
[
1
],
q
[
T
[
0
]])
circuit
.
barrier
(
q
)
tIndex
=
0
lIndex
=
2
while
lIndex
<
(
len
(
L
)
-
1
):
circuit
.
x
(
q
[
L
[
lIndex
]])
circuit
.
ccx
(
q
[
L
[
lIndex
]],
q
[
T
[
tIndex
]],
q
[
T
[
tIndex
+
1
]])
lIndex
+=
1
tIndex
+=
1
circuit
.
barrier
(
q
)
circuit
.
x
(
q
[
L
[
lIndex
]])
circuit
.
ccx
(
q
[
L
[
lIndex
]],
q
[
T
[
tIndex
]],
q
[
R
])
circuit
.
x
(
q
[
R
])
circuit
.
barrier
(
q
)
# Undo
while
lIndex
>
2
:
lIndex
-=
1
tIndex
-=
1
circuit
.
ccx
(
q
[
L
[
lIndex
]],
q
[
T
[
tIndex
]],
q
[
T
[
tIndex
+
1
]])
circuit
.
x
(
q
[
L
[
lIndex
]])
circuit
.
barrier
(
q
)
circuit
.
ccx
(
q
[
0
],
q
[
1
],
q
[
T
[
0
]])
circuit
.
x
(
q
[
1
])
circuit
.
x
(
q
[
0
])
This diff is collapsed.
Click to expand it.
logic_gates.py
+
22
−
18
View file @
9800f45b
...
...
@@ -2,10 +2,10 @@
# Logic Gates Modules
# AND, OR, XOR, NAND, NOR, XNOR
def
and
(
circuit
,
A
,
B
,
result
):
def
AND
(
circuit
,
q
,
A
,
B
,
result
):
circuit
.
ccx
(
q
[
A
],
q
[
B
],
q
[
result
])
def
or
(
circuit
,
A
,
B
,
result
):
def
OR
(
circuit
,
q
,
A
,
B
,
result
):
circuit
.
x
(
q
[
A
])
circuit
.
x
(
q
[
B
])
circuit
.
ccx
(
q
[
result
])
...
...
@@ -14,36 +14,40 @@ def or(circuit, A, B, result):
circuit
.
x
(
q
[
B
])
circuit
.
x
(
q
[
A
])
def
nand
(
circuit
,
A
,
B
,
result
):
def
NAND
(
circuit
,
q
,
A
,
B
,
result
):
circuit
.
ccx
(
q
[
A
],
q
[
B
],
q
[
result
])
circuit
.
x
(
q
[
result
])
def
nor
(
circuit
,
A
,
B
,
result
):
def
NOR
(
circuit
,
q
,
A
,
B
,
result
):
circuit
.
x
(
q
[
A
])
circuit
.
x
(
q
[
B
])
circuit
.
ccx
(
q
[
result
])
# Undo
circuit
.
x
(
q
[
B
])
circuit
.
x
(
q
[
A
])
def
xor
(
circuit
,
A
,
B
,
result
,
t1
,
t2
,
t3
):
nand
(
circuit
,
q
[
A
],
q
[
B
],
q
[
t1
])
def
XOR
(
circuit
,
q
,
A
,
B
,
result
,
t1
,
t2
,
t3
):
NAND
(
circuit
,
q
[
A
],
q
[
B
],
q
[
t1
])
circuit
.
x
(
q
[
t1
])
nand
(
circuit
,
q
[
A
],
q
[
t1
],
q
[
t2
])
NAND
(
circuit
,
q
[
A
],
q
[
t1
],
q
[
t2
])
circuit
.
x
(
q
[
t2
])
nand
(
circuit
,
q
[
B
],
q
[
t1
],
q
[
t3
])
NAND
(
circuit
,
q
[
B
],
q
[
t1
],
q
[
t3
])
circuit
.
x
(
q
[
t3
])
nand
(
circuit
,
q
[
t2
],
q
[
t3
],
q
[
result
])
NAND
(
circuit
,
q
[
t2
],
q
[
t3
],
q
[
result
])
circuit
.
x
(
q
[
result
])
# Undo
circuit
.
x
(
q
[
t3
])
nand
(
circuit
,
q
[
B
],
q
[
t1
],
q
[
t3
])
NAND
(
circuit
,
q
[
B
],
q
[
t1
],
q
[
t3
])
circuit
.
x
(
q
[
t2
])
nand
(
circuit
,
q
[
A
],
q
[
t1
],
q
[
t2
])
NAND
(
circuit
,
q
[
A
],
q
[
t1
],
q
[
t2
])
circuit
.
x
(
q
[
t1
])
nand
(
circuit
,
q
[
A
],
q
[
B
],
q
[
t1
])
NAND
(
circuit
,
q
[
A
],
q
[
B
],
q
[
t1
])
def
xnor
(
circuit
,
a
,
b
,
result
,
R
,
At
,
Bt
):
xor
(
circuit
,
a
,
b
,
result
,
R
,
At
,
Bt
)
circuit
.
x
(
q
[
result
])
def
XNOR
(
circuit
,
q
,
a
,
b
,
result
,
R
,
At
,
Bt
):
# circuit, q = quantum register, a, b, result, R = first NAND, At=second NAND, Bt = third NAND
XOR
(
circuit
,
a
,
b
,
result
,
R
,
At
,
Bt
)
circuit
.
x
(
q
[
result
])
# Just XOR negated
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