Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalyst support for qml.CosineWindow #6318

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pennylane/devices/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import pennylane as qml
from pennylane import Snapshot, transform
from pennylane.measurements import SampleMeasurement, StateMeasurement
from pennylane.operation import StatePrepBase, Tensor
from pennylane.operation import Tensor
from pennylane.ops import BasisState, StatePrep
from pennylane.tape import QuantumScript, QuantumScriptBatch
from pennylane.typing import PostprocessingFn
from pennylane.wires import WireError
Expand Down Expand Up @@ -289,7 +290,7 @@ def decompose(
``False``, the operator should be decomposed. This replaces ``stopping_condition``
if and only if the tape has shots.
skip_initial_state_prep (bool): If ``True``, the first operator will not be decomposed if
it inherits from :class:`~.StatePrepBase`. Defaults to ``True``.
it inherits from :class:`~.StatePrep` or :class:`~.BasisState`. Defaults to ``True``.
decomposer (Callable): an optional callable that takes an operator and implements the
relevant decomposition. If ``None``, defaults to using a callable returning
``op.decomposition()`` for any :class:`~.Operator` .
Expand Down Expand Up @@ -357,7 +358,7 @@ def decomposer(op):
if stopping_condition_shots is not None and tape.shots:
stopping_condition = stopping_condition_shots

if tape.operations and isinstance(tape[0], StatePrepBase) and skip_initial_state_prep:
if tape.operations and isinstance(tape[0], (StatePrep, BasisState)) and skip_initial_state_prep:
Comment on lines -360 to +361
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to update Catalyst to target the more general base class StatePrepBase instead of changing this here. Alternatively, we might include all 3 state prep classes in this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including all three state prep classes would reintroduce the bug. The issue is that CosineWindow inherits from StatePrepBase, so Catalyst will attempt to optimize it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if CosineWindow inherits from StatePrep? Does it solve the problem?

prep_op = [tape[0]]
else:
prep_op = []
Expand Down
Loading