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

Add construct_batch and transform_program functions to workflow module #5084

Merged
merged 32 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
be144a4
add construct_batch and transform_program functions to workflow module
albi3ro Jan 19, 2024
a1753e3
Merge branch 'master' into construct-batch
albi3ro Jan 19, 2024
6bd22dc
fixing some tests
albi3ro Jan 22, 2024
2c22a78
:wq
albi3ro Jan 22, 2024
335da6e
adding graphic and tests
albi3ro Jan 23, 2024
127e2b0
finishing up testing
albi3ro Jan 24, 2024
3dc4032
Merge branch 'master' into construct-batch
albi3ro Jan 24, 2024
61fa6de
Apply suggestions from code review
albi3ro Jan 24, 2024
2329a39
Update pennylane/transforms/core/transform.py
albi3ro Jan 24, 2024
e7b50d3
Update pennylane/transforms/core/transform.py
albi3ro Jan 24, 2024
e983368
code coverage, tidy image
albi3ro Jan 24, 2024
748e815
Merge branch 'construct-batch' of https://github.com/PennyLaneAI/penn…
albi3ro Jan 24, 2024
21f7f12
remove qfunc uses shots arg property, just recalculate
albi3ro Jan 26, 2024
73d52f2
Merge branch 'master' into construct-batch
albi3ro Jan 29, 2024
952933f
Apply suggestions from code review
albi3ro Jan 30, 2024
a8a99da
update capitalization on image
albi3ro Jan 30, 2024
4e4d4dd
Merge branch 'construct-batch' of https://github.com/PennyLaneAI/penn…
albi3ro Jan 30, 2024
18804a2
responding to feedback and fixing up documentation
albi3ro Jan 30, 2024
6d06da1
Merge branch 'master' into construct-batch
albi3ro Jan 30, 2024
d00ac60
minor documentation fix and test addition
albi3ro Jan 30, 2024
1bdbb1b
Merge branch 'master' into construct-batch
albi3ro Jan 30, 2024
c0f7c36
move expand_fn_transform
albi3ro Jan 31, 2024
99adb2d
Merge branch 'construct-batch' of https://github.com/PennyLaneAI/penn…
albi3ro Jan 31, 2024
c560673
Merge branch 'master' into construct-batch
albi3ro Jan 31, 2024
dc1e95d
fix import
albi3ro Jan 31, 2024
4c54371
Merge branch 'construct-batch' of https://github.com/PennyLaneAI/penn…
albi3ro Jan 31, 2024
85d3069
Merge branch 'master' into construct-batch
albi3ro Jan 31, 2024
39b78aa
set seed in flaky test
albi3ro Jan 31, 2024
5aee020
Apply suggestions from code review
albi3ro Jan 31, 2024
a74de98
create keyword args section and usage details
albi3ro Jan 31, 2024
c667da2
set seed in flaky test
albi3ro Jan 31, 2024
b6ab690
Merge branch 'master' into construct-batch
albi3ro Jan 31, 2024
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
Binary file added doc/_static/transforms_order.png
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
251 changes: 251 additions & 0 deletions doc/_static/transforms_order.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@
* Raise a more informative error when calling `adjoint_jacobian` with trainable state-prep operations.
[(#5026)](https://github.com/PennyLaneAI/pennylane/pull/5026)

* Adds `qml.workflow.transform_program` and `qml.workflow.construct_batch` to inspect the transform program and batch of tapes
at different stages.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
[(#5084)](https://github.com/PennyLaneAI/pennylane/pull/5084)

* Adds a `qml.transforms.core.expand_fn_transform` that converts a tape-to-tape function into a transform.
[(#5084)](https://github.com/PennyLaneAI/pennylane/pull/5084)

albi3ro marked this conversation as resolved.
Show resolved Hide resolved
* `CRX`, `CRY`, `CRZ`, `CROT`, and `ControlledPhaseShift` (i.e. `CPhaseShift`) now inherit from `ControlledOp`, giving them additional properties such as `control_wire` and `control_values`. Calling `qml.ctrl` on `RX`, `RY`, `RZ`, `Rot`, and `PhaseShift` with a single control wire will return gates of types `CRX`, `CRY`, etc. as opposed to a general `Controlled` operator.
[(#5069)](https://github.com/PennyLaneAI/pennylane/pull/5069)

Expand Down
3 changes: 1 addition & 2 deletions pennylane/_qubit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import pennylane as qml
from pennylane import Device, DeviceError
from pennylane.workflow import set_shots
from pennylane.math import multiply as qmlmul
from pennylane.math import sum as qmlsum
from pennylane.measurements import (
Expand Down Expand Up @@ -1036,7 +1035,7 @@ def classical_shadow(self, obs, circuit):
n_snapshots = self.shots
seed = obs.seed

with set_shots(self, shots=1):
with qml.workflow.set_shots(self, shots=1):
# slow implementation but works for all devices
n_qubits = len(wires)
mapped_wires = np.array(self.map_wires(wires))
Expand Down
18 changes: 10 additions & 8 deletions pennylane/devices/default_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ def adjoint_state_measurements(
)


def adjoint_ops(op: qml.operation.Operator) -> bool:
"""Specify whether or not an Operator is supported by adjoint differentiation."""
return op.num_params == 0 or op.num_params == 1 and op.has_generator
albi3ro marked this conversation as resolved.
Show resolved Hide resolved


def adjoint_observables(obs: qml.operation.Operator) -> bool:
"""Specifies whether or not an observable is compatible with adjoint differentiation on DefaultQubit."""
return obs.has_matrix


def _add_adjoint_transforms(program: TransformProgram, device_vjp=False) -> None:
"""Private helper function for ``preprocess`` that adds the transforms specific
for adjoint differentiation.
Expand All @@ -171,14 +181,6 @@ def _add_adjoint_transforms(program: TransformProgram, device_vjp=False) -> None

"""

def adjoint_ops(op: qml.operation.Operator) -> bool:
"""Specify whether or not an Operator is supported by adjoint differentiation."""
return op.num_params == 0 or op.num_params == 1 and op.has_generator

def adjoint_observables(obs: qml.operation.Operator) -> bool:
"""Specifies whether or not an observable is compatible with adjoint differentiation on DefaultQubit."""
return obs.has_matrix

name = "adjoint + default.qubit"
program.add_transform(no_sampling, name=name)
program.add_transform(
Expand Down
3 changes: 3 additions & 0 deletions pennylane/templates/subroutines/permute.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def circuit():

"""

def __repr__(self):
return f"Permute({self.hyperparameters['permutation']}, wires={self.wires.tolist()})"

num_wires = AnyWires
grad_method = None

Expand Down
2 changes: 1 addition & 1 deletion pennylane/transforms/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
r"""This module contains the experimental transforms building blocks (core).
"""

from .transform import transform
from .transform import transform, expand_fn_transform
from .transform_dispatcher import TransformDispatcher, TransformContainer, TransformError
from .transform_program import TransformProgram
Loading
Loading