Skip to content

Commit

Permalink
added gates in qlm
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed Jul 2, 2024
1 parent a734794 commit ee3f8f1
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions misc/inverse_circuit/gates_qlm.py
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


0 comments on commit ee3f8f1

Please sign in to comment.