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

[Frontend] JAX tracer supporting user-defined tape transformation #240

Merged
merged 131 commits into from Sep 21, 2023

Conversation

grwlf
Copy link
Contributor

@grwlf grwlf commented Aug 11, 2023

In this PR we aim at making it possible to apply user-defined transformations to a tape containing Catalyst quantum operators. The main difficulty is related to the fact that in Catalyst we only trace programs rather than execute them so the operations on tape: (1) are filled with abstract parameters, (2) include control flow operations containing nested tapes.

The approach we are working on would essentially split the tracing process into classical and quantum parts. In order to do so, we store JAX tracing contexts and re-enter them as needed. We described the idea and the associated risks in the internal document.

Tasks:

  • Prototyping is done
  • Core tracing framework is implemented
  • Catalyst extensions are ported to the new tracing framework
    • Control flow ops (For-loops, WhileLoops, Conditionals, Adjoint)
    • CustomOps
    • QubitUnitary
    • Mid-circuit measurement
    • Measurements (Sample, ExpVal, Counts, Probs, State)
    • Observables (Compbasis, Paulis, Hadamard, Hermitian,Tensor,Hamiltonian)
    • Gradient primitives (Grad, JVP, VJP)
  • All kinds of execution pipelines are supported
    • Both qjit and qnode
    • Just qjit (no quantum parts)
    • Just qnode (interpretation)
  • Optimizations are ported
    • Qubit insert/extract state preservation (quantum register tracing optimisation)
    • Differentiation-specific procedures (JVP/VJP/Grad) are reviewed and ported
  • All tests pass locally
  • Latest version of Catalyst is merged into the PR
    • Obvious merge conflicts are solves
    • Pytests are fixed
    • Littests are fixed
  • Code is clean
    • Temporary and unused source files are removed
    • JAX internals are collected in a separate utility file
    • Tracing context classes are unified
    • Pylint is happy
    • Docstrings are ported or created
    • CodeFactor is happy
    • Codecov is happy
    • Remaining FIXMEs are fixed

[sc-41345]

@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Patch coverage: 99.62% and project coverage change: +0.04% 🎉

Comparison is base (8106beb) 99.47% compared to head (02e1361) 99.51%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   99.47%   99.51%   +0.04%     
==========================================
  Files          41       40       -1     
  Lines        7192     7196       +4     
  Branches      386      410      +24     
==========================================
+ Hits         7154     7161       +7     
+ Misses         20       17       -3     
  Partials       18       18              
Files Changed Coverage Δ
frontend/catalyst/pennylane_extensions.py 99.58% <99.34%> (+0.43%) ⬆️
frontend/catalyst/jax_tracer.py 99.55% <99.50%> (+0.27%) ⬆️
frontend/catalyst/compilation_pipelines.py 100.00% <100.00%> (ø)
frontend/catalyst/jax_primitives.py 97.08% <100.00%> (+0.03%) ⬆️
frontend/catalyst/utils/contexts.py 100.00% <100.00%> (ø)
frontend/catalyst/utils/jax_extras.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

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

Copy link
Collaborator

@dime10 dime10 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 to me 💯

frontend/catalyst/utils/tracing.py Outdated Show resolved Hide resolved
frontend/catalyst/utils/jax_extras.py Outdated Show resolved Hide resolved
frontend/catalyst/jax_tracer.py Outdated Show resolved Hide resolved
@grwlf grwlf merged commit b2dc4d5 into main Sep 21, 2023
18 checks passed
@grwlf grwlf deleted the tape-transform branch September 21, 2023 18:59
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.

None yet

3 participants