qp.testing.assert_decomposable

assert_decomposable(op, check_matrix=True)[source]

Check that an operator can be decomposed with its registered decomposition rules.

At least one rule registered for op with add_decomps() must be applicable to op, and every applicable rule is checked with assert_valid_decomp_rule().

Parameters:
  • op (Operator) – the operator to decompose

  • check_matrix (bool) – If True, the matrix of each decomposition is compared with the matrix of op. Defaults to True.

Raises:

AssertionError – if no registered rule is applicable to op, or if an applicable rule is not consistent with op

Example

>>> qp.testing.assert_decomposable(qp.CNOT([0, 1]))
class MyOp(qp.operation.Operator):
    num_wires = 1

op = MyOp(0)
>>> qp.testing.assert_decomposable(op)
Traceback (most recent call last):
    ...
AssertionError: No decomposition rules are registered for MyOp(wires=[0]).