Skip to content

Commit

Permalink
remove legacy opamth
Browse files Browse the repository at this point in the history
  • Loading branch information
lillian542 committed Nov 19, 2024
1 parent fd67a4c commit 5eb346f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/braket/pennylane_plugin/ahs_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from pennylane._version import __version__
from pennylane.devices import QubitDevice
from pennylane.measurements import MeasurementProcess, SampleMeasurement
from pennylane.ops import CompositeOp, Hamiltonian
from pennylane.ops import CompositeOp
from pennylane.pulse import ParametrizedEvolution
from pennylane.pulse.hardware_hamiltonian import HardwareHamiltonian, HardwarePulse

Expand Down Expand Up @@ -312,9 +312,6 @@ def _validate_measurement_basis(self, observable):
if isinstance(observable, CompositeOp):
for op in observable.operands:
self._validate_measurement_basis(op)
elif isinstance(observable, (Hamiltonian, qml.Hamiltonian)):
for op in observable.ops:
self._validate_measurement_basis(op)

elif not observable.has_diagonalizing_gates:
raise RuntimeError(
Expand Down
4 changes: 2 additions & 2 deletions src/braket/pennylane_plugin/braket_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
Variance,
)
from pennylane.operation import Operation
from pennylane.ops import Hamiltonian, Sum
from pennylane.ops import Sum
from pennylane.tape import QuantumTape

from braket.aws import (
Expand Down Expand Up @@ -287,7 +287,7 @@ def _apply_gradient_result_type(self, circuit, braket_circuit):
f"Braket can only compute gradients for circuits with a single expectation"
f" observable, not a {pl_measurements.return_type} observable."
)
if isinstance(pl_observable, (Hamiltonian, Sum)):
if isinstance(pl_observable, Sum):
targets = [self.map_wires(op.wires) for op in pl_observable.terms()[1]]
else:
targets = self.map_wires(pl_observable.wires).tolist()
Expand Down
13 changes: 4 additions & 9 deletions src/braket/pennylane_plugin/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def supported_observables(device: Device, shots: int) -> frozenset[str]:
*[_BRAKET_TO_PENNYLANE_OBSERVABLES[braket_obs] for braket_obs in braket_observables],
)
supported |= {"Prod", "SProd"}
return supported if shots else supported | {"Sum", "Hamiltonian", "LinearCombination"}
return supported if shots else supported | {"Sum", "LinearCombination"}


def get_adjoint_gradient_result_type(
Expand Down Expand Up @@ -568,7 +568,7 @@ def translate_result_type( # noqa: C901
Returns:
Union[ResultType, tuple[ResultType]]: The Braket result type corresponding to
the given observable; if the observable type has multiple terms, for example a Hamiltonian,
the given observable; if the observable type has multiple terms, for example a Sum,
then this will return a result type for each term.
"""
return_type = measurement.return_type
Expand All @@ -595,7 +595,7 @@ def translate_result_type( # noqa: C901
if isinstance(observable, qml.ops.LinearCombination):
if return_type is ObservableReturnTypes.Expectation:
return tuple(Expectation(_translate_observable(op)) for op in observable.terms()[1])
raise NotImplementedError(f"Return type {return_type} unsupported for Hamiltonian")
raise NotImplementedError(f"Return type {return_type} unsupported for LinearCombination")

braket_observable = _translate_observable(observable)
if return_type is ObservableReturnTypes.Expectation:
Expand All @@ -609,7 +609,7 @@ def translate_result_type( # noqa: C901


def _flatten_observable(observable):
if isinstance(observable, (qml.ops.Hamiltonian, qml.ops.CompositeOp, qml.ops.SProd)):
if isinstance(observable, (qml.ops.CompositeOp, qml.ops.SProd)):
simplified = qml.ops.LinearCombination(*observable.terms()).simplify()
coeffs, _ = simplified.terms()
if len(coeffs) > 1 or coeffs[0] != 1:
Expand Down Expand Up @@ -669,11 +669,6 @@ def _(obs: qml.Projector):
return observables.Hermitian(obs.matrix(), targets=wires)


@_translate_observable.register
def _(t: qml.operation.Tensor):
return reduce(lambda x, y: x @ y, [_translate_observable(factor) for factor in t.obs])


@_translate_observable.register
def _(t: qml.ops.Prod):
return reduce(lambda x, y: x @ y, [_translate_observable(factor) for factor in t.operands])
Expand Down

0 comments on commit 5eb346f

Please sign in to comment.