Hi,
I have the following decomposition within a “Pooling” gate(subclass of qml.operation.Operation
):
def decomposition(self):
'''
Decomposes pool gate, tracing out a wire or measuring and applying a conditional transformation.
Wire 1 is pooled into wire 0.
'''
params = self.parameters[0]
wires = self.wires
if self.pool_type == "trace":
return [
qml.CRZ(params[0], wires=[wires[1], wires[0]]),
qml.PauliX(wires=wires[1]),
qml.CRX(params[1], wires=[wires[1], wires[0]])
]
if self.pool_type == "measure":
return qml.cond(qml.measure(wires=wires[1]), qml.U3)(params[0], params[1], params[2], wires=wires[0])
Whenever I try to run a circuit using the “measure” version, I get the error in the title. Upon closer inspection, it’s similar to some trouble I had earlier with qml.ctrl, where the error is from PennyLane internal preprocess.py, in the following code:
def _operator_decomposition_gen(
op: qml.operation.Operator,
acceptance_function: Callable[[qml.operation.Operator], bool],
decomposer: Callable[[qml.operation.Operator], Sequence[qml.operation.Operator]],
max_expansion: Optional[int] = None,
current_depth=0,
name: str = "device",
) -> Generator[qml.operation.Operator, None, None]:
"""A generator that yields the next operation that is accepted."""
max_depth_reached = False
if max_expansion is not None and max_expansion <= current_depth:
max_depth_reached = True
if acceptance_function(op) or max_depth_reached:
yield op
else:
try:
decomp = decomposer(op)
current_depth += 1
except qml.operation.DecompositionUndefinedError as e:
raise DeviceError(
f"Operator {op} not supported on {name} and does not provide a decomposition."
) from e
for sub_op in decomp:
yield from _operator_decomposition_gen(
sub_op,
acceptance_function,
decomposer=decomposer,
max_expansion=max_expansion,
current_depth=current_depth,
name=name,
)
Where op = Pooling (measure)(Array([6.16770658, 2.81488335, 5.38861346], dtype=float64), wires=[0, 1])
but decomp = None
, which means the error results from the for sub_op in decomp
line. A similar thing had occured with using qml.ctrl
, as the ctrled gate had no decomp and I scrapped that whole idea. Is there a way around this? Do i have to add something to my class definition?