PennyLaneAI / PennyLaneAI/catalyst

Add explicit attribute (e.g. catalyst.main) for entry/main function

Open
#2,854 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Context:
Several places in the Catalyst codebase assume that the first non-declaration func.func in the module is the program entry point:

  • frontend/catalyst/jit.py : accesses self.mlir_module.body.operations[0]
  • frontend/catalyst/utils/gen_mlir.py : adds llvm.emit_c_interface to the first op
  • mlir/lib/Catalyst/Analysis/ResourceAnalysis.cpp : counts qubit arguments only for the first function
  • . . .

This is not guaranteed by MLIR and relies on JAX's tracing placing the entry function first. If JAX ever reorders module contents, or if future passes move/clone functions, this assumption silently breaks.

Proposed Solution:
Introduce an explicit attribute (e.g., catalyst.entry_point or catalyst.main) that is attached to the entry function during tracing. All downstream consumers (resource analysis, codegen, etc.) should detect the entry point via this attribute rather than positional assumption.

The existing llvm.emit_c_interface attribute or the jit_ name prefix could serve as detection mechanisms, but a dedicated Catalyst attribute is cleaner and self-documenting.

Raised in PR #2782 discussion.

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

Start by tracing how the entry function is created and reviewing the positional lookups in frontend/catalyst/jit.py, frontend/catalyst/utils/gen_mlir.py, and mlir/lib/Catalyst/Analysis/ResourceAnalysis.cpp. Define how the explicit Catalyst entry-point attribute is attached and recognized across these consumers. Done means downstream code identifies the entry function through the attribute rather than assuming it is first.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.