Skip to content

Commit

Permalink
add autotest, tensor test
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp committed Mar 22, 2024
1 parent 0d08279 commit bd1d5c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions qualtran/bloqs/basic_gates/su2_rotation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions qualtran/serialization/resolver_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bd1d5c9

Please sign in to comment.