Skip to content

Commit

Permalink
Remove pybind11 modules from Catalyst's core MLIR libs (#1187)
Browse files Browse the repository at this point in the history
**Context:**

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

*
[mlir/python/PyCompilerDriver.cpp](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/python/PyCompilerDriver.cpp)
*
[mlir/python/QuantumExtension.cpp](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/python/QuantumExtension.cpp)

The Python-C++ bindings were originally implemented using pybind11. This
PR is part of a larger effort to replace all pybind11 code with nanobind
to to align with our adoption of Python's stable ABI.

However, mlir/python/PyCompilerDriver.cpp was removed in PR #1285, and
furthermore we have decided to deprecate
mlir/python/QuantumExtension.cpp entirely since it was not included in
the distributed 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](https://github.com/PennyLaneAI/catalyst/blob/main/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](https://github.com/llvm/llvm-project/blob/main/mlir/include/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](https://app.shortcut.com/xanaduai/epic/68472) for a
list of nanobind's benefits.

-----


[[sc-72842](https://app.shortcut.com/xanaduai/story/72842/replace-pybind11-with-nanobind-in-catalyst-s-core)]
  • Loading branch information
joeycarter authored Nov 17, 2024
1 parent f157a0d commit 4925d37
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 192 deletions.
7 changes: 7 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@

<h3>Deprecations 👋</h3>

<h3>Internal changes ⚙️</h3>

* The `QuantumExtension` module (previously implemented with pybind11) has been removed. This module
was not included in the distributed wheels and has been deprecated to align with our adoption of
Python's stable ABI, which pybind11 does not support.
[(#1187)](https://github.com/PennyLaneAI/catalyst/pull/1187)

<h3>Documentation 📝</h3>

* A new tutorial going through how to write a new MLIR pass is available. The tutorial writes an empty pass that prints hello world. The code of the tutorial is at [a separate github branch](https://github.com/PennyLaneAI/catalyst/commit/ba7b3438667963b307c07440acd6d7082f1960f3).
Expand Down
11 changes: 0 additions & 11 deletions mlir/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ declare_mlir_dialect_python_bindings(
dialects/mitigation.py
DIALECT_NAME mitigation)

declare_mlir_python_extension(QuantumPythonSources.Extension
MODULE_NAME _quantumDialects
ADD_TO_PARENT QuantumPythonSources
SOURCES
QuantumExtension.cpp
PRIVATE_LINK_LIBS
LLVMSupport
MLIRIR
EMBED_CAPI_LINK_LIBS
QuantumCAPI
)

################################################################################
# Common CAPI
Expand Down
77 changes: 0 additions & 77 deletions mlir/python/QuantumExtension.cpp

This file was deleted.

1 change: 0 additions & 1 deletion mlir/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ set(TEST_SUITES

if(QUANTUM_ENABLE_BINDINGS_PYTHON)
list(APPEND DIALECT_TESTS_DEPEND QuantumPythonModules)
list(APPEND TEST_SUITES python)
endif()

add_lit_testsuite(check-dialects "Run the regression tests for mlir dialects"
Expand Down
7 changes: 0 additions & 7 deletions mlir/test/python/lit.local.cfg

This file was deleted.

29 changes: 0 additions & 29 deletions mlir/test/python/smoketest_catalyst.py

This file was deleted.

33 changes: 0 additions & 33 deletions mlir/test/python/smoketest_gradient.py

This file was deleted.

34 changes: 0 additions & 34 deletions mlir/test/python/smoketest_quantum.py

This file was deleted.

0 comments on commit 4925d37

Please sign in to comment.