Skip to content

Commit

Permalink
[Frontend] Program verification (#626)
Browse files Browse the repository at this point in the history
**Context:** Having a proper encoding for the device capabilites, we
implement the main part of program verification in this PR.

**Description of the Change:**
[sc-55558]
[sc-60607]
[sc-60648]
* [x] Verify that no MCM (measure op) is present in the call 
* [ ] Verify that no callbacks are present in the call tree (future:
verify that callbacks have custom vjp or are io callbacks)
* [x] Verify that no state or variance is returned from the QNode.
(Double check if Lightning Adjoint supports this!)
* [x] adjoint diff method: Does the Tape only contain operations deemed
differentiable by the QJITDevice from the TOML spec?
* [x] parameter-shit method: Does the Tape only contain operations that
support the 2-term parameter shift rule?



**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

The following PRs need to be merged before this one:
- #609 Introduces device
capabilities.
- #712 Makes
toml-independent tests possible.

---------

Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
Co-authored-by: Lillian <lillian542@gmail.com>
  • Loading branch information
4 people committed Jun 13, 2024
1 parent 8330b75 commit a36947d
Show file tree
Hide file tree
Showing 25 changed files with 1,292 additions and 401 deletions.
2 changes: 1 addition & 1 deletion .dep-versions
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ llvm=cd9a641613eddf25d4b25eaa96b2c393d401d42c
enzyme=1beb98b51442d50652eaa3ffb9574f4720d611f1

# Always remove custom PL/LQ versions before release.
pennylane=7f97ea735b3c43b43a0ffe34040bffaa49603268
pennylane=f0bc6120747749497b8ef08238485526ec376a26
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ catalyst: runtime dialects frontend
.PHONY: frontend
frontend:
@echo "install Catalyst Frontend"
# Uninstall pennylane before updating Catalyst, since pip will not replace two development
# versions of a package with the same version tag (e.g. 0.37-dev0).
$(PYTHON) -m pip uninstall -y pennylane
$(PYTHON) -m pip install -e . --extra-index-url https://test.pypi.org/simple
rm -r frontend/PennyLane_Catalyst.egg-info

Expand Down
1 change: 0 additions & 1 deletion frontend/catalyst/api_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from catalyst.api_extensions.error_mitigation import mitigate_with_zne
from catalyst.api_extensions.function_maps import vmap
from catalyst.api_extensions.quantum_operators import (
Controlled,
HybridAdjoint,
HybridCtrl,
MidCircuitMeasure,
Expand Down
6 changes: 3 additions & 3 deletions frontend/catalyst/api_extensions/differentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
probs_p,
vjp_p,
)
from catalyst.jax_tracer import Function
from catalyst.jax_tracer import Function, mark_gradient_tracing
from catalyst.tracing.contexts import EvaluationContext
from catalyst.utils.exceptions import DifferentiableCompileError

Expand Down Expand Up @@ -716,7 +716,8 @@ def _make_jaxpr_check_differentiable(f: Differentiable, grad_params: GradParams,
"""Gets the jaxpr of a differentiable function. Perform the required additional checks and
return the output tree."""
method = grad_params.method
jaxpr, shape = jax.make_jaxpr(f, return_shape=True)(*args)
with mark_gradient_tracing(method):
jaxpr, shape = jax.make_jaxpr(f, return_shape=True)(*args)
_, out_tree = tree_flatten(shape)
assert len(jaxpr.eqns) == 1, "Expected jaxpr consisting of a single function call."
assert jaxpr.eqns[0].primitive == func_p, "Expected jaxpr consisting of a single function call."
Expand All @@ -742,7 +743,6 @@ def _make_jaxpr_check_differentiable(f: Differentiable, grad_params: GradParams,
)

_verify_differentiable_child_qnodes(jaxpr, method)

return jaxpr, out_tree


Expand Down
Loading

0 comments on commit a36947d

Please sign in to comment.