Skip to content

Forward Catalyst subprocess diagnostics to Python - #3080

Open
sengthai wants to merge 6 commits into
mainfrom
forward-and-print-from-stderr
Open

Forward Catalyst subprocess diagnostics to Python#3080
sengthai wants to merge 6 commits into
mainfrom
forward-and-print-from-stderr

Conversation

@sengthai

@sengthai sengthai commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Context:
Successful Catalyst subprocess calls capture both output streams but previously returned only stdout, silently discarding warnings and other diagnostics written to stderr. This prevented warnings from appearing in PennyLane workflows such as qp.specs.

We also has verbose but this will output like system log which are not necessary for end users.

Here, we forward captured Catalyst stderr while preserving stdout as normal. When Python’s stderr is attached to a terminal, pass --color to Catalyst so LLVM diagnostics retain their colors. Note that to make this work PL needs to update to pass the stderr_return=True.

@sengthai
sengthai marked this pull request as ready for review July 30, 2026 14:17
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.92%. Comparing base (c67c55b) to head (d64ec66).

Files with missing lines Patch % Lines
frontend/catalyst/compiler.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3080      +/-   ##
==========================================
- Coverage   96.92%   96.92%   -0.01%     
==========================================
  Files         166      166              
  Lines       19133    19138       +5     
  Branches     1815     1817       +2     
==========================================
+ Hits        18545    18549       +4     
  Misses        429      429              
- Partials      159      160       +1     

☔ 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.

@mehrdad2m

Copy link
Copy Markdown
Contributor

Thanks @sengthai. I noticed this is very similar to what

def _catalyst(*args, stdin=None, stderr_return=False):
"""Raw interface to catalyst"""
cmd = _get_catalyst_cli_cmd(*args, stdin=stdin)
try:
result = subprocess.run(cmd, input=stdin, check=True, capture_output=True, text=True)
if stderr_return:
return result.stdout, result.stderr
return result.stdout # pragma: no cover
except subprocess.CalledProcessError as e: # pragma: no cover
raise CompileError(f"catalyst failed with error code {e.returncode}: {e.stderr}") from e
does for the inspection module in python_interface. Do you think it make sense to unify them and follow the same approach of making it optional?

@sengthai

sengthai commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@mehrdad2m Thanks and good to know! I made a change and mirror the xdsl's approach b7a204f. And I just realized that qjit has verbose flag to print those diagnostic from Catalyst. So, here I enable this in qp.specs.
PennyLaneAI/pennylane#9938

@sengthai
sengthai requested review from a team and mehrdad2m July 31, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants