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
opwithadd_decomps()must be applicable toop, and every applicable rule is checked withassert_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 ofop. Defaults toTrue.
- Raises:
AssertionError – if no registered rule is applicable to
op, or if an applicable rule is not consistent withop
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]).