Skip to content

Reorganize quantum_info crate to clearly separate Python interface code#16582

Open
mtreinish wants to merge 2 commits into
Qiskit:mainfrom
mtreinish:reorg-python-split-rs-quantum-info
Open

Reorganize quantum_info crate to clearly separate Python interface code#16582
mtreinish wants to merge 2 commits into
Qiskit:mainfrom
mtreinish:reorg-python-split-rs-quantum-info

Conversation

@mtreinish

@mtreinish mtreinish commented Jul 13, 2026

Copy link
Copy Markdown
Member

In #16567 we added support for conditional compilation of the python interface code in quantum info. This made it possible to build the crate in isolation without needing PyO3 or python present. However, the mechanics of how it went about this was fairly brute force, it added a cfg attribute on everything using python in the crate. While this was fine for a first pass it wasn't the best for maintainability because the Python interface code is mixed in with everything else. In an attempt to create a cleaner separation between the Python code and the rest of the crate this commit adds a new top level module quantum_info::python to the crate which contains all the Python interface code. This both keeps a clear separation of concerns for the module and also moves to only needing a single cfg attribute.

This also catches a few places in the dependencies of other crates where the quantum-info crate's python feature was not explicitly listed even though it depended on the feature. While cargo was resolving the feature as part of the circuit crate in most cases, making this explicit makes it easier to work with in the future, especially as we work up the dependency tree on removing default pyo3/python usage.

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

In Qiskit#16567 we added support for conditional compilation of the python
interface code in quantum info. This made it possible to build the crate
in isolation without needing PyO3 or python present. However, the
mechanics of how it went about this was fairly brute force, it added a
cfg attribute on everything using python in the crate. While this was
fine for a first pass it wasn't the best for maintainability because the
Python interface code is mixed in with everything else. In an attempt to
create a cleaner separation between the Python code and the rest of the
crate this commit adds a new top level module `quantum_info::python` to
the crate which contains all the Python interface code. This both keeps
a clear separation of concerns for the module and also moves to only
needing a single cfg attribute.

This also catches a few places in the dependencies of other crates where
the quantum-info crate's python feature was not explicitly listed even
though it depended on the feature. While cargo was resolving the feature
as part of the circuit crate in most cases, making this explicit makes
it easier to work with in the future, especially as we work up the
dependency tree on removing default pyo3/python usage.
@mtreinish
mtreinish requested a review from a team as a code owner July 13, 2026 16:04
@mtreinish
mtreinish requested a review from jakelishman July 13, 2026 16:04
@mtreinish mtreinish added Changelog: None Do not include in the GitHub Release changelog. Rust This PR or issue is related to Rust code in the repository labels Jul 13, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @mtreinish

In the previous commit the `PhasedQubitSparsePauliList::eq` and
`PhasedQubitSparsePauli::eq` methods were accidently removed. This was
caused by a confusion in the implementation where both types derive the
PartialEq trait which defines an eq method based on the fields in the
types. This will be used for the `==` operator and also other places
working with the generic `PartialEq` trait. However, for the python
interface's `__eq__` method the custom eq methods were used. The
overloaded names tripped me up and I accidently removed the inner eq
method overzealously. In a follow up PR we should either move the custom
eq to a custom `PartialEq` implementation or rename the overloaded `eq`
method used for python equality. But for right now this just restores
the previous state to keep this PR just a straight code reorganization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: None Do not include in the GitHub Release changelog. Rust This PR or issue is related to Rust code in the repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants