diff --git a/src/braket/pennylane_plugin/ahs_device.py b/src/braket/pennylane_plugin/ahs_device.py index 524b3783..39954ea2 100644 --- a/src/braket/pennylane_plugin/ahs_device.py +++ b/src/braket/pennylane_plugin/ahs_device.py @@ -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 @@ -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( diff --git a/src/braket/pennylane_plugin/braket_device.py b/src/braket/pennylane_plugin/braket_device.py index 223c9d1a..01c183bd 100644 --- a/src/braket/pennylane_plugin/braket_device.py +++ b/src/braket/pennylane_plugin/braket_device.py @@ -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 ( @@ -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() diff --git a/src/braket/pennylane_plugin/translation.py b/src/braket/pennylane_plugin/translation.py index aab1a20f..3587ddcb 100644 --- a/src/braket/pennylane_plugin/translation.py +++ b/src/braket/pennylane_plugin/translation.py @@ -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( @@ -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 @@ -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: @@ -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: @@ -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])