Skip to content

Conversation

mtreinish
Copy link
Member

Summary

Namespace packages are constant source of problems for users. The python
packaging ecosystem around splitting packages across namespaces is
fragile at the best of times and can often leave a you with an
environment that isn't recoverable (especially when mixing install
methods). There is also a performance hit whenever there is a piece of
the namespace we allow external packages to extend since it requires
doing a full python path search which can be slow depending on the
backing I/O and the number of paths in sys.path for an environment. This
commit addresses the piece from the aer perspective by moving
qiskit.providers.aer to it's own package and namespace 'qiskit_aer'.

This will be coupled with a change in terra that removes the arbitrary
namespace hook points and hard coding the element namespace maps via a
custom import loader at the root of the namespace. This has 2 advantages
it removes the use of namespace packages so the fragility and
performance impact are fixed since every element will be renamed to use
'qiskit_' instead of 'qiskit.', but it also makes it explicit where we
extend the namespace. The previous method allowed any package to extend
qiskit.* and qiskit.providers.* with whatever they wanted. This commit
will need to be coordinated with the terra change to ensure we don't
block development, because while it's not breaking for end users as a
coordinated code release piecewise it's a breaking change for each
element, including Aer.

Details and comments

Depends-On: Qiskit/qiskit#4767
Fixes Qiskit/qiskit#559

@mtreinish mtreinish added the on hold Can not fix yet label Jul 21, 2020
@mtreinish mtreinish removed the on hold Can not fix yet label Aug 31, 2020
@mtreinish
Copy link
Member Author

This is failing unittests because of a weird circular import error. I originally never encountered this locally prior to merging Qiskit/qiskit#4767 but by switching to python setup.py bdist_wheel instead of pip install I have been able to recreate this failure. I have no idea on the source of it as of yet. Since this will likely take me some time to debug I'm setting this as on hold as a revert is proposed at Qiskit/qiskit#5006

@mtreinish mtreinish added the on hold Can not fix yet label Aug 31, 2020


class SnapshotDensityMatrix(Snapshot):
class SnapshotDensityMatrix(snapshot.Snapshot):
Copy link
Member

Choose a reason for hiding this comment

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

Snapshot is used in the code below, which is why the CI is giving an import error.

@mtreinish mtreinish force-pushed the namespace-no-more branch 3 times, most recently from 6aa1064 to 9fae0dd Compare September 18, 2020 22:18
Namespace packages are constant source of problems for users. The python
packaging ecosystem around splitting packages across namespaces is
fragile at the best of times and can often leave a you with an
environment that isn't recoverable (especially when mixing install
methods). There is also a performance hit whenever there is a piece of
the namespace we allow external packages to extend since it requires
doing a full python path search which can be slow depending on the
backing I/O and the number of paths in sys.path for an environment. This
commit addresses the piece from the aer perspective by moving
qiskit.providers.aer to it's own package and namespace 'qiskit_aer'.

This will be coupled with a change in terra that removes the arbitrary
namespace hook points and hard coding the element namespace maps via a
custom import loader at the root of the namespace. This has 2 advantages
it removes the use of namespace packages so the fragility and
performance impact are fixed since every element will be renamed to use
'qiskit_*' instead of 'qiskit.*', but it also makes it explicit where we
extend the namespace. The previous method allowed any package to extend
qiskit.* and qiskit.providers.* with whatever they wanted. This commit
will need to be coordinated with the terra change to ensure we don't
block development, because while it's not breaking for end users as a
coordinated code release piecewise it's a breaking change for each
element, including Aer.

Depends-On: Qiskit/qiskit#4767
Fixes Qiskit/qiskit#559
@mtreinish mtreinish requested a review from vvilpas as a code owner October 8, 2020 15:08
mtreinish and others added 11 commits October 8, 2020 11:12
Fix snapshot imports

Remove imports of Aer in tests

Replace relative imports in parent directors with imports using the full path

Remove `from qiskit` imports
make GHA tutorial test run earlier

Revert this commit when tests are passing
Except for the qutip_extra_lite dir
mtreinish added a commit to mtreinish/qiskit-aer that referenced this pull request May 31, 2022
Namespace packages are constant source of problems for users. The python
packaging ecosystem around splitting packages across namespaces is
fragile at the best of times and can often leave a you with an
environment that isn't recoverable (especially when mixing install
methods). There is also a performance hit whenever there is a piece of
the namespace we allow external packages to extend since it requires
doing a full python path search which can be slow depending on the
backing I/O and the number of paths in sys.path for an environment. This
commit addresses the piece from the aer perspective by moving
qiskit.providers.aer to it's own package and namespace 'qiskit_aer'.

