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

[Capture] unitary_to_rot is plxpr compatible #6916

Merged
merged 42 commits into from
Feb 11, 2025

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Feb 3, 2025

Context:

This PR adds a UnitaryToRotInterpreter to apply the unitary_to_rot transform natively to plxpr.

Description of the Change:

  • Add UnitaryToRotInterpreter to transform plxpr

Benefits:

unitary_to_rot can be applied natively to plxpr.

import jax
import pprint

qml.capture.enable()

U1 = qml.Rot(1.0, 2.0, 3.0, wires=0)

@qml.capture.expand_plxpr_transforms
@qml.transforms.unitary_to_rot
def f(U1):
    qml.X(0)
    qml.QubitUnitary(U1, 0)
    qml.Y(0)
    return qml.expval(qml.Z(0))

>>> jaxpr = jax.make_jaxpr(f)(U1.matrix())
>>> tape = qml.tape.plxpr_to_tape(jaxpr.jaxpr, jaxpr.consts, U1.matrix())
>>> pprint.pprint(tape.operations)
[X(0),
 RZ(Array(1., dtype=float32), wires=[0]),
 RY(Array(2., dtype=float32), wires=[0]),
 RZ(Array(3., dtype=float32), wires=[0]),
 Y(0)]
>>> pprint.pprint(tape.measurements)
[expval(Z(0))]

Possible Drawbacks: None identified.

[sc-83556]

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.59%. Comparing base (67fbcba) to head (ea4a582).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6916   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files         480      480           
  Lines       45520    45547   +27     
=======================================
+ Hits        45335    45362   +27     
  Misses        185      185           

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

@andrijapau andrijapau marked this pull request as draft February 3, 2025 18:43
@andrijapau andrijapau changed the title Add UnitaryToRotInterpreter for transforming plxpr [Capture] unitary_to_rot is plxpr compatible Feb 4, 2025
@andrijapau andrijapau marked this pull request as ready for review February 4, 2025 19:56
@andrijapau andrijapau requested a review from mudit2812 February 4, 2025 20:17
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Implementation looks good. I'll do a second pass later to review tests.

@andrijapau andrijapau requested a review from mudit2812 February 6, 2025 19:59
andrijapau and others added 2 commits February 7, 2025 13:53
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
@andrijapau andrijapau requested a review from mudit2812 February 7, 2025 19:05
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Pretty much ready to approve. Could you add a test to verify that using @unitary_to_rot with @qml.capture.expand_plxpr_transforms works correctly? Check out this PR for a good example

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@andrijapau andrijapau requested a review from mudit2812 February 10, 2025 19:10
@andrijapau andrijapau enabled auto-merge (squash) February 11, 2025 18:06
@andrijapau andrijapau disabled auto-merge February 11, 2025 18:07
@andrijapau andrijapau enabled auto-merge (squash) February 11, 2025 18:22
@andrijapau andrijapau merged commit 65c52a8 into master Feb 11, 2025
46 checks passed
@andrijapau andrijapau deleted the unitary-to-rot-interpreter branch February 11, 2025 18:50
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