Reorganize quantum_info crate to clearly separate Python interface code#16582
Open
mtreinish wants to merge 2 commits into
Open
Reorganize quantum_info crate to clearly separate Python interface code#16582mtreinish wants to merge 2 commits into
mtreinish wants to merge 2 commits into
Conversation
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.
Collaborator
|
One or more of the following people are relevant to this code:
|
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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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::pythonto 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