Skip to content

Commit

Permalink
Replace assert qml.equal with qml.assert_equal in tests (#6709)
Browse files Browse the repository at this point in the history
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      test directory!

- [ ] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [ ] Ensure that the test suite passes, by running `make test`.

- [ ] Add a new entry to the `doc/releases/changelog-dev.md` file,
summarizing the
      change, and including a link back to the PR.

- [ ] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      To lint modified files, simply `pip install pylint`, and then
      run `pylint pennylane/path/to/file.py`.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
  • Loading branch information
astralcai authored Dec 11, 2024
1 parent 544f8ee commit 9d9205a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/data/attributes/test_pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ def test_quantum_scripts(shots):
"""Test that ``QuantumScript`` can be serialized as Pytrees."""
script = qml.tape.QuantumScript([qml.X(0)], shots=shots)

assert qml.equal(DatasetPyTree(script).get_value(), script)
qml.assert_equal(DatasetPyTree(script).get_value(), script)
6 changes: 3 additions & 3 deletions tests/devices/test_legacy_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_legacy_device_expand_fn():
[qml.X(0), qml.CNOT((0, 1)), qml.RX(0.5, 0), qml.CNOT((0, 1))], [qml.state()]
)
(new_tape,), fn = legacy_device_expand_fn(tape, device=DummyDevice())
assert qml.equal(new_tape, expected)
qml.assert_equal(new_tape, expected)
assert fn(("A",)) == "A"


Expand All @@ -173,8 +173,8 @@ def test_legacy_device_batch_transform():
tape = qml.tape.QuantumScript([], [qml.expval(qml.X(0) + qml.Y(0))])
(tape1, tape2), fn = legacy_device_batch_transform(tape, device=DummyDevice())

assert qml.equal(tape1, qml.tape.QuantumScript([], [qml.expval(qml.X(0))]))
assert qml.equal(tape2, qml.tape.QuantumScript([], [qml.expval(qml.Y(0))]))
qml.assert_equal(tape1, qml.tape.QuantumScript([], [qml.expval(qml.X(0))]))
qml.assert_equal(tape2, qml.tape.QuantumScript([], [qml.expval(qml.Y(0))]))
assert fn((1.0, 2.0)) == np.array(3.0)


Expand Down
10 changes: 5 additions & 5 deletions tests/ops/op_math/test_controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,11 @@ def test_differentiable_one_qubit_special_unitary_multiple_ctrl(self):
op = qml.ctrl(qml.RZ(qml.numpy.array(theta), 0), (1, 2, 3, 4))
decomp = op.decomposition()

assert qml.equal(decomp[0], qml.CRZ(qml.numpy.array(theta), [4, 0]))
assert qml.equal(decomp[1], qml.MultiControlledX(wires=[1, 2, 3, 0]))
assert qml.equal(decomp[2], qml.CRZ(qml.numpy.array(-theta / 2), wires=[4, 0]))
assert qml.equal(decomp[3], qml.MultiControlledX(wires=[1, 2, 3, 0]))
assert qml.equal(decomp[4], qml.CRZ(qml.numpy.array(-theta / 2), wires=[4, 0]))
qml.assert_equal(decomp[0], qml.CRZ(qml.numpy.array(theta), [4, 0]))
qml.assert_equal(decomp[1], qml.MultiControlledX(wires=[1, 2, 3, 0]))
qml.assert_equal(decomp[2], qml.CRZ(qml.numpy.array(-theta / 2), wires=[4, 0]))
qml.assert_equal(decomp[3], qml.MultiControlledX(wires=[1, 2, 3, 0]))
qml.assert_equal(decomp[4], qml.CRZ(qml.numpy.array(-theta / 2), wires=[4, 0]))

decomp_mat = qml.matrix(op.decomposition, wire_order=op.wires)()
assert qml.math.allclose(op.matrix(), decomp_mat)
Expand Down
2 changes: 1 addition & 1 deletion tests/pytrees/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_pennylane_pytree_roundtrip(obj_in: Any):
data, struct = flatten(obj_in)
obj_out = unflatten(data, pytree_structure_load(pytree_structure_dump(struct)))

assert qml.equal(obj_in, obj_out)
qml.assert_equal(obj_in, obj_out)


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/tape/test_qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,13 @@ def test_setting_trainable_params_to_none(self):
)

assert tape.num_params == 1
assert qml.equal(tape.get_operation(0)[0], qml.RY(2.3, 1))
qml.assert_equal(tape.get_operation(0)[0], qml.RY(2.3, 1))

new_tape = tape.copy(trainable_params=None)

assert new_tape.num_params == 2
assert qml.equal(new_tape.get_operation(0)[0], qml.RX(1.2, 0))
assert qml.equal(new_tape.get_operation(1)[0], qml.RY(2.3, 1))
qml.assert_equal(new_tape.get_operation(0)[0], qml.RX(1.2, 0))
qml.assert_equal(new_tape.get_operation(1)[0], qml.RY(2.3, 1))

def test_setting_measurements_and_trainable_params(self):
"""Test that when explicitly setting both measurements and trainable params, the
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/test_subroutines/test_gqsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_decomposition(self):
]

for op1, op2 in zip(decomposition, expected):
assert qml.equal(op1, op2)
qml.assert_equal(op1, op2)

@pytest.mark.jax
def test_gqsp_jax(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/test_subroutines/test_multiplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_mul_out_k_mod():
assert op[1].name == "ControlledSequence"
assert op[2].name == "Adjoint(QFT)"
print(op[1].base)
assert qml.equal(op[1].base, qml.PhaseAdder(2, x_wires=[4, 5]))
qml.assert_equal(op[1].base, qml.PhaseAdder(2, x_wires=[4, 5]))


class TestMultiplier:
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/test_subroutines/test_prepselprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_copy(self):
op = qml.PrepSelPrep(lcu, control=0)
op_copy = copy.copy(op)

assert qml.equal(op, op_copy)
qml.assert_equal(op, op_copy)

@pytest.mark.parametrize(
("lcu"),
Expand Down

0 comments on commit 9d9205a

Please sign in to comment.