Skip to content

Commit

Permalink
Merge pull request #255 from kevinsung/phase-cphase
Browse files Browse the repository at this point in the history
Add phase and cphase gates
  • Loading branch information
jcmgray committed Aug 20, 2024
2 parents e067d2a + 932dfee commit 7cd4f4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions quimb/tensor/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ def u1_gate_param_gen(params):


register_param_gate("U1", u1_gate_param_gen, 1)
register_param_gate("PHASE", u1_gate_param_gen, 1)


# two qubit parametrizable gates
Expand Down Expand Up @@ -629,6 +630,7 @@ def cu1_param_gen(params):


register_param_gate("CU1", cu1_param_gen, 2)
register_param_gate("CPHASE", cu1_param_gen, 2)


def crx_param_gen(params):
Expand Down Expand Up @@ -2095,6 +2097,16 @@ def u1(self, lamda, i, gate_round=None, parametrize=False, **kwargs):
**kwargs,
)

def phase(self, lamda, i, gate_round=None, parametrize=False, **kwargs):
self.apply_gate(
"PHASE",
lamda,
i,
gate_round=gate_round,
parametrize=parametrize,
**kwargs,
)

def cu3(
self,
theta,
Expand Down Expand Up @@ -2143,6 +2155,19 @@ def cu1(self, lamda, i, j, gate_round=None, parametrize=False, **kwargs):
**kwargs,
)

def cphase(
self, lamda, i, j, gate_round=None, parametrize=False, **kwargs
):
self.apply_gate(
"CPHASE",
lamda,
i,
j,
gate_round=gate_round,
parametrize=parametrize,
**kwargs,
)

def fsim(
self, theta, phi, i, j, gate_round=None, parametrize=False, **kwargs
):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_tensor/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_all_gate_methods(self, Circ):
("u3", 1, 3),
("u2", 1, 2),
("u1", 1, 1),
("phase", 1, 1),
# two qubit
("cx", 2, 0),
("cy", 2, 0),
Expand All @@ -267,6 +268,7 @@ def test_all_gate_methods(self, Circ):
("cu3", 2, 3),
("cu2", 2, 2),
("cu1", 2, 1),
("cphase", 2, 1),
("fsim", 2, 2),
("fsimg", 2, 5),
("givens", 2, 1),
Expand Down

0 comments on commit 7cd4f4a

Please sign in to comment.