This is coupled with a custom namespace module that implements a
custom import loader at the root of the namespace. This has 2 advantages
it removes the use of namespace packages so the fragility and
performance impact are fixed since every element will be renamed to use
'qiskit_' instead of 'qiskit.' (aer being the only one remaining).

This is the second attempt at doing this namespace rename, the first
failed attempt in Qiskit#840 was trying to migrate all the former qiskit
elements at the same time and was too difficult to migrate everything at
once without causing breaking api changes. This commit is mechanically
the same (renaming qiskit.providers.aer -> qiskit_aer), but how it
integrates with qiskit-terra is changed. With Qiskit/qiskit#5089
qiskit-terra, the
package which owns the 'qiskit.*' namespace, adds a metaimporter that
will redirect imports from qiskit.providers.aer to qiskit_aer. This
means before we can merge this commit Qiskit/qiskit#5089 will need
to be released first to ensure that for backwards compatibility existing
users will be able to access aer from the old namespace.

Fixes Qiskit/qiskit#559
@mtreinish
Copy link
Member Author

Superseded by #1526

@mtreinish mtreinish closed this May 31, 2022
mtreinish added a commit to mtreinish/qiskit-aer that referenced this pull request Jun 14, 2022
Namespace packages are constant source of problems for users. The python
packaging ecosystem around splitting packages across namespaces is
fragile at the best of times and can often leave a you with an
environment that isn't recoverable (especially when mixing install
methods). There is also a performance hit whenever there is a piece of
the namespace we allow external packages to extend since it requires
doing a full python path search which can be slow depending on the
backing I/O and the number of paths in sys.path for an environment. This
commit addresses the piece from the aer perspective by moving
qiskit.providers.aer to it's own package and namespace 'qiskit_aer'.

This is coupled with a custom namespace module that implements a
custom import loader at the root of the namespace. This has 2 advantages
it removes the use of namespace packages so the fragility and
performance impact are fixed since every element will be renamed to use
'qiskit_' instead of 'qiskit.' (aer being the only one remaining).

This is the second attempt at doing this namespace rename, the first
failed attempt in Qiskit#840 was trying to migrate all the former qiskit
elements at the same time and was too difficult to migrate everything at
once without causing breaking api changes. This commit is mechanically
the same (renaming qiskit.providers.aer -> qiskit_aer), but how it
integrates with qiskit-terra is changed. With Qiskit/qiskit#5089
qiskit-terra, the
package which owns the 'qiskit.*' namespace, adds a metaimporter that
will redirect imports from qiskit.providers.aer to qiskit_aer. This
means before we can merge this commit Qiskit/qiskit#5089 will need
to be released first to ensure that for backwards compatibility existing
users will be able to access aer from the old namespace.

Fixes Qiskit/qiskit#559
mtreinish added a commit to mtreinish/qiskit-aer that referenced this pull request Jul 26, 2022
Namespace packages are constant source of problems for users. The python
packaging ecosystem around splitting packages across namespaces is
fragile at the best of times and can often leave a you with an
environment that isn't recoverable (especially when mixing install
methods). There is also a performance hit whenever there is a piece of
the namespace we allow external packages to extend since it requires
doing a full python path search which can be slow depending on the
backing I/O and the number of paths in sys.path for an environment. This
commit addresses the piece from the aer perspective by moving
qiskit.providers.aer to it's own package and namespace 'qiskit_aer'.

This is coupled with a custom namespace module that implements a
custom import loader at the root of the namespace. This has 2 advantages
it removes the use of namespace packages so the fragility and
performance impact are fixed since every element will be renamed to use
'qiskit_' instead of 'qiskit.' (aer being the only one remaining).

This is the second attempt at doing this namespace rename, the first
failed attempt in Qiskit#840 was trying to migrate all the former qiskit
elements at the same time and was too difficult to migrate everything at
once without causing breaking api changes. This commit is mechanically
the same (renaming qiskit.providers.aer -> qiskit_aer), but how it
integrates with qiskit-terra is changed. With Qiskit/qiskit#5089
qiskit-terra, the
package which owns the 'qiskit.*' namespace, adds a metaimporter that
will redirect imports from qiskit.providers.aer to qiskit_aer. This
means before we can merge this commit Qiskit/qiskit#5089 will need
to be released first to ensure that for backwards compatibility existing
users will be able to access aer from the old namespace.

Fixes Qiskit/qiskit#559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold Can not fix yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop using namespace packages
2 participants