Skip to content

Commit

Permalink
Fix test_trotter_is_used_if_num_steps_is_defined (#5867)
Browse files Browse the repository at this point in the history
1. Add `assert` to `qml.equal` such that the test case actually tests
something.
2. Fix the expected params for the decomposed gates.

[sc-66069]
  • Loading branch information
astralcai authored Jun 18, 2024
1 parent 37bc2e6 commit 209867b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/ops/op_math/test_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,22 @@ def test_generator_decomposition(self, op_name, str_wires):
def test_trotter_is_used_if_num_steps_is_defined(self):
"""Test that the Suzuki-Trotter decomposition is used when ``num_steps`` is defined."""
phi = 1.23
num_steps = 3
op = qml.IsingXY(phi, wires=[0, 1])
exp = qml.evolve(op.generator(), coeff=-phi, num_steps=3)
exp = qml.evolve(op.generator(), coeff=-phi, num_steps=num_steps)
dec = exp.decomposition()
assert qml.math.allclose(
qml.matrix(qml.tape.QuantumScript(dec), wire_order=[0, 1]),
qml.matrix(exp, wire_order=[0, 1]),
)
new_phi = (-phi / 2) / num_steps
expected_decomp = [
qml.IsingXX(phi / 3, wires=[0, 1]),
qml.IsingYY(phi / 3, wires=[0, 1]),
qml.IsingXX(phi / 3, wires=[0, 1]),
qml.IsingYY(phi / 3, wires=[0, 1]),
qml.IsingXX(phi / 3, wires=[0, 1]),
qml.IsingYY(phi / 3, wires=[0, 1]),
]
qml.IsingXX(new_phi, wires=[0, 1]),
qml.IsingYY(new_phi, wires=[0, 1]),
] * num_steps
assert len(dec) == len(expected_decomp)
for op1, op2 in zip(dec, expected_decomp):
qml.equal(op1, op2)
assert qml.equal(op1, op2)

@pytest.mark.parametrize(
("time", "hamiltonian", "steps", "expected_queue"),
Expand Down

0 comments on commit 209867b

Please sign in to comment.