Skip to content

Commit

Permalink
Allow an abstract .mv value without wires
Browse files Browse the repository at this point in the history
  • Loading branch information
dime10 committed May 10, 2024
1 parent 1cd11e8 commit 70c03dc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pennylane/measurements/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import Optional, Sequence, Tuple, Union

import pennylane as qml
from pennylane.math.utils import is_abstract
from pennylane.operation import DecompositionUndefinedError, EigvalsUndefinedError, Operator
from pennylane.pytrees import register_pytree
from pennylane.typing import TensorLike
Expand Down Expand Up @@ -162,6 +163,9 @@ def __init__(
# Cast sequence of measurement values to list
self.mv = obs if getattr(obs, "name", None) == "MeasurementValue" else list(obs)
self.obs = None
elif is_abstract(obs): # Catalyst program with qml.sample(m, wires=i)
self.mv = obs
self.obs = None

Check warning on line 168 in pennylane/measurements/measurements.py

View check run for this annotation

Codecov / codecov/patch

pennylane/measurements/measurements.py#L167-L168

Added lines #L167 - L168 were not covered by tests
else:
self.obs = obs
self.mv = None
Expand Down Expand Up @@ -306,7 +310,7 @@ def wires(self):
This is the union of all the Wires objects of the measurement.
"""
if self.mv is not None:
if self.mv is not None and not is_abstract(self.mv):
if isinstance(self.mv, list):
return qml.wires.Wires.all_wires([m.wires for m in self.mv])
return self.mv.wires
Expand Down

0 comments on commit 70c03dc

Please sign in to comment.