Skip to content

Commit 37fa2cb

Browse files
authored
Merge pull request #277 from kevinsung/sx
Add SX and SXDG gates
2 parents 667f8d9 + c1eabef commit 37fa2cb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

quimb/tensor/circuit.py

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [ ] multi qubit gates via MPO for MPS simulation
77
"""
88

9+
import cmath
910
import functools
1011
import itertools
1112
import math
@@ -419,6 +420,8 @@ def register_special_gate(name, fn, num_qubits, tag=None, array=None):
419420
register_constant_gate("SDG", qu.S_gate().H, 1)
420421
register_constant_gate("T", qu.T_gate(), 1)
421422
register_constant_gate("TDG", qu.T_gate().H, 1)
423+
register_constant_gate("SX", cmath.rect(1, 0.25 * math.pi) * qu.Xsqrt(), 1)
424+
register_constant_gate("SXDG", cmath.rect(1, -0.25 * math.pi) * qu.Xsqrt().H, 1)
422425
register_constant_gate("X_1_2", qu.Xsqrt(), 1, "X_1/2")
423426
register_constant_gate("Y_1_2", qu.Ysqrt(), 1, "Y_1/2")
424427
register_constant_gate("Z_1_2", qu.Zsqrt(), 1, "Z_1/2")
@@ -2038,6 +2041,12 @@ def t(self, i, gate_round=None, **kwargs):
20382041
def tdg(self, i, gate_round=None, **kwargs):
20392042
self.apply_gate("TDG", i, gate_round=gate_round, **kwargs)
20402043

2044+
def sx(self, i, gate_round=None, **kwargs):
2045+
self.apply_gate("SX", i, gate_round=gate_round, **kwargs)
2046+
2047+
def sxdg(self, i, gate_round=None, **kwargs):
2048+
self.apply_gate("SXDG", i, gate_round=gate_round, **kwargs)
2049+
20412050
def x_1_2(self, i, gate_round=None, **kwargs):
20422051
self.apply_gate("X_1_2", i, gate_round=gate_round, **kwargs)
20432052

tests/test_tensor/test_circuit.py

+4
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ def test_all_gate_methods(self, Circ):
235235
("y", 1, 0),
236236
("z", 1, 0),
237237
("s", 1, 0),
238+
("sdg", 1, 0),
238239
("t", 1, 0),
240+
("tdg", 1, 0),
239241
("h", 1, 0),
242+
("sx", 1, 0),
243+
("sxdg", 1, 0),
240244
("iden", 1, 0),
241245
("x_1_2", 1, 0),
242246
("y_1_2", 1, 0),

0 commit comments

Comments
 (0)