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

[BugFix] - PennyLane raises an informative error if running circuit(s) with dynamic tracers as wires #6405

Merged
merged 8 commits into from
Oct 17, 2024

Conversation

PietropaoloFrisoni
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni commented Oct 16, 2024

Context: Pennylane provides incorrect results or non-informative errors (depending on the circumstances) when working with @jax.jit and dynamic wires (that is, JAX tracers) at the same time. For example:

dev = qml.device("default.qubit")

@jax.jit
@qml.qnode(dev)
def circuit(input_wires):
    qml.Hadamard(input_wires[1])
    return qml.probs(wires=[0, 1])

circuit([0, 1])

Description of the Change: Pennylane raises an informative error in the validate_device_wires transform to inform the user that abstract wires are not currently supported. We cannot raise this error in the Wires class since this would be a problem for Catalyst. This solution should not (hopefully) cause issues in other repositories.

Benefits: This prevents non-informative errors and, most importantly, wrong results.

Possible Drawbacks: This change could potentially break existing code(s) that somehow used abstract wires and for some reason they worked fine.

Related GitHub Issues: #6380

Related ShortCut Stories: [sc-75756]

@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review October 16, 2024 14:49
@PietropaoloFrisoni PietropaoloFrisoni changed the title [BugFix] - PennyLane cannot work correctly with dynamic tracers as wires [BugFix] - PennyLane raises an informative error if running circuit(s) with dynamic tracers as wires Oct 16, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.40%. Comparing base (e0f614c) to head (cd78015).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6405   +/-   ##
=======================================
  Coverage   99.40%   99.40%           
=======================================
  Files         447      447           
  Lines       42400    42418   +18     
=======================================
+ Hits        42146    42164   +18     
  Misses        254      254           

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

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!

@albi3ro albi3ro self-requested a review October 17, 2024 15:37
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.

Excellent choice of location for this fix 👍

@PietropaoloFrisoni PietropaoloFrisoni enabled auto-merge (squash) October 17, 2024 21:26
@PietropaoloFrisoni PietropaoloFrisoni merged commit 056bb92 into master Oct 17, 2024
36 checks passed
@PietropaoloFrisoni PietropaoloFrisoni deleted the Bug_wires_tracers branch October 17, 2024 21:53
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