qml.ops.functions.assert_valid¶
-
assert_valid
(op, skip_pickle=False)[source]¶ Runs basic validation checks on an
Operator
to make sure it has been correctly defined.- Parameters
op (Operator) – an operator instance to validate
- Keyword Arguments
skip_pickle=False – If
True
, pickling tests are not run. Set toTrue
when testing a locally defined operator, as pickle cannot handle local objects
Examples:
class MyOp(qml.operation.Operator): def __init__(self, data, wires): self.data = data super().__init__(wires=wires) op = MyOp(qml.numpy.array(0.5), wires=0)
>>> assert_valid(op) AssertionError: op.data must be a tuple
class MyOp(qml.operation.Operator): def __init__(self, wires): self.hyperparameters["unhashable_list"] = [] super().__init__(wires=wires) op = MyOp(wires = 0) assert_valid(op)
ValueError: metadata output from _flatten must be hashable. This also applies to hyperparameters
code/api/pennylane.ops.functions.assert_valid
Download Python script
Download Notebook
View on GitHub