-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented numba clifford operations
- Loading branch information
1 parent
c621acf
commit ce82a33
Showing
3 changed files
with
239 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,139 @@ | ||
from numba import njit | ||
from qibo.backends.clifford import CliffordOperations as CO | ||
|
||
|
||
class CliffordOperations(CO): | ||
def __init__(self, engine): | ||
super().__init__(engine) | ||
|
||
@staticmethod | ||
def I(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.I)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def H(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.H)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def CNOT(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.CNOT)( | ||
symplectic_matrix, control_q, target_q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def CZ(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.CZ)( | ||
symplectic_matrix, control_q, target_q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def S(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.S)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def Z(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.Z)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def X(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.X)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def Y(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.Y)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def SX(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.SX)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def SDG(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.SDG)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def SXDG(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.SXDG)( | ||
symplectic_matrix, q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def RX(symplectic_matrix, q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, f4)", parallel=True, cache=True)(CO.RX)( | ||
symplectic_matrix, q, nqubits, theta | ||
) | ||
|
||
@staticmethod | ||
def RZ(symplectic_matrix, q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, f4)", parallel=True, cache=True)(CO.RZ)( | ||
symplectic_matrix, q, nqubits, theta | ||
) | ||
|
||
@staticmethod | ||
def RY(symplectic_matrix, q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, f4)", parallel=True, cache=True)(CO.RY)( | ||
symplectic_matrix, q, nqubits, theta | ||
) | ||
|
||
@staticmethod | ||
def SWAP(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.SWAP)( | ||
symplectic_matrix, control_q, target_q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def iSWAP(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)( | ||
CO.iSWAP | ||
)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def FSWAP(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)( | ||
CO.FSWAP | ||
)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def CY(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.CY)( | ||
symplectic_matrix, control_q, target_q, nqubits | ||
) | ||
|
||
@staticmethod | ||
def CRX(symplectic_matrix, control_q, target_q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8, f4)", parallel=True, cache=True)( | ||
CO.CRX | ||
)(symplectic_matrix, control_q, target_q, nqubits, theta) | ||
|
||
@staticmethod | ||
def CRZ(symplectic_matrix, control_q, target_q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8, f4)", parallel=True, cache=True)( | ||
CO.CRZ | ||
)(symplectic_matrix, control_q, target_q, nqubits, theta) | ||
|
||
@staticmethod | ||
def CRY(symplectic_matrix, control_q, target_q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8, f4)", parallel=True, cache=True)( | ||
CO.CRY | ||
)(symplectic_matrix, control_q, target_q, nqubits, theta) | ||
|
||
@staticmethod | ||
def ECR(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.ECR)( | ||
symplectic_matrix, control_q, target_q, nqubits | ||
) |
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,95 @@ | ||
from numba import njit | ||
from qibo.backends.clifford import CliffordOperations as CO | ||
|
||
class CliffordOperations(CO): | ||
|
||
def __init__(self, engine): | ||
super().__init__(engine) | ||
|
||
@staticmethod | ||
def I(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.I)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def H(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.H)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def CNOT(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.CNOT)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def CZ(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.CZ)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def S(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.S)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def Z(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.Z)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def X(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.X)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def Y(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.Y)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def SX(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.SX)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def SDG(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.SDG)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def SXDG(symplectic_matrix, q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8)", parallel=True, cache=True)(CO.SXDG)(symplectic_matrix, q, nqubits) | ||
|
||
@staticmethod | ||
def RX(symplectic_matrix, q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, f4)", parallel=True, cache=True)(CO.RX)(symplectic_matrix, q, nqubits, theta) | ||
|
||
@staticmethod | ||
def RZ(symplectic_matrix, q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, f4)", parallel=True, cache=True)(CO.RZ)(symplectic_matrix, q, nqubits, theta) | ||
|
||
@staticmethod | ||
def RY(symplectic_matrix, q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, f4)", parallel=True, cache=True)(CO.RY)(symplectic_matrix, q, nqubits, theta) | ||
|
||
@staticmethod | ||
def SWAP(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.SWAP)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def iSWAP(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.iSWAP)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def FSWAP(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.FSWAP)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def CY(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.CY)(symplectic_matrix, control_q, target_q, nqubits) | ||
|
||
@staticmethod | ||
def CRX(symplectic_matrix, control_q, target_q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8, f4)", parallel=True, cache=True)(CO.CRX)(symplectic_matrix, control_q, target_q, nqubits, theta) | ||
|
||
@staticmethod | ||
def CRZ(symplectic_matrix, control_q, target_q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8, f4)", parallel=True, cache=True)(CO.CRZ)(symplectic_matrix, control_q, target_q, nqubits, theta) | ||
|
||
@staticmethod | ||
def CRY(symplectic_matrix, control_q, target_q, nqubits, theta): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8, f4)", parallel=True, cache=True)(CO.CRY)(symplectic_matrix, control_q, target_q, nqubits, theta) | ||
|
||
@staticmethod | ||
def ECR(symplectic_matrix, control_q, target_q, nqubits): | ||
return njit("b1[:,:](b1[:,:], u8, u8, u8)", parallel=True, cache=True)(CO.ECR)(symplectic_matrix, control_q, target_q, nqubits) |
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