From 9db46fd444f3a69d806630154b559858479878f7 Mon Sep 17 00:00:00 2001 From: gyu-don Date: Fri, 29 Mar 2019 10:12:47 +0900 Subject: [PATCH] Add numpy backend ccx implementation to improve performance --- blueqat/backends/numpy_backend.py | 18 ++++++++++++++++++ blueqat/gate.py | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/blueqat/backends/numpy_backend.py b/blueqat/backends/numpy_backend.py index 3cb05a8..a650828 100644 --- a/blueqat/backends/numpy_backend.py +++ b/blueqat/backends/numpy_backend.py @@ -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 diff --git a/blueqat/gate.py b/blueqat/gate.py index 0d33b09..8c53870 100644 --- a/blueqat/gate.py +++ b/blueqat/gate.py @@ -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):