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

Fix demos to use jax that require grads #1226

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from

Conversation

austingmhuang
Copy link
Contributor

@austingmhuang austingmhuang commented Oct 1, 2024

Doesn't build due to the fact that this PR is not yet merged. JSON files need to be updated as well.

Summary:
Fixes remaining demos that checked for requires_grad. Won't build for now due to missing a fix in this PR

[sc-69776] [sc-69778]

Copy link

github-actions bot commented Oct 1, 2024

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

austingmhuang and others added 11 commits October 1, 2024 17:26
@austingmhuang austingmhuang marked this pull request as ready for review October 15, 2024 20:46
@austingmhuang austingmhuang changed the title [WIP] Fix demos to use jax that require grads Fix demos to use jax that require grads Oct 15, 2024
Comment on lines +197 to +199
# In this example, we use the ``default.qubit`` simulator:
num_wires = 6
dev = qml.device("lightning.qubit", wires=num_wires)
dev = qml.device("default.qubit", wires=num_wires)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason lightning.qubit doesn't work with JAX here. Not sure why but I had to change to using default to get it working.

…ton (#1244)

For the top 20 most visited demos in 2024, updating the `ask a question
on the forum` button url to a unique Discussion Forum thread. Updated
demo's `.metadata.json` files
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @austingmhuang. before doing a full review, could you please make sure that this PR targets dev instead of master? Also, if there is any demo that does not require features in dev, their upgrade should be done in this PR.

Comment on lines +69 to +70
from jax import numpy as jnp
import jax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just use vanilla numpy in this demo.

Comment on lines 204 to +209
from pennylane import qchem
from pennylane import numpy as np
from jax import numpy as jnp

symbols = ['H', 'H']
geometry = np.array([[0.0, 0.0, -0.69434785],
[0.0, 0.0, 0.69434785]], requires_grad = False)
geometry = jnp.array([[0.0, 0.0, -0.69434785],
[0.0, 0.0, 0.69434785]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demo is already updated in another PR, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not updated in that PR. Well that PR had a one line change in this demo by accident.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demo doesn't work without the requires_grad changes because it calls fermionic_hamiltonian directly

from pennylane import numpy as np
import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update this demo in this PR as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it cannot be done. This demo calls electronic_integrals() directly, which checks for requires_grad, leading to an error.

@austingmhuang austingmhuang changed the base branch from master to dev October 23, 2024 21:19
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 this pull request may close these issues.

7 participants