-
Notifications
You must be signed in to change notification settings - Fork 31
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.