Skip to content

Commit

Permalink
Add numpy backend ccx implementation to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
gyu-don committed Mar 29, 2019
1 parent 151f104 commit 9db46fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions blueqat/backends/numpy_backend.py
Expand Up @@ -253,6 +253,24 @@ def gate_s(self, gate, ctx):
qubits[(i & (1 << target)) != 0] *= 1.j
return ctx

def gate_ccz(self, gate, ctx):
c1, c2, t = gate.targets
qubits = ctx.qubits
n_qubits = ctx.n_qubits
i = ctx.indices
indices = (i & (1 << c1)) != 0
indices &= (i & (1 << c2)) != 0
indices &= (i & (1 << t)) != 0
qubits[indices] *= -1
return ctx

def gate_ccx(self, gate, ctx):
c1, c2, t = gate.targets
ctx = self.gate_h(HGate(t), ctx)
ctx = self.gate_ccz(CCZGate(gate.targets), ctx)
ctx = self.gate_h(HGate(t), ctx)
return ctx

def gate_u1(self, gate, ctx):
qubits = ctx.qubits
n_qubits = ctx.n_qubits
Expand Down
5 changes: 5 additions & 0 deletions blueqat/gate.py
Expand Up @@ -227,6 +227,11 @@ def fallback(self, n_qubits):
]


class CCZGate(Gate):
"""2-Controlled Z gate"""
lowername = "ccz"


class U1Gate(OneQubitGate):
"""U1 gate"""
def __init__(self, targets, lambd, **kwargs):
Expand Down

0 comments on commit 9db46fd

Please sign in to comment.