From 8cbf93f516febf42bf147c0694fb817dcc86cd3a Mon Sep 17 00:00:00 2001 From: lillian542 Date: Tue, 7 May 2024 14:21:25 -0400 Subject: [PATCH] update transforms and gradients using decompose --- pennylane/gradients/finite_difference.py | 1 + pennylane/gradients/parameter_shift.py | 1 + pennylane/transforms/compile.py | 6 +++++- pennylane/transforms/optimization/merge_rotations.py | 5 ++++- pennylane/transforms/transpile.py | 5 ++++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pennylane/gradients/finite_difference.py b/pennylane/gradients/finite_difference.py index e478bc65383..05a353b44cd 100644 --- a/pennylane/gradients/finite_difference.py +++ b/pennylane/gradients/finite_difference.py @@ -203,6 +203,7 @@ def _expand_transform_finite_diff( stopping_condition=_finite_diff_stopping_condition, skip_initial_state_prep=False, name="finite_diff", + error=qml.operation.DecompositionUndefinedError, ) if new_tape is tape: return [tape], postprocessing diff --git a/pennylane/gradients/parameter_shift.py b/pennylane/gradients/parameter_shift.py index ef2709e7af5..9036378f712 100644 --- a/pennylane/gradients/parameter_shift.py +++ b/pennylane/gradients/parameter_shift.py @@ -780,6 +780,7 @@ def _expand_transform_param_shift( stopping_condition=_param_shift_stopping_condition, skip_initial_state_prep=False, name="param_shift", + error=qml.operation.DecompositionUndefinedError, ) if new_tape is tape: return [tape], postprocessing diff --git a/pennylane/transforms/compile.py b/pennylane/transforms/compile.py index a2421a9845a..50bb7104989 100644 --- a/pennylane/transforms/compile.py +++ b/pennylane/transforms/compile.py @@ -190,7 +190,11 @@ def stop_at(obj): return obj.name in basis_set and (not getattr(obj, "only_visual", False)) [expanded_tape], _ = qml.devices.preprocess.decompose( - tape, stopping_condition=stop_at, max_expansion=expand_depth, name="compile" + tape, + stopping_condition=stop_at, + max_expansion=expand_depth, + name="compile", + error=qml.operation.DecompositionUndefinedError, ) # Apply the full set of compilation transforms num_passes times diff --git a/pennylane/transforms/optimization/merge_rotations.py b/pennylane/transforms/optimization/merge_rotations.py index e3a7362ae0d..2c8178c1997 100644 --- a/pennylane/transforms/optimization/merge_rotations.py +++ b/pennylane/transforms/optimization/merge_rotations.py @@ -123,7 +123,10 @@ def stop_at(obj): return not isinstance(obj, Adjoint) [expanded_tape], _ = qml.devices.preprocess.decompose( - tape, stopping_condition=stop_at, name="merge_rotations" + tape, + stopping_condition=stop_at, + name="merge_rotations", + error=qml.operation.DecompositionUndefinedError, ) list_copy = expanded_tape.operations new_operations = [] diff --git a/pennylane/transforms/transpile.py b/pennylane/transforms/transpile.py index f2f6e4e0870..8e9fa68e666 100644 --- a/pennylane/transforms/transpile.py +++ b/pennylane/transforms/transpile.py @@ -168,7 +168,10 @@ def stop_at(obj): return (obj.name in all_ops) and (not getattr(obj, "only_visual", False)) [expanded_tape], _ = qml.devices.preprocess.decompose( - tape, stopping_condition=stop_at, name="transpile" + tape, + stopping_condition=stop_at, + name="transpile", + error=qml.operation.DecompositionUndefinedError, ) # make copy of ops list_op_copy = expanded_tape.operations.copy()