Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pybind11 modules from Catalyst's core MLIR libs #1187

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

joeycarter
Copy link
Contributor

@joeycarter joeycarter commented Oct 7, 2024

Context:

Catalyst's core MLIR libraries originally contains two Python extension modules (importable Python modules written in C/C++):

The Python-C++ bindings were originally implemented using pybind11. This PR is part of a larger effort to replace all pybind11 code with nanobind.

However, mlir/python/PyCompilerDriver.cpp was removed in PR #1285, and we have decided to remove mlir/python/QuantumExtension.cpp entirely since we do not ship this module with our wheels. Therefore, we can remove all pybind11 code in Catalyst's core MLIR libs, with no need to replace these modules with nanobind.

Description of the Change:

This change replaces all the pybind11 code in mlir/python/PyCompilerDriver.cpp with the equivalent nanobind objects and operations.

This change removes the MLIR python module QuantumExtension entirely, along with associated tests and infrastructure, since (a) it depends on upstream MLIR Python bindings written in pybind11: mlir/Bindings/Python/PybindAdaptors.h, which would be quite onerous to port to nanobind, and (b) we do not actually use these dialect extensions, nor do we ship them with our wheels.

Benefits:

See Epic 68472 for a list of nanobind's benefits.


[sc-72842]

@joeycarter joeycarter marked this pull request as ready for review October 11, 2024 21:08
@joeycarter joeycarter added the author:build-wheels Run the wheel building workflows on this Pull Request label Oct 11, 2024
Copy link
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.

@joeycarter joeycarter marked this pull request as draft October 11, 2024 22:44
@joeycarter joeycarter marked this pull request as ready for review October 15, 2024 13:49
@joeycarter joeycarter marked this pull request as draft October 15, 2024 21:05
@joeycarter joeycarter marked this pull request as ready for review November 7, 2024 19:27
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.37%. Comparing base (3c835e0) to head (df01e51).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1187   +/-   ##
=======================================
  Coverage   98.37%   98.37%           
=======================================
  Files          78       78           
  Lines       11361    11361           
  Branches      990      990           
=======================================
  Hits        11176    11176           
  Misses        127      127           
  Partials       58       58           

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

joeycarter added a commit that referenced this pull request Nov 13, 2024
**Context:** I had observed when working on the pybind11 -> nanobind
conversions in the MLIR python binding (#1187) that the
`test_pipeline_error` test fails on some platforms because it asserts
that the string `"Trace"` (with a capital "T") is in the error message,
but it is not, even though the stack trace was printed. Normally, it
would match the string `"Trace"` in the first line of the stack trace,
which contains `"llvm::sys::PrintStackTrace"`. For whatever reason, this
line is not always printed out. We can make this test more robust by
matching a string not contained within the stack trace itself, but one
immediately preceding it, which should always be part of the error
message. I've chosen `"diagnostic emitted with trace"` for this purpose
(but I'm happy to take other suggestions).

**Description of the Change:** Change test from

```python
assert "Trace" in e.value.args[0]
```

to

```python
assert "diagnostic emitted with trace" in e.value.args[0]
```

and similarly when asserting that there is **no** stack trace in the
error message.

**Benefits:** More robust test; unblocks #1187.
@joeycarter
Copy link
Contributor Author

We'll need to revisit this PR once #1285 is merged in, since it removes the compiler_driver Python module.

Good news at least that the build system is now sorted out! 🟢

Now that #1285 has been merged, there is no need for nanobind in
Catalyst's core MLIR libraries
@joeycarter joeycarter changed the title Replace pybind11 with nanobind in Catalyst's core Remove pybind11 modules from Catalyst's core MLIR libs Nov 15, 2024
@joeycarter
Copy link
Contributor Author

With the removal of the mlir/python/PyCompilerDriver.cpp module in #1285, there is now no more pybind11 code to replace with nanobind in Catalyst's core MLIR libs! I've updated the title and description to reflect this change.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant