qp.testing.assert_valid¶
- assert_valid(op, *, skip_deepcopy=False, skip_differentiation=False, skip_new_decomp=False, skip_decomp_matrix_check=False, skip_pickle=False, skip_wire_mapping=False, skip_bind_new_parameters=False, skip_eigvals=False)[source]¶
Runs basic validation checks on an
OperatororOperator2to make sure it has been correctly defined.- Parameters:
op (.Operator) – an operator instance to validate
- Keyword Arguments:
skip_deepcopy=False – If
True, deepcopy tests are not run.skip_differentiation=False – If
True, differentiation tests are not run.skip_new_decomp – If
True, the operator will not be tested for its decomposition defined using the new system.skip_decomp_matrix_check – If
True, the decomposition rule check will only verify that the produced operators match the resource function, and does not test that the matrix of the decomposition matches the operator itself.skip_pickle=False – If
True, pickling tests are not run. Set toTruewhen testing a locally defined operator, as pickle cannot handle local objectsskip_wire_mapping – If
True, the operator will not be tested for wire mapping.skip_bind_new_parameters – If
True, thebind_new_parameterstests will be skipped.skip_eigvals – If
True, the eigendecomposition tests will be skipped.
Examples:
class MyOp(Operator): def __init__(self, data, wires): self._data = data super().__init__(wires=wires) op = MyOp(pnp.array(0.5), wires=0)
>>> assert_valid(op) Traceback (most recent call last): ... AssertionError: MyOp._unflatten must be able to reproduce the original operator from () and (Wires([0]), ()). You may need to override either _unflatten or _flatten. For local testing, try type(op)._unflatten(*op._flatten()).
class MyOp(Operator): def __init__(self, wires): self.hyperparameters["unhashable_list"] = [] super().__init__(wires=wires) op = MyOp(wires = 0)
>>> assert_valid(op) Traceback (most recent call last): ... AssertionError: metadata output from _flatten must be hashable. Got metadata (Wires([0]), (('unhashable_list', []),))