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

[Capture] First PR for enabling dynamic decompositions with PLxPR enabled #6859

Merged
merged 48 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
696acf3
E.C.
PietropaoloFrisoni Jan 20, 2025
9cdfae9
Creating an empty `DynamicDecomposeInterpreter` c;ass
PietropaoloFrisoni Jan 21, 2025
1e138fa
Sbattendo la testa contro il muro tante volte
PietropaoloFrisoni Jan 21, 2025
76c9250
Current prototype version
PietropaoloFrisoni Jan 22, 2025
c821ac9
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 22, 2025
cee6ec4
Fixing one more problem
PietropaoloFrisoni Jan 22, 2025
a208dc5
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 22, 2025
d16a9e0
Moving tests to separate file
PietropaoloFrisoni Jan 23, 2025
a8b9283
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 23, 2025
18bc43c
Pylint fixes (although premature)
PietropaoloFrisoni Jan 23, 2025
e2e8fd0
Removing reundandt tuple calls
PietropaoloFrisoni Jan 23, 2025
0abd620
Tests with dynamic wires
PietropaoloFrisoni Jan 23, 2025
1e3ffb6
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 23, 2025
1ae399b
Adding Autograph test
PietropaoloFrisoni Jan 23, 2025
9a54c3e
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 24, 2025
c5f2ae5
Removing unused parameters and adding a few tests
PietropaoloFrisoni Jan 24, 2025
497440c
Adding a few more tests
PietropaoloFrisoni Jan 24, 2025
c7da133
Removing import
PietropaoloFrisoni Jan 24, 2025
2f0417c
Pylint
PietropaoloFrisoni Jan 24, 2025
3c8bc37
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 24, 2025
e9ff110
Adding test with hyperparameters
PietropaoloFrisoni Jan 27, 2025
b9f5d03
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 27, 2025
f2437b4
Black
PietropaoloFrisoni Jan 27, 2025
8c615c5
A few more tests
PietropaoloFrisoni Jan 27, 2025
9fef95b
Changelog
PietropaoloFrisoni Jan 27, 2025
4a56150
Removing redundant operations
PietropaoloFrisoni Jan 28, 2025
e733762
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 29, 2025
9792df6
Pre-binding hyperparameters [ci skip]
PietropaoloFrisoni Jan 29, 2025
aa422b3
Removing redundant method
PietropaoloFrisoni Jan 30, 2025
b7a18cd
Pylint
PietropaoloFrisoni Jan 30, 2025
97cba03
Testing CI failures (JAX imports)
PietropaoloFrisoni Jan 30, 2025
e05963e
isort
PietropaoloFrisoni Jan 30, 2025
ec73757
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 30, 2025
bc594ca
Support for consts and hyperparameters
PietropaoloFrisoni Jan 31, 2025
4734388
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Jan 31, 2025
1ea4a14
Fixes neede after autograph PR merged on master
PietropaoloFrisoni Jan 31, 2025
f65ab4e
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Feb 5, 2025
f576486
[ci skip]
PietropaoloFrisoni Feb 5, 2025
fd817cc
Removing `DynamicDecomposeInterpreter`
PietropaoloFrisoni Feb 5, 2025
90fc1e5
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Feb 5, 2025
e7a2775
pylint
PietropaoloFrisoni Feb 5, 2025
f621156
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Feb 10, 2025
e9834af
Suggestions from code review (more tests)
PietropaoloFrisoni Feb 10, 2025
bd9473b
disabling wrong iimport order in test file (conflict between isort an…
PietropaoloFrisoni Feb 10, 2025
43a6838
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
PietropaoloFrisoni Feb 10, 2025
98fe17e
Suggestions from code review
PietropaoloFrisoni Feb 10, 2025
902e4f8
Refactoring changelog with program capture entries
PietropaoloFrisoni Feb 10, 2025
4f95b74
Merge branch 'master' into cond_dynamic_decomp
PietropaoloFrisoni Feb 10, 2025
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
21 changes: 14 additions & 7 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@
convert_to_numpy=True)
```

* The higher order primitives in program capture can now accept inputs with abstract shapes.
[(#6786)](https://github.com/PennyLaneAI/pennylane/pull/6786)

* The `PlxprInterpreter` classes can now handle creating dynamic arrays via `jnp.ones`, `jnp.zeros`,
`jnp.arange`, and `jnp.full`.
[#6865)](https://github.com/PennyLaneAI/pennylane/pull/6865)

* `QNode` objects now have an `update` method that allows for re-configuring settings like `diff_method`, `mcm_method`, and more. This allows for easier on-the-fly adjustments to workflows. Any arguments not specified will retain their original value.
[(#6803)](https://github.com/PennyLaneAI/pennylane/pull/6803)

Expand Down Expand Up @@ -154,6 +147,20 @@
* The `qml.clifford_t_decomposition` has been improved to use less gates when decomposing `qml.PhaseShift`.
[(#6842)](https://github.com/PennyLaneAI/pennylane/pull/6842)


<h4>Capturing and representing hybrid programs</h4>

* Implemented a `compute_plxpr_decomposition` method in the `qml.operation.Operator` class to apply dynamic decompositions
with program capture enabled.
[(#6859)](https://github.com/PennyLaneAI/pennylane/pull/6859)

* The higher order primitives in program capture can now accept inputs with abstract shapes.
[(#6786)](https://github.com/PennyLaneAI/pennylane/pull/6786)

* The `PlxprInterpreter` classes can now handle creating dynamic arrays via `jnp.ones`, `jnp.zeros`,
`jnp.arange`, and `jnp.full`.
[#6865)](https://github.com/PennyLaneAI/pennylane/pull/6865)

<h3>Breaking changes 💔</h3>

* `MultiControlledX` no longer accepts strings as control values.
Expand Down
27 changes: 27 additions & 0 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,33 @@ def compute_decomposition(
"""
raise DecompositionUndefinedError

@classproperty
def has_plxpr_decomposition(cls) -> bool:
"""Whether or not the Operator returns a defined plxpr decomposition."""
return cls.compute_plxpr_decomposition != Operator.compute_plxpr_decomposition

@staticmethod
def compute_plxpr_decomposition(*args, **hyperparameters) -> None:
r"""Experimental method to compute the dynamic decomposition of the operator with program capture enabled.

When the program capture feature is enabled with ``qml.capture.enable()``, the decomposition of the operator
is computed with this method if it is defined. Otherwise, the :meth:`~.Operator.compute_decomposition` method is used.

If this method is defined, the control flow operations within the method are recorded in the JAX representation
of the operator's decomposition.

This method is experimental and subject to change.

.. seealso:: :meth:`~.Operator.compute_decomposition`.

Args:
*args (list): positional arguments passed to the operator, including trainable parameters and wires
**hyperparameters (dict): non-trainable hyperparameters of the operator, as stored in the ``hyperparameters`` attribute

"""
PietropaoloFrisoni marked this conversation as resolved.
Show resolved Hide resolved

raise DecompositionUndefinedError

# pylint: disable=no-self-argument, comparison-with-callable
@classproperty
def has_diagonalizing_gates(cls) -> bool:
Expand Down
13 changes: 12 additions & 1 deletion pennylane/transforms/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,18 @@ def interpret_operation_eqn(self, eqn):
with qml.QueuingManager.stop_recording():
op = eqn.primitive.impl(*invals, **eqn.params)
if eqn.outvars[0].__class__.__name__ == "DropVar":
return self.decompose_operation(op)

if op.has_plxpr_decomposition:

args = (*op.parameters, *op.wires)
qml.capture.run_autograph(op.compute_plxpr_decomposition)(
*args, **op.hyperparameters
)
PietropaoloFrisoni marked this conversation as resolved.
Show resolved Hide resolved

else:
PietropaoloFrisoni marked this conversation as resolved.
Show resolved Hide resolved

return self.decompose_operation(op)

return op

# pylint: disable=unused-variable,missing-function-docstring
Expand Down
Loading