-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 a lazy loading wrapper class for __qiskit_version__ #5620
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8d2730a
Add a lazy loading wrapper class for __qiskit_version__
mtreinish f8f6aaf
Rename qiskit.execute module to qiskit.execute_function
mtreinish 86512b1
Rename qiskit.compiler inner modules to avoid name conflict
mtreinish 6d8647f
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish ddf4cc4
Fix docs build
mtreinish 7d42e27
Merge branch 'lazy-wrap-qiskit-version' of github.com:mtreinish/qiski…
mtreinish fa2dbd3
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish 7da924a
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish acd74b3
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish 6754d32
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish 9c2b985
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish 4531ba8
Apply suggestions from code review
mtreinish e730c13
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish 04762b6
Merge branch 'master' into lazy-wrap-qiskit-version
mtreinish 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.. _qiskit-execute: | ||
|
||
.. automodule:: qiskit.execute | ||
.. automodule:: qiskit.execute_function | ||
:no-members: | ||
:no-inherited-members: | ||
:no-special-members: |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
45 changes: 45 additions & 0 deletions
45
releasenotes/notes/qiskit-version-wrapper-90cb7fcffeaafd6a.yaml
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,45 @@ | ||
--- | ||
upgrade: | ||
- | | ||
The ``qiskit.__qiskit_version__`` module attribute was previously a ``dict`` | ||
will now return a custom read-only ``Mapping`` object that checks the | ||
version of qiskit elements at runtime instead of at import time. This was | ||
done to speed up the import path of qiskit and eliminate a possible import | ||
cycle by only importing the element packages at runtime if the version | ||
is needed from the package. This should be fully compatible with the | ||
``dict`` previously return and for most normal use cases there will be no | ||
difference. However, if some applications were relying on either mutating | ||
the contents or explicitly type checking it may require updates to adapt to | ||
this change. | ||
- | | ||
The ``qiskit.execute`` module has been renamed to | ||
:mod:`qiskit.execute_function`. This was necessary to avoid a potentical | ||
name conflict between the :func:`~qiskit.execute_function.execute` function | ||
which is re-exported as ``qiskit.execute``. ``qiskit.execute`` the function | ||
in some situations could conflict with ``qiskit.execute`` the module which | ||
would lead to a cryptic error because Python was treating ``qiskit.execute`` | ||
as the module when the intent was to the function or vice versa. The module | ||
rename was necessary to avoid this conflict. If you're importing | ||
``qiskit.execute`` to get the module (typical usage was | ||
``from qiskit.execute import execute``) you will need to update this to | ||
use ``qiskit.execute_function`` instead. ``qiskit.execute`` will now always | ||
resolve to the function. | ||
- | | ||
The ``qiskit.compiler.transpile``, ``qiskit.compiler.assemble``, | ||
``qiskit.compiler.schedule``, and ``qiskit.compiler.sequence`` modules have | ||
been renamed to ``qiskit.compiler.transpiler``, | ||
``qiskit.compiler.assembler``, ``qiskit.compiler.scheduler``, and | ||
``qiskit.compiler.sequence`` respectively. This was necessary to avoid a | ||
potentical name conflict between the modules and the re-exported function | ||
paths :func:`qiskit.compiler.transpile`, :func:`qiskit.compiler.assemble`, | ||
:func:`qiskit.compiler.schedule`, and :func:`qiskit.compiler.sequence`. | ||
In some situations this name conflict between the module path and | ||
re-exported function path would lead to a cryptic error because Python was | ||
treating an import as the module when the intent was to use the function or | ||
vice versa. The module rename was necessary to avoid this conflict. If | ||
you were using the imports to get the modules before (typical usage would | ||
be like``from qiskit.compiler.transpile import transpile``) you will need | ||
to update this to use the new module paths. | ||
:func:`qiskit.compiler.transpile`, :func:`qiskit.compiler.assemble`, | ||
:func:`qiskit.compiler.schedule`, and :func:`qiskit.compiler.sequence` | ||
will now always resolve to the functions. |
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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021 | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Tests for qiskit/version.py""" | ||
|
||
from qiskit import __qiskit_version__ | ||
from qiskit import __version__ | ||
from qiskit.test import QiskitTestCase | ||
|
||
|
||
class TestVersion(QiskitTestCase): | ||
"""Tests for qiskit/version.py""" | ||
|
||
def test_qiskit_version(self): | ||
"""Test qiskit-version sets the correct version for terra.""" | ||
self.assertEqual(__version__, __qiskit_version__['qiskit-terra']) |
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.
Should the
get_version_info()
call that populates__version__
also be moved to runtime (or maybe this needs python 3.7)?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.
Ideally yes it would be good to do this only at runtime, although for the release case (or anything outside of the dev case) this only adds an extra
stat()
call which is limited overhead. But I think we'll have to wait until python 3.7 with modulegetattr
to do this.We could create a custom class with a
__str__
and__repr__
that runsget_version_info()
internally but that would cause issues for people who use string methods on version (the use case I'm thinking of isqiskit.__version__.split('.')
so I think it would be best to wait