Skip to content

Commit

Permalink
update transforms and gradients using decompose
Browse files Browse the repository at this point in the history
  • Loading branch information
lillian542 committed May 7, 2024
1 parent 6da835b commit 8cbf93f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions pennylane/gradients/finite_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pennylane/gradients/parameter_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pennylane/transforms/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pennylane/transforms/optimization/merge_rotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 4 additions & 1 deletion pennylane/transforms/transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8cbf93f

Please sign in to comment.