Skip to content

🎨🐍 Streamline Python bindings - #982

Merged
burgholzer merged 21 commits into
munich-quantum-toolkit:mainfrom
denialhaag:streamline-python-bindings
Jun 13, 2025
Merged

🎨🐍 Streamline Python bindings#982
burgholzer merged 21 commits into
munich-quantum-toolkit:mainfrom
denialhaag:streamline-python-bindings

Conversation

@denialhaag

@denialhaag denialhaag commented Jun 2, 2025

Copy link
Copy Markdown
Member

Description

This PR aligns the implementation of Python bindings with the implementation introduced in qmap#624. To this end, a helper function add_mqt_core_binding is introduced.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@denialhaag
denialhaag marked this pull request as draft June 2, 2025 14:15
@denialhaag denialhaag changed the title Draft: Streamline Python bindings Streamline Python bindings Jun 2, 2025
@ystade

ystade commented Jun 2, 2025

Copy link
Copy Markdown
Collaborator

@denialhaag I assume that is all still a work in progress. When you have a state where it makes sense to have a look, feel free to request a review from me before you request it from @burgholzer as the restructuring in QMAP was initiated by me in #624. Also, feel free to reach out if you have any questions.

@denialhaag

Copy link
Copy Markdown
Member Author

@ystade, yes, this is very much still work in progress. I'll let you know if I have any questions. Thanks! :)

@codecov

codecov Bot commented Jun 2, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ystade

ystade commented Jun 3, 2025

Copy link
Copy Markdown
Collaborator

@denialhaag I just pushed a commit that may solve the linter issue, let's see what the CI says.

@ystade

ystade commented Jun 3, 2025

Copy link
Copy Markdown
Collaborator

Besides the comments that will be included in the review, I have one comment that I could not put in the review.

@burgholzer added the following file

/*
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
* Copyright (c) 2025 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/
// This file must be the first include for any bindings code.
#pragma once
#include <pybind11/pybind11.h> // IWYU pragma: export
#include <pybind11/stl.h> // IWYU pragma: export
namespace mqt {
namespace py = pybind11;
using namespace py::literals;
} // namespace mqt

This did not exist in MQT QMAP when I restructured the bindings. The state right now feels not quite satisfactory as the source files are now clearly separated into src/ and bindings/ but the header files are still mixed in the include/ directory. I would argue that the only Python header is superfluous and the few lines can be added to every C++ source file defining a Python module. However, @burgholzer had surely some good motivation to create this header, so maybe he can give his thoughts on that issue.

@burgholzer

Copy link
Copy Markdown
Member

Besides the comments that will be included in the review, I have one comment that I could not put in the review.

@burgholzer added the following file

/*
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
* Copyright (c) 2025 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/
// This file must be the first include for any bindings code.
#pragma once
#include <pybind11/pybind11.h> // IWYU pragma: export
#include <pybind11/stl.h> // IWYU pragma: export
namespace mqt {
namespace py = pybind11;
using namespace py::literals;
} // namespace mqt

This did not exist in MQT QMAP when I restructured the bindings. The state right now feels not quite satisfactory as the source files are now clearly separated into src/ and bindings/ but the header files are still mixed in the include/ directory. I would argue that the only Python header is superfluous and the few lines can be added to every C++ source file defining a Python module. However, @burgholzer had surely some good motivation to create this header, so maybe he can give his thoughts on that issue.

The main motivation was that these includes always need to come first in order for the STL bindings to work as expected. The common header makes that fairly easy to enforce.
Given that there is a limited amount of bindings files in this project, I would be fine with eliminating the header and adding the appropriate includes (including a comment stating that these need to come first) to every file that needs them.

@ystade ystade left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @denialhaag for your work on this. This looks already very good and clean. I added very few comments and one reminder within the code. After those comments are resolved, I think this PR is ready to be reviewed again by @burgholzer .

Comment thread .readthedocs.yaml Outdated
Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md Outdated
Comment thread CMakeLists.txt
@ystade

ystade commented Jun 3, 2025

Copy link
Copy Markdown
Collaborator

@denialhaag One more thing, I am quite certain that the last commits did not trigger the full CI, esp. the C++ Linting since only config files were changed. Can you either introduce some dummy change to some C++ file to trigger the entire CI again (the change can be reverted after the CI has finished) or you manually run the CI workflow under Actions/CI/run workflow on this branch? However, this must be done in your forked repository.

In general, since you have the permissions now, I think for the future it is more convenient if you just work directly in this repo without forking it but this is really no big issue.

Comment thread .github/workflows/ci.yml Outdated
@denialhaag

Copy link
Copy Markdown
Member Author

Besides the comments that will be included in the review, I have one comment that I could not put in the review.
@burgholzer added the following file

/*
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
* Copyright (c) 2025 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/
// This file must be the first include for any bindings code.
#pragma once
#include <pybind11/pybind11.h> // IWYU pragma: export
#include <pybind11/stl.h> // IWYU pragma: export
namespace mqt {
namespace py = pybind11;
using namespace py::literals;
} // namespace mqt

This did not exist in MQT QMAP when I restructured the bindings. The state right now feels not quite satisfactory as the source files are now clearly separated into src/ and bindings/ but the header files are still mixed in the include/ directory. I would argue that the only Python header is superfluous and the few lines can be added to every C++ source file defining a Python module. However, @burgholzer had surely some good motivation to create this header, so maybe he can give his thoughts on that issue.

The main motivation was that these includes always need to come first in order for the STL bindings to work as expected. The common header makes that fairly easy to enforce. Given that there is a limited amount of bindings files in this project, I would be fine with eliminating the header and adding the appropriate includes (including a comment stating that these need to come first) to every file that needs them.

I removed pybind11.hpp. Let me know if this is what you had in mind.

@denialhaag denialhaag left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Undo these changes before merging.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
@denialhaag denialhaag self-assigned this Jun 4, 2025
Comment thread .github/workflows/ci.yml Outdated
@burgholzer burgholzer changed the title Streamline Python bindings 🎨🐍 Streamline Python bindings Jun 10, 2025
@burgholzer burgholzer added refactor Anything related to code refactoring code quality Code quality improvements Core Anything related to the Core library and IR c++ Anything related to C++ code python Anything related to Python code labels Jun 10, 2025
@burgholzer burgholzer added this to the MQT Core milestone Jun 10, 2025
Comment thread .github/workflows/ci.yml Outdated

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @denialhaag 👋🏼
Many thanks for your work on this! I just did a fairly quick review of the whole PR to keep moving this forward. Nothing really critical, so this should hopefully be easy to address. Otherwise, this is looking really good already and should be done "soon".

Comment thread .github/workflows/ci.yml
Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md Outdated
Comment thread CMakeLists.txt Outdated
Comment thread bindings/dd/CMakeLists.txt
Comment thread bindings/ir/register_symbolic.cpp Outdated
Comment thread src/CMakeLists.txt
denialhaag and others added 3 commits June 10, 2025 17:17
Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍🏼 Let's get this in now, to not create too many conflicts with other ongoing PRs.
Thanks for your work on this!

@burgholzer burgholzer moved this to In Progress in MQT Core Jun 13, 2025
@burgholzer
burgholzer enabled auto-merge (squash) June 13, 2025 14:50
@burgholzer
burgholzer merged commit 20104fc into munich-quantum-toolkit:main Jun 13, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in MQT Core Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code code quality Code quality improvements Core Anything related to the Core library and IR python Anything related to Python code refactor Anything related to code refactoring

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants