From fdbc84c6237ac026821ee5c06eb96898ffd7006b Mon Sep 17 00:00:00 2001 From: Yannick Stade <100073938+ystade@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:20:16 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Add=20basic=20Pytho?= =?UTF-8?q?n=20bindings=20for=20NAComputation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- src/python/CMakeLists.txt | 2 ++ src/python/na/CMakeLists.txt | 23 +++++++++++++++++++++++ src/python/na/register_na_computation.cpp | 23 +++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/python/na/CMakeLists.txt create mode 100644 src/python/na/register_na_computation.cpp diff --git a/pyproject.toml b/pyproject.toml index 86458d2386..66a1de8c35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,7 +85,7 @@ ninja.version = ">=1.10" build-dir = "build/{wheel_tag}/{build_type}" # Only build the Python bindings target -build.targets = ["ir"] +build.targets = ["ir", "na"] # Only install the Python package component install.components = ["mqt-core_Python"] diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 07d753def5..cfd17992de 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -1,2 +1,4 @@ # add the IR bindings package add_subdirectory(ir) +# add the NA bindings package +add_subdirectory(na) diff --git a/src/python/na/CMakeLists.txt b/src/python/na/CMakeLists.txt new file mode 100644 index 0000000000..62903dab4f --- /dev/null +++ b/src/python/na/CMakeLists.txt @@ -0,0 +1,23 @@ +if(NOT TARGET na) + # collect source files + file(GLOB_RECURSE NA_SOURCES **.cpp) + + # declare the Python module + pybind11_add_module( + # Name of the extension + na + # Prefer thin LTO if available + THIN_LTO + # Optimize the bindings for size + OPT_SIZE + # Source code goes here + ${MQT_CORE_INCLUDE_BUILD_DIR}/python/pybind11.hpp + ${NA_SOURCES}) + target_link_libraries(na PRIVATE MQT::CoreNA MQT::ProjectOptions MQT::ProjectWarnings) + + # Install directive for scikit-build-core + install( + TARGETS na + DESTINATION . + COMPONENT ${MQT_CORE_TARGET_NAME}_Python) +endif() diff --git a/src/python/na/register_na_computation.cpp b/src/python/na/register_na_computation.cpp new file mode 100644 index 0000000000..49accdcb15 --- /dev/null +++ b/src/python/na/register_na_computation.cpp @@ -0,0 +1,23 @@ +#include "na/NAComputation.hpp" +#include "python/pybind11.hpp" + +namespace mqt { + +void registerNAComputation(py::module& m) { + + auto qc = py::class_(m, "NAComputation"); + + ///--------------------------------------------------------------------------- + /// \n Constructors \n + ///--------------------------------------------------------------------------- + + qc.def(py::init<>(), "Constructs an empty NAComputation."); + + ///--------------------------------------------------------------------------- + /// \n String Serialization \n + ///--------------------------------------------------------------------------- + /// + qc.def("__str__", + [](const na::NAComputation& circ) { return circ.toString(); }); +} +} // namespace mqt From 31b7ae574761b3fd3f8338d07d318be73587fd0f Mon Sep 17 00:00:00 2001 From: Yannick Stade <100073938+ystade@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:39:34 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A9=B9=20Add=20na=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/python/na/register_na_computation.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/python/na/register_na_computation.cpp b/src/python/na/register_na_computation.cpp index 49accdcb15..4a74a651cf 100644 --- a/src/python/na/register_na_computation.cpp +++ b/src/python/na/register_na_computation.cpp @@ -20,4 +20,7 @@ void registerNAComputation(py::module& m) { qc.def("__str__", [](const na::NAComputation& circ) { return circ.toString(); }); } + +PYBIND11_MODULE(na, m, py::mod_gil_not_used()) { registerNAComputation(m); } + } // namespace mqt