From edd3f14c97e70e173ebfd6ef440a7202590d18a9 Mon Sep 17 00:00:00 2001 From: Anurudh Peduri Date: Thu, 28 Mar 2024 21:18:10 +0000 Subject: [PATCH] test call graph --- qualtran/bloqs/basic_gates/su2_rotation.py | 3 ++- .../bloqs/basic_gates/su2_rotation_test.py | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/qualtran/bloqs/basic_gates/su2_rotation.py b/qualtran/bloqs/basic_gates/su2_rotation.py index 49711c03e..039dadf54 100644 --- a/qualtran/bloqs/basic_gates/su2_rotation.py +++ b/qualtran/bloqs/basic_gates/su2_rotation.py @@ -122,8 +122,9 @@ def _unitary_(self): def build_composite_bloq(self, bb: 'BloqBuilder', q: 'SoquetT') -> Dict[str, 'SoquetT']: pi = sympy.pi if self._is_parameterized_() else np.pi + exp = sympy.exp if self._is_parameterized_() else np.exp - bb.add(GlobalPhase(coefficient=-np.exp(1j * self.global_shift), eps=self.eps / 4)) + bb.add(GlobalPhase(coefficient=-exp(1j * self.global_shift), eps=self.eps / 4)) q = bb.add(ZPowGate(exponent=1 - self.lambd / pi, global_shift=-1, eps=self.eps / 4), q=q) q = bb.add(Ry(angle=2 * self.theta, eps=self.eps / 4), q=q) q = bb.add(ZPowGate(exponent=-self.phi / pi, global_shift=-1, eps=self.eps / 4), q=q) diff --git a/qualtran/bloqs/basic_gates/su2_rotation_test.py b/qualtran/bloqs/basic_gates/su2_rotation_test.py index 119617739..bb89fba8f 100644 --- a/qualtran/bloqs/basic_gates/su2_rotation_test.py +++ b/qualtran/bloqs/basic_gates/su2_rotation_test.py @@ -13,9 +13,19 @@ # limitations under the License. import cirq import numpy as np +import sympy from qualtran import Bloq -from qualtran.bloqs.basic_gates import Hadamard, TGate, XGate, YGate, ZGate +from qualtran.bloqs.basic_gates import ( + GlobalPhase, + Hadamard, + Ry, + TGate, + XGate, + YGate, + ZGate, + ZPowGate, +) from qualtran.cirq_interop import BloqAsCirqGate from qualtran.cirq_interop.testing import assert_decompose_is_consistent_with_t_complexity @@ -80,3 +90,17 @@ def test_from_matrix_on_standard_gates(): np.testing.assert_allclose( SU2RotationGate.from_matrix(mat).rotation_matrix, mat, atol=1e-15 ) + + +def test_call_graph(): + theta, phi, lambd, alpha, eps = sympy.symbols("theta, phi, lambd, alpha, eps") + pi = sympy.pi + + gate = SU2RotationGate(theta, phi, lambd, alpha, eps) + _, sigma = gate.call_graph() + assert sigma == { + GlobalPhase(-sympy.exp(1j * alpha), eps / 4): 1, + ZPowGate(-phi / pi, -1, eps / 4): 1, + ZPowGate(-lambd / pi + 1, -1, eps / 4): 1, + Ry(2 * theta, eps / 4): 1, + }