Skip to content

Conversation

@rturrado
Copy link
Contributor

@rturrado rturrado commented Dec 2, 2025

Context:
Currently we have two pipeline registries: the frontend pipeline is used by default qjit program flow, and the CPP pipeline is used by CLI and things like having stage names in the pipeline being passed into the pipeline kwarg on qjit, e.g. in the oqd, mbqc, ppm pytests.

This seems redundant, not to mention error-prone when developing and maintaining.

With more and more custom pipelines emerging and people start thinking about pipeline organization more (e.g. #1758), it would be good to have pipeline registration in just one place.

Description of the Change:

  • Set pipelineList in mlir/include/DefaultPipelines.h as the only source of truth for pipeline and pass names.
    This pipeline list is a vector of PipelineInfo, each of which is a pair of pipeline name and pass names.
    The pass names are just vectors of strings too.
  • Update mlir/lib/Driver/Pipelines.cpp and frontend/catalyst/pipelines.py to use DefaultPipelines.h, via a few accessor functions.
    These were the 2 points where information was being duplicated at the moment.
    In order for the Python code to use the C++ code, add a default_pipelines nanobind module to frontend/catalyst.

Benefits:
The definition of the pipelines and passes, used by C++ and Python code, is defined just in one point.

Possible Drawbacks:

  • We introduce mlir/include/Driver/DefaultPipelines.h as a dependency to the frontend. It's not a big deal but it is ugly to depend on files outside the project.
  • I don't think this PR solves the two pipeline registration issue. It just proposes a solution for the duplication of data. But I fear that the issue complains about the duplication of the processes of registration too.
  • On top of this last point, I think that the CPP pipeline code could be refactored a lot. I assume this is going to be accomplished in a near future work.

Related GitHub Issues:
#1762

Set pipelineList in mlir/include/DefaultPipelines.h as the only source of truth for pipeline and pass names.
Update mlir/lib/Driver/Pipelines.cpp to use getEnforceRuntimeInvariantsPipeline() function from DefaultPipelines.h.
Update frontend/catalyst/pipelines.py to use get_enforce_runtime_invariants_stage() function from default_pipelines nanobind module.
Add fmt library dependency to mlir/lib/Driver.

Add default_pipelines nanobind module to frontend/catalyst.
At the moment, it only exports a couple of functions, one to get the pipeline names, and the other to get the pass names of the EnforceRuntimeInvariants stage.
Move nanobind configuration code from frontend/catalyst/utils to frontend.

Add catalyst.default_pipelines as a CMakeExtension to setup.py.
Update Pipelines.cpp and pipelines.py to use the new accessor functions.
@github-actions github-actions bot added the external PRs where the author is not a part of PennyLane Org (or part of external contributors team) label Dec 2, 2025
@dime10
Copy link
Contributor

dime10 commented Dec 2, 2025

Thank you @rturrado 🎉 As discussed in the issue I'll put a hold label on this for the time being :)

@rturrado
Copy link
Contributor Author

rturrado commented Dec 2, 2025

@dime10 yes, yes, thanks!

@rturrado
Copy link
Contributor Author

rturrado commented Dec 3, 2025

By the way, when unifying the HLOLoweringPass passes from Pipelines.cpp and pipelines.py I found out that:

  • In Pipelines.cpp StablehloLegalizeToLinalgPass was nested but in pipelines.py it was not.
  • In pipelines.py there were two more passes than in Pipelines.cpp: detensorize-function-boundary, and symbol-dce.

@dime10
Copy link
Contributor

dime10 commented Dec 3, 2025

By the way, when unifying the HLOLoweringPass passes from Pipelines.cpp and pipelines.py I found out that:

  • In Pipelines.cpp StablehloLegalizeToLinalgPass was nested but in pipelines.py it was not.
  • In pipelines.py there were two more passes than in Pipelines.cpp: detensorize-function-boundary, and symbol-dce.

Ah, thanks for reporting this! That's exactly the problem we're trying to prevent I suppose 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge external PRs where the author is not a part of PennyLane Org (or part of external contributors team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants