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

Raise RuntimeWarning if jax > 0.4.28 is installed #6864

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Jan 20, 2025

Jax is not compatible with pennylane for versions > 0.4.28 (confirmed by the test logs of this PR). This PR raises a RuntimeWarning if version > 0.4.28 is installed:

  • In QNode.__init__ if the specified interface resolves to JAX or JAX_JIT
  • In execute if the original interface was "auto" or None and the resolved interface is JAX or JAX_JIT. I don't raise a warning if the original interface was jax/jax-jit because if that is the case, QNode.__init__ should've already raised a warning.
  • This is done by adding a _validate_jax_version private kwarg to qml.math.get_canonical_interface_name, which is called by QNode.__init__, and qml.workflow.resolution._resolve_interface (used by qml.execute), so that both those entry points can raise warnings if appropriate.

Possible drawbacks:
None. The only annoying is that our CI uses supported versions of jax, so we can't get coverage for the runtime warning. I've added a # pragma: no cover to work around this, but I'm not particularly happy about it.

[sc-82570]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.60%. Comparing base (872607d) to head (2395413).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6864   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files         476      476           
  Lines       45182    45195   +13     
=======================================
+ Hits        45002    45015   +13     
  Misses        180      180           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mudit2812 mudit2812 requested a review from josh146 January 20, 2025 21:09
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

So why are we not validating if someone specifies interface="jax"? Or am I missing something?

@mudit2812 mudit2812 requested a review from albi3ro January 21, 2025 19:26
@@ -551,7 +551,7 @@ def __init__(
# input arguments
self.func = func
self.device = device
self._interface = get_canonical_interface_name(interface)
self._interface = get_canonical_interface_name(interface, _validate_jax_version=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be less invasive to do something like,

Suggested change
self._interface = get_canonical_interface_name(interface, _validate_jax_version=True)
self._interface = get_canonical_interface_name(interface)
if "jax" in self.interface:
_validate_jax_version()

and not have to modify anything downstream. For example, _resolve_interface is called in qml.execute which (with the new changes coming) will only be configurable purely from the QNode with no other entry point. That way I see us only having to verify the version here.

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.

3 participants