qp.testing

This module contains utilities for testing PennyLane objects, such as operators, decomposition rules, and captured programs.

Operators

assert_valid(op, *[, skip_deepcopy, ...])

Runs basic validation checks on an Operator or Operator2 to make sure it has been correctly defined.

Decompositions

assert_decomposable(op[, check_matrix])

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

assert_valid_decomp_rule(op, rule[, ...])

Check that a decomposition rule is consistent with the operator it decomposes.

decomp_rule_to_tape(op, rule)

Apply a decomposition rule to an operator and record the result as a tape.

Program capture

plxpr_to_tape(plxpr, consts, *args)

Convert a plxpr into a tape.

assert_eqn_matches_op(eqn, expected_op)

Assert that a jaxpr equation creates an operator of the expected type.

extract_all_primitives(jaxpr)

Collect the primitives of every equation in a jaxpr, including the equations of jaxprs nested inside higher-order primitives such as qnode, cond and for_loop.

find_eqns(jaxpr, primitive)

Find the equations in a jaxpr that use a given primitive.