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

Add support for qml.Hamiltonian with lightning.qubit for diff_method='adjoint' #216

Closed
yitchen-tim opened this issue Jan 28, 2022 · 2 comments · Fixed by #294
Closed

Add support for qml.Hamiltonian with lightning.qubit for diff_method='adjoint' #216

yitchen-tim opened this issue Jan 28, 2022 · 2 comments · Fixed by #294
Assignees
Labels
enhancement New feature or request

Comments

@yitchen-tim
Copy link

Issue description

Description of the issue:
When running the following simple code block, it throws the NotImplementedError. There is no issue if I change to other simulators such as default.qubit, or replace the observable to simple observables such as qml.PauliX(0).

import pennylane as qml
import numpy as np

dev = qml.device("lightning.qubit", wires=4)
H, qubits = qml.qchem.molecular_hamiltonian(['H','H'], np.array([0.0, 0.1, 0.0, 0.0, -0.1, 0.0]))

@qml.qnode(dev, diff_method='adjoint')
def circuit(params):
    qml.RX(params, wires=1)
    return qml.expval(H)

circuit(0.123)
  • Expected behavior: It returns the expectation value of the Hamiltonian.

  • Actual behavior: It throws NotImplementedError.

  • Reproduces how often: Every time

  • System information:

Name: PennyLane
Version: 0.20.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, scipy, semantic-version, toml
Required-by: amazon-braket-pennylane-plugin, PennyLane-Lightning, PennyLane-Qchem
Platform info: Linux-4.14.256-197.484.amzn2.x86_64-x86_64-with-debian-buster-sid
Python version: 3.7.10
Numpy version: 1.19.2
Scipy version: 1.5.2
Installed devices:

  • default.gaussian (PennyLane-0.20.0)
  • default.mixed (PennyLane-0.20.0)
  • default.qubit (PennyLane-0.20.0)
  • default.qubit.autograd (PennyLane-0.20.0)
  • default.qubit.jax (PennyLane-0.20.0)
  • default.qubit.tf (PennyLane-0.20.0)
  • default.qubit.torch (PennyLane-0.20.0)
  • lightning.qubit (PennyLane-Lightning-0.20.2)
  • braket.aws.qubit (amazon-braket-pennylane-plugin-1.3.0)
  • braket.local.qubit (amazon-braket-pennylane-plugin-1.3.0)
@antalszava
Copy link
Contributor

Hi @yitchen-tim, thanks for reporting this! 🙂

This is a feature that is not supported with lightning.qubit, the error is meant to refer to that. It's great to know that this would be useful to add in. 👍

@antalszava antalszava changed the title NotImplementedError when evaluating molecular Hamiltonian with lightning.qubit Add support for qml.Hamiltonian with lightning.qubit (NotImplementedError) Jan 28, 2022
@antalszava antalszava changed the title Add support for qml.Hamiltonian with lightning.qubit (NotImplementedError) Add support for qml.Hamiltonian with lightning.qubit for diff_method='adjoint' Jan 28, 2022
@antalszava
Copy link
Contributor

@yitchen-tim a further note here: this is expected not to be working for default.qubit either, see the restrictions to the underlying adjoint_jacobian method in the note box on this page: https://pennylane.readthedocs.io/en/stable/code/api/pennylane.devices.default_qubit.DefaultQubit.html?highlight=adjoint_jacobian#pennylane.devices.default_qubit.DefaultQubit.adjoint_jacobian

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

Successfully merging a pull request may close this issue.

3 participants