Skip to content

Commit

Permalink
use qml.equal on tests for decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoG-byte committed Jun 19, 2024
1 parent bfc67f1 commit 782f175
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/ops/qubit/test_parametric_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,9 @@ def test_PauliRot_all_Identity(self):

decomp_op = decomp_ops[0]

assert qml.equal(decomp_op, qml.GlobalPhase(theta/2))
assert qml.equal(decomp_op, qml.GlobalPhase(theta / 2))

assert qml.math.allclose(op.matrix(), decomp_op.matrix() * np.eye(4))

def test_PauliRot_all_Identity_broadcasted(self):
"""Test handling of the broadcasted all-identity Pauli."""
Expand All @@ -2785,16 +2787,12 @@ def test_PauliRot_all_Identity_broadcasted(self):

decomp_op = decomp_ops[0]

assert decomp_op.name == "GlobalPhase"

# global phase acts on all wires so wire attribute is unused
assert decomp_op.wires == Wires([])

assert len(decomp_op.data[0]) == len(theta)
for param, angle in zip(decomp_op.data[0], theta):
assert qml.math.allclose(param, angle / 2)
assert qml.equal(decomp_op, qml.GlobalPhase(theta / 2))

for op_matrix, decomp_phase in zip(op.matrix(), decomp_op.matrix().T):
op_matrices = op.matrix()
decomp_op_matrices = decomp_op.matrix().T
assert len(op_matrices) == len(decomp_op_matrices)
for op_matrix, decomp_phase in zip(op_matrices, decomp_op_matrices):
assert qml.math.allclose(op_matrix, decomp_phase * np.eye(4))

@pytest.mark.parametrize("theta", [0.4, np.array([np.pi / 3, 0.1, -0.9])])
Expand Down

0 comments on commit 782f175

Please sign in to comment.