Skip to content

Commit

Permalink
Fix deprecations that weren't caught by CI (#6879)
Browse files Browse the repository at this point in the history
**Context:**

PR #6822 deprecated the arguments `config` and `inner_transform_program`
to `qml.execute`. However, because of some bug in our CI, the
`qml.PennyLaneDeprecationWarning` are not being treated as errors. I
just happened to find this warning in our CI logs.

**Description of the Change:**

Promoted `qml.PennyLaneDeprecationWarning` to a `ValueError` to fish out
any deprecated code. Updated said code to use `qml.workflow.run` instead
of `qml.execute`.

[sc-81529]
  • Loading branch information
andrijapau authored Jan 24, 2025
1 parent 721acb2 commit afec979
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
1 change: 1 addition & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
* The ``inner_transform_program`` and ``config`` keyword arguments in ``qml.execute`` have been deprecated.
If more detailed control over the execution is required, use ``qml.workflow.run`` with these arguments instead.
[(#6822)](https://github.com/PennyLaneAI/pennylane/pull/6822)
[(#6879)](https://github.com/PennyLaneAI/pennylane/pull/6879)

<h3>Internal changes ⚙️</h3>

Expand Down
15 changes: 1 addition & 14 deletions pennylane/optimize/qnspsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,7 @@ def _step_core(self, cost, args, kwargs):
all_grad_dirs.append(grad_dirs)
all_tensor_dirs.append(tensor_dirs)

if isinstance(cost.device, qml.devices.Device):
program, config = cost.device.preprocess()

raw_results = qml.execute(
all_grad_tapes + all_metric_tapes,
cost.device,
None,
transform_program=program,
config=config,
)
else:
raw_results = qml.execute(
all_grad_tapes + all_metric_tapes, cost.device, None
) # pragma: no cover
raw_results = qml.execute(all_grad_tapes + all_metric_tapes, cost.device)
grads = [
self._post_process_grad(raw_results[2 * i : 2 * i + 2], all_grad_dirs[i])
for i in range(self.resamplings)
Expand Down
23 changes: 4 additions & 19 deletions pennylane/optimize/riemannian_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,31 +392,16 @@ def get_omegas(self):
self.nqubits,
)

if isinstance(self.circuit.device, qml.devices.Device):
program, config = self.circuit.device.preprocess()

circuits = qml.execute(
circuits,
self.circuit.device,
transform_program=program,
config=config,
diff_method=None,
)
else:
circuits = qml.execute(
circuits, self.circuit.device, diff_method=None
) # pragma: no cover

program = self.circuit.device.preprocess_transforms()
raw_results = qml.execute(circuits, self.circuit.device)

circuits_plus = np.array(circuits[: len(circuits) // 2]).reshape(
results_plus = np.array(raw_results[: len(raw_results) // 2]).reshape(
len(self.coeffs), len(self.lie_algebra_basis_names)
)
circuits_min = np.array(circuits[len(circuits) // 2 :]).reshape(
results_min = np.array(raw_results[len(raw_results) // 2 :]).reshape(
len(self.coeffs), len(self.lie_algebra_basis_names)
)

# For each observable O_i in the Hamiltonian, we have to calculate all Lie coefficients
omegas = circuits_plus - circuits_min
omegas = results_plus - results_min

return np.dot(self.coeffs, omegas)

0 comments on commit afec979

Please sign in to comment.