annotate-invalid-gradient-functions fails on call chains deeper than 9 functions

Open
#3,480 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@JohannesWittmann9 is already working on this.

Since Nov 17, 2026.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
compilers

Research direction

Start by locating AnnotateInvalidGradientFunctionsPass and its greedy pattern rewrite, then read how the pass visits functions and applies MLIR's iteration limit. Reproduce the failure with a measurement at the bottom of a call chain of at least 10 functions, comparing caller-before-callee and callee-before-caller order. Done means compilation succeeds regardless of function order; the issue names no test file, so find the relevant pass tests in the repository.

Written by the indexing model from the issue text.

Description

Description

AnnotateInvalidGradientFunctionsPass fails on modules where a measurement sits at the bottom of a call chain 9 or more calls deep. The pass seems to mark one more caller per iteration of the greedy pattern rewriter. Once the chain is longer than the default maximum number of iterations (10), the rewrite doesn’t converge and compilation fails. With callers defined before callees, the same chains (tested up to 50) pass, so the result depends on the order the functions are visited.

This introduces a bug in Qrisp, which is was fixing by removing the pass for the pipeline. This however is no long term solution so a fix in catalyst would be appropriate. (eclipse-qrisp/Qrisp#886)

Suggested fix

The GreedyPatternRewriter of MLIR stops after maximum number of iterations (defaults to 10) and I think the walk order matters. Currently I do not see a way of accessing the config of the GreedyPatternRewriter. So setting a different walking strategy or increased number of iterations would be my idea.

Notes

I would be happy to work on this, as it would help us with fixing our bug. 😄

Dominant language
Python
Stars
234
Forks
84
Avg merge
2d 12h
Merged PRs (30d)
84

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PennyLaneAI/catalyst

All issues in PennyLaneAI/catalyst

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.