From 932dfee70e0915ffdef75e53645d47a2c8d48ba2 Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Tue, 20 Aug 2024 10:27:06 +0800 Subject: [PATCH] add phase and cphase gates --- quimb/tensor/circuit.py | 25 +++++++++++++++++++++++++ tests/test_tensor/test_circuit.py | 2 ++ 2 files changed, 27 insertions(+) diff --git a/quimb/tensor/circuit.py b/quimb/tensor/circuit.py index 16a17232..39157e35 100644 --- a/quimb/tensor/circuit.py +++ b/quimb/tensor/circuit.py @@ -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 @@ -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): @@ -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, @@ -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 ): diff --git a/tests/test_tensor/test_circuit.py b/tests/test_tensor/test_circuit.py index 11533aa9..0629271d 100644 --- a/tests/test_tensor/test_circuit.py +++ b/tests/test_tensor/test_circuit.py @@ -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), @@ -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),