Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LinearCombination as an observable #245

Closed
astralcai opened this issue Apr 29, 2024 · 1 comment · Fixed by #246
Closed

Support LinearCombination as an observable #245

astralcai opened this issue Apr 29, 2024 · 1 comment · Fixed by #246

Comments

@astralcai
Copy link
Contributor

Describe the feature you'd like
In v0.36.0 of PennyLane, the new LinearCombination is used in favour of the legacy Hamiltonian, which should also be supported as an observable.

Additional context
There are two classes now to represent a Hamiltonian: qml.ops.Hamiltonian, and qml.ops.LinearCombination. The latter is now used by default in favour of the former. With new opmath enabled, qml.Hamiltonian will refer to LinearCombination, and with new opmath disabled, qml.Hamiltonian will refer to the old Hamiltonian class.

Solution

  1. In braket_device.py, line 169 should be updated to return base_observables.union({"Hamiltonian", "LinearCombination"})
  2. Update all isinstance(..., Hamiltonian) checks to isinstance(..., (qml.ops.Hamiltonian, qml.ops.LinearCombination)), such as line 230 of braket_device.py, line 561 and 691 of translation.py
  3. Update line 584-585 of translation.py to:
@_translate_observable.register(qml.ops.Hamiltonian)
@_translate_observable.register(qml.ops.LinearCombination)
def _(H: Union[qml.ops.Hamiltonian, qml.ops.LinearCombination]):
    ...
@virajvchaudhari
Copy link
Contributor

Thanks for pointing this out @astralcai, we will take a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants