PennyLaneAI / PennyLaneAI/catalyst

Gradient dialect removes `qnode` attribute from quantum functions when creating helper functions.

Open
#419 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug compiler good first issue
Dominant language
Python
Stars
234
Forks
84
Avg merge
2d 15h
Merged PRs (30d)
66

Description

  • Expected behavior: The attribute remains through the lowering of gradient and quantum dialect up until LLVM-IR (in which case we might wish to annotate it with some metadata).

  • Actual behavior: The gradient transforms generates helper functions which will strip the qnode attribute from qnodes. E.g.,

  func.func private @f(%arg0: tensor<f64>) -> tensor<f64> attributes {diff_method = "parameter-shift", llvm.linkage = #llvm.linkage<internal>, qnode} {
  }

Changes to:

  func.func private @f.quantum(%arg0: memref<f64>, %arg1: memref<?xf64>) -> memref<f64> attributes {gradient.qgrad = @f.qgrad, passthrough = ["noinline"]} {
}

This causes async to not be triggered since async looks for the qnode attribute.

  • Reproduces how often: Always

Contributor guide

Open the contributing guide

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.

Research direction

No file or test is named. Trace the gradient and quantum dialect lowering that creates the helper functions shown in the LLVM-IR example, then follow how function attributes are copied or dropped. Confirm that qnode remains available through lowering so async can still detect it, and add coverage for the reproduced case if the existing tests provide a suitable location.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.