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

Make qml.QutritBasisStatePreparation JIT compatible #6308

Merged
merged 44 commits into from
Oct 11, 2024
Merged

Conversation

willjmax
Copy link
Contributor

This PR makes qml.QutritBasisStatePreparation JIT compatible. Previously, the template used the qml.TShift operator in the decomposition. However, this approach requires non-jittable control flow on the input. To make the template jittable the decomposition is changed to return a qml.ops.QutritUnitary representing a TShift operator raised to some power. This change requires adding matrix_power and eigh to the multi dispatch. This PR addresses sc-70863.

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 Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.39%. Comparing base (38a5140) to head (111405e).
Report is 321 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6308   +/-   ##
=======================================
  Coverage   99.39%   99.39%           
=======================================
  Files         448      448           
  Lines       42464    42471    +7     
=======================================
+ Hits        42209    42216    +7     
  Misses        255      255           

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

Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Thanks @willjmax! Some minor queries, before I dig in deeper.

pennylane/templates/state_preparations/basis_qutrit.py Outdated Show resolved Hide resolved
pennylane/templates/state_preparations/basis_qutrit.py Outdated Show resolved Hide resolved
Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

Nice! 😄

Just one comment. The following example does not work with jax.jit. For some reason qml.sample fails. I have tested default.qubit with BasisState to see if it should fail but it works correctly there.

n = 2

@jax.jit
@qml.qnode(qml.device("default.qutrit", wires = n, shots = 1))
def circuit(state):

    qml.QutritBasisStatePreparation(state, wires = range(n))
    
    return qml.sample(wires = range(n))

state = jax.numpy.array([1,1])
circuit(state)

Otherwise, the PR looks good to me :)

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

Looks good! 👌

Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

[Non blocker] could combine matrix and pl_gates tests into one decomposition test, otherwise looks good with just one minor thing.

@obliviateandsurrender
Copy link
Contributor

obliviateandsurrender commented Oct 11, 2024

I think qutrit basis state prep test in templates/state_preparations/basis_qutrit.py should be made to xfail for the CI to pass.

@willjmax
Copy link
Contributor Author

I think qutrit basis state prep test in templates/state_preparations/basis_qutrit.py should be made to xfail for the CI to pass.

No, this was due to a bug that I caused. I pushed a fix.

@willjmax willjmax enabled auto-merge (squash) October 11, 2024 19:03
@soranjh soranjh disabled auto-merge October 11, 2024 19:24
@willjmax willjmax merged commit 814e991 into master Oct 11, 2024
38 checks passed
@willjmax willjmax deleted the jit-qutrit branch October 11, 2024 20:06
austingmhuang pushed a commit that referenced this pull request Oct 23, 2024
This PR makes `qml.QutritBasisStatePreparation` JIT compatible.
Previously, the template used the `qml.TShift` operator in the
decomposition. However, this approach requires non-jittable control flow
on the input. To make the template jittable the decomposition is changed
to return a `qml.ops.QutritUnitary` representing a `TShift` operator
raised to some power. This change requires adding `matrix_power` and
`eigh` to the multi dispatch. This PR addresses sc-70863.

---------

Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
mudit2812 pushed a commit that referenced this pull request Nov 11, 2024
This PR makes `qml.QutritBasisStatePreparation` JIT compatible.
Previously, the template used the `qml.TShift` operator in the
decomposition. However, this approach requires non-jittable control flow
on the input. To make the template jittable the decomposition is changed
to return a `qml.ops.QutritUnitary` representing a `TShift` operator
raised to some power. This change requires adding `matrix_power` and
`eigh` to the multi dispatch. This PR addresses sc-70863.

---------

Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
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.

4 participants