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 tutorial_pulse_programming101.py to type cast expval #1317

Merged
merged 4 commits into from
Feb 14, 2025

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Feb 14, 2025

Context:

In PennyLaneAI/pennylane#6939, a fix was made to qml.expval so that it no longer silently converts the result to a real number. However, in tutorial_pulse_programming101.py we use a Hamiltonian with complex-typed coefficients. This resulted in an imaginary expectation value (X+0j) and broke the jax.value_and_grad function.

Description of change:

Wrap the qnode function to get the expectation value and convert it to a real number. This allows jax.value_and_grad to be used and fixes the demo.

Copy link

👋 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!

Copy link

github-actions bot commented Feb 14, 2025

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

  • Pull Request ID: 1317
  • Deployment SHA: ef9343fb385774ac5d41e50606ce7f4924903f0f
    (The Deployment SHA refers to the latest commit hash the docs were built from)

Note: It may take several minutes for updates to this pull request to be reflected on the deployed site.

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Thanks a lot @andrijapau!

Copy link
Contributor

@JerryChen97 JerryChen97 left a comment

Choose a reason for hiding this comment

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

lgtm

@andrijapau andrijapau added the ci:build-all-qml-demos Build all the Demos for this Pull Request label Feb 14, 2025
@andrijapau andrijapau merged commit 691322d into dev Feb 14, 2025
19 checks passed
@andrijapau andrijapau deleted the fix-pulse-program branch February 14, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:build-all-qml-demos Build all the Demos for this Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants