-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
Inferential gates in qlm | ||
""" | ||
import numpy as np | ||
import qat.lang.AQASM as qlm | ||
|
||
def _matrix_gen(inaccuracy): | ||
""" | ||
Matrix M for M gate | ||
""" | ||
theta = inaccuracy * np.pi / 2 | ||
return np.array([ | ||
[np.cos(theta), np.sin(theta)], | ||
[np.sin(theta), -np.cos(theta)] | ||
]) | ||
|
||
M = qlm.AbstractGate("M", [float], arity=1, matrix_generator=_matrix_gen) | ||
|
||
|
||
def m_gate(inaccuracy): | ||
def _matrix_gen(inaccuracy): | ||
""" | ||
Matrix M for M gate | ||
""" | ||
theta = inaccuracy * np.pi / 2 | ||
return np.array([ | ||
[np.cos(theta), np.sin(theta)], | ||
[np.sin(theta), -np.cos(theta)] | ||
]) | ||
gate_m = qlm.AbstractGate( | ||
"M", [float], arity=1, matrix_generator=_matrix_gen) | ||
return gate_m | ||
|
||
|
||
@qlm.build_gate("Rule", [float], arity=3) | ||
def rule_gate(certainty): | ||
""" | ||
Implication Gate in QLM Abstract Gate | ||
""" | ||
|
||
routine = qlm.QRoutine() | ||
register = routine.new_wires(3) | ||
routine.apply(m_gate(certainty), register[1]) | ||
routine.apply(qlm.CCNOT, register[0], register[1], register[2]) | ||
return routine | ||
|
||
@qlm.build_gate("Not", [], arity=2) | ||
def not_gate(): | ||
""" | ||
Not Gate | ||
""" | ||
routine = qlm.QRoutine() | ||
register = routine.new_wires(2) | ||
routine.apply(qlm.CNOT, register[0], register[1]) | ||
routine.apply(qlm.X, register[1]) | ||
return routine | ||
|
||
@qlm.build_gate("And", [], arity=3) | ||
def and_gate(): | ||
""" | ||
AND gate | ||
""" | ||
routine = qlm.QRoutine() | ||
register = routine.new_wires(3) | ||
routine.apply(qlm.CCNOT, register[0], register[1], register[2]) | ||
return routine | ||
|
||
@qlm.build_gate("Or", [], arity=3) | ||
def or_gate(): | ||
""" | ||
OR gate | ||
""" | ||
routine = qlm.QRoutine() | ||
register = routine.new_wires(3) | ||
routine.apply(qlm.CCNOT, register[0], register[1], register[2]) | ||
routine.apply(qlm.CNOT, register[0], register[2]) | ||
routine.apply(qlm.CNOT, register[1], register[2]) | ||
return routine | ||
|
||
|