From bd1d5c966f723f77aee2433bdbd0bc8ae02de96f Mon Sep 17 00:00:00 2001 From: Anurudh Peduri Date: Fri, 22 Mar 2024 13:35:33 +0100 Subject: [PATCH] add autotest, tensor test --- .../bloqs/basic_gates/su2_rotation_test.py | 23 +++++++++++++++---- qualtran/serialization/resolver_dict.py | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/qualtran/bloqs/basic_gates/su2_rotation_test.py b/qualtran/bloqs/basic_gates/su2_rotation_test.py index bcf9cb031f..ffb1b89701 100644 --- a/qualtran/bloqs/basic_gates/su2_rotation_test.py +++ b/qualtran/bloqs/basic_gates/su2_rotation_test.py @@ -14,17 +14,30 @@ import cirq import numpy as np -from .su2_rotation import SU2RotationGate +from .su2_rotation import SU2RotationGate, _su2_rotation_gate, _t_gate, _hadamard def test_cirq_decompose_SU2_to_single_qubit_pauli_gates(): random_state = np.random.default_rng(42) for _ in range(20): - theta = random_state.random() * 2 * np.pi - phi = random_state.random() * 2 * np.pi - lambd = random_state.random() * 2 * np.pi - + theta, phi, lambd = random_state.random(size=3) * 2 * np.pi gate = SU2RotationGate(theta, phi, lambd) np.testing.assert_allclose(cirq.unitary(gate), gate.rotation_matrix) + + +def test_tensors(): + random_state = np.random.default_rng(42) + + for _ in range(20): + theta, phi, lambd = random_state.random(size=3) * 2 * np.pi + gate = SU2RotationGate(theta, phi, lambd) + + np.testing.assert_allclose(gate.tensor_contract(), gate.rotation_matrix) + + +def test_su2_rotation_gates(bloq_autotester): + bloq_autotester(_su2_rotation_gate) + bloq_autotester(_t_gate) + bloq_autotester(_hadamard) diff --git a/qualtran/serialization/resolver_dict.py b/qualtran/serialization/resolver_dict.py index 118f0ac205..d000c7b64c 100644 --- a/qualtran/serialization/resolver_dict.py +++ b/qualtran/serialization/resolver_dict.py @@ -153,6 +153,7 @@ "qualtran.bloqs.basic_gates.rotation.YPowGate": qualtran.bloqs.basic_gates.rotation.YPowGate, "qualtran.bloqs.basic_gates.rotation.ZPowGate": qualtran.bloqs.basic_gates.rotation.ZPowGate, "qualtran.bloqs.basic_gates.s_gate.SGate": qualtran.bloqs.basic_gates.s_gate.SGate, + "qualtran.bloqs.basic_gates.su2_rotation.SU2RotationGate": qualtran.bloqs.basic_gates.su2_rotation.SU2RotationGate, "qualtran.bloqs.basic_gates.swap.CSwap": qualtran.bloqs.basic_gates.swap.CSwap, "qualtran.bloqs.basic_gates.swap.Swap": qualtran.bloqs.basic_gates.swap.Swap, "qualtran.bloqs.basic_gates.swap.TwoBitCSwap": qualtran.bloqs.basic_gates.swap.TwoBitCSwap,