qml.assert_equal

assert_equal(op1, op2, check_interface=True, check_trainability=True, rtol=1e-05, atol=1e-09)[source]

Function to assert that two operators, measurements, or tapes are equal

Parameters
  • op1 (Operator or MeasurementProcess or QuantumTape) – First object to compare

  • op2 (Operator or MeasurementProcess or QuantumTape) – Second object to compare

  • check_interface (bool, optional) – Whether to compare interfaces. Default: True.

  • check_trainability (bool, optional) – Whether to compare trainability status. Default: True.

  • rtol (float, optional) – Relative tolerance for parameters.

  • atol (float, optional) – Absolute tolerance for parameters.

Returns

None

Raises

AssertionError – An AssertionError is raised if the two operators are not equal.

See also

equal()

Example

>>> op1 = qml.RX(np.array(0.12), wires=0)
>>> op2 = qml.RX(np.array(1.23), wires=0)
>>> qml.assert_equal(op1, op2)
AssertionError: op1 and op2 have different data.
Got (array(0.12),) and (array(1.23),)
>>> h1 = qml.Hamiltonian([1, 2], [qml.PauliX(0), qml.PauliY(1)])
>>> h2 = qml.Hamiltonian([1, 1], [qml.PauliX(0), qml.PauliY(1)])
>>> qml.assert_equal(h1, h2)
AssertionError: op1 and op2 have different operands because op1 and op2 have different scalars. Got 2 and 1

Contents

Using PennyLane

Release news

Development

API

Internals