Skip to content

Rework the catalyst CLI installation mechanism#2970

Open
dime10 wants to merge 3 commits into
mainfrom
repackage-catalyst-shim
Open

Rework the catalyst CLI installation mechanism#2970
dime10 wants to merge 3 commits into
mainfrom
repackage-catalyst-shim

Conversation

@dime10

@dime10 dime10 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

In order to better support dynamically linked or loaded libraries from the Catalyst executable (the CLI tool), we need to guarantee a predictable location. Currently, the binary is installed via the data_files mechanism which is not the most predictable (see current get_cli_path impl), and separates the CLI binary from other package libraries (typically under site-packages/catalyst/lib).

For dynamic linking of shared libs, we'd need the .so to be located on a fixed path relative to the executable, since this path needs to be set at build time (i.e. RPATH). For dynamically loaded libraries (dlopen), the fixed relative path removes the need for heuristics to compute the real path of a shared lib.

The new system leverages the console_scripts entry point mechanism to install a tiny shim in a location automatically available on PATH for most Python installs.
This is common practice among CLI tools distributed as a Python package (e.g. cmake) and comes with a few advantages:

  • catalyst is available as a command for both wheel installations and editable installs (the current mechanism only works for wheel installs)
  • predictable/fixed path of the CLI within the Catalyst package
  • simpler get_cli_path implementation (fewer heuristics)

[sc-122013]

Note on performance:

The overhead of running the CLI through the shim in the first version was about 100x. While only a couple of seconds total (on an empty file / pipeline), when used interactively this is clearly noticeable and off-putting. The new structure avoids importing Catalyst except the necessary pieces to locate the binary. The final result is about 10x slower than when invoked directly, but this is fast enough to not be a burden (~0.3s).

dime10 added 3 commits June 19, 2026 16:51
The overhead of running the CLI through the shim in the previous version
was about 100x. While only a couple of seconds total
(on an empty file / pipeline), when used interactively this is clearly
noticeable and off-putting. The new structure avoids importing Catalyst
except the necessary pieces to locate the binary. The final result is
about 10x slower than when invoked directly, but this is fast enough
to not be a burden (~0.3s).
@dime10 dime10 requested a review from a team June 19, 2026 23:31
@dime10 dime10 added frontend Pull requests that update the frontend author:build-wheels Run the wheel building workflows on this Pull Request labels Jun 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (9016922) to head (46c6470).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2970   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files         166      166           
  Lines       19185    19215   +30     
  Branches     1786     1788    +2     
=======================================
+ Hits        18604    18634   +30     
  Misses        429      429           
  Partials      152      152           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kipawaa kipawaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such a great QoL upgrade, thanks @dime10 !

spec = importlib.util.find_spec("catalyst")
if spec is None or spec.origin is None:
raise ImportError(
"Could not locate the 'catalyst' package, please make sure it is installed."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide an install hint here, ex. via "pip install pennylane-catalyst"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I would consider that an installation instruction, which we usually want to keep in a centralized placed. I'm pretty sure any Python user also knows how to pip install a package 😅 But what we could do is link to the install guide, why not :)


def get_cli_path() -> str: # pragma: nocover
"""Method to obtain the Catalyst CLI path packaged via the data_files mechanism."""
def get_cli_path() -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much nicer 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truly 😅

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

Labels

author:build-wheels Run the wheel building workflows on this Pull Request frontend Pull requests that update the frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants