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

🚸 Add Basic Python Bindings for NAComputation #751

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add an interface target in the src/python/CMakeLists.txt file after including all the subdirectories that links all the bindings targets together.
That would let us use a single string here.
Maybe its also fine to leave this as is, given how this will change with #662 again anyway.


# Only install the Python package component
install.components = ["mqt-core_Python"]
Expand Down
2 changes: 2 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# add the IR bindings package
add_subdirectory(ir)
# add the NA bindings package
add_subdirectory(na)
23 changes: 23 additions & 0 deletions src/python/na/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions src/python/na/register_na_computation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "na/NAComputation.hpp"
#include "python/pybind11.hpp"

namespace mqt {

void registerNAComputation(py::module& m) {

auto qc = py::class_<na::NAComputation>(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(); });
}

PYBIND11_MODULE(na, m, py::mod_gil_not_used()) { registerNAComputation(m); }

} // namespace mqt
Loading