Skip to content

Commit

Permalink
Merge pull request #277 from kevinsung/sx
Browse files Browse the repository at this point in the history
Add SX and SXDG gates
  • Loading branch information
jcmgray authored Feb 12, 2025
2 parents 667f8d9 + c1eabef commit 37fa2cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions quimb/tensor/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [ ] multi qubit gates via MPO for MPS simulation
"""

import cmath
import functools
import itertools
import math
Expand Down Expand Up @@ -419,6 +420,8 @@ def register_special_gate(name, fn, num_qubits, tag=None, array=None):
register_constant_gate("SDG", qu.S_gate().H, 1)
register_constant_gate("T", qu.T_gate(), 1)
register_constant_gate("TDG", qu.T_gate().H, 1)
register_constant_gate("SX", cmath.rect(1, 0.25 * math.pi) * qu.Xsqrt(), 1)
register_constant_gate("SXDG", cmath.rect(1, -0.25 * math.pi) * qu.Xsqrt().H, 1)
register_constant_gate("X_1_2", qu.Xsqrt(), 1, "X_1/2")
register_constant_gate("Y_1_2", qu.Ysqrt(), 1, "Y_1/2")
register_constant_gate("Z_1_2", qu.Zsqrt(), 1, "Z_1/2")
Expand Down Expand Up @@ -2038,6 +2041,12 @@ def t(self, i, gate_round=None, **kwargs):
def tdg(self, i, gate_round=None, **kwargs):
self.apply_gate("TDG", i, gate_round=gate_round, **kwargs)

def sx(self, i, gate_round=None, **kwargs):
self.apply_gate("SX", i, gate_round=gate_round, **kwargs)

def sxdg(self, i, gate_round=None, **kwargs):
self.apply_gate("SXDG", i, gate_round=gate_round, **kwargs)

def x_1_2(self, i, gate_round=None, **kwargs):
self.apply_gate("X_1_2", i, gate_round=gate_round, **kwargs)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_tensor/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ def test_all_gate_methods(self, Circ):
("y", 1, 0),
("z", 1, 0),
("s", 1, 0),
("sdg", 1, 0),
("t", 1, 0),
("tdg", 1, 0),
("h", 1, 0),
("sx", 1, 0),
("sxdg", 1, 0),
("iden", 1, 0),
("x_1_2", 1, 0),
("y_1_2", 1, 0),
Expand Down

0 comments on commit 37fa2cb

Please sign in to comment.