Skip to content

Conversation

mtreinish
Copy link
Member

Summary

This commit adds a warning whenever qiskit is imported if it can't
import qiskit-aer or qiskit-ibmq-provider. Right now if a user installs
terra and either does not install aer or the ibmq-provider, or also
equally as likely installs them but python packaging messes up the
namespace and there is no indication that these features are missing
until they go to use qiskit.Aer, or qiskit.IBMQ. To address this
commit adds a warning that will only be displayed once on the first
import of anything from the qiskit namespace in a python process, using
python's stdlib warning mechanism (which is configurable and
suppressible). This will hopefully remove the surprise when users try
to use Aer or IBMQ like in documentation and tutorials and they just
get an empty AttributeError.

Details and comments

Related #2483

This commit adds a warning whenever qiskit is imported if it can't
import qiskit-aer or qiskit-ibmq-provider. Right now if a user installs
terra and either does not install aer or the ibmq-provider, or also
equally as likely installs them but python packaging messes up the
namespace and there is no indication that these features are missing
until they go to use qiskit.Aer, or qiskit.IBMQ. To address this
commit adds a warning that will only be displayed once on the first
import of anything from the qiskit namespace in a python process, using
python's stdlib warning mechanism (which is configurable and
suppressible). This will hopefully remove the surprise when users try
to use Aer or IBMQ like in documentation and tutorials and they just
get an empty AttributeError.

Related Qiskit#2483
@nonhermitian
Copy link
Contributor

These read a bit odd. Perhaps:

Could not import the Aer provider from the qiskit-aer package.
Install qiskit-aer or check your installation.

Could not import the IBMQ account from the qiskit-ibmq-provider package.
Install qiskit-ibmq-provider or check your installation.

@mtreinish mtreinish added this to the 0.9 milestone Aug 8, 2019
@mtreinish mtreinish merged commit 6795f53 into Qiskit:master Aug 13, 2019
@mtreinish mtreinish deleted the warn-on-missing-namespace branch August 13, 2019 20:22
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Aug 13, 2019
Recently we started emitting on failed imports for IBMQ and Aer in Qiskit#2842
to tell users if they have a misconfigured or missing qiskit-aer or
qiskit-ibmq-provider package. However, in that PR we set the warning
class to ImportWarning which is ignored by default in python. This
defeats the whole purpose of emitting the warning because no one will
see it unless they explicit enable printing ImportWarnings to stderr.
ImportWarning was chosen because it seems to map the best to what we're
warning about and provides a unique enough class that is easy to filter
for those users who do not wish to install either Aer or IBMQ. This
commit changes the warning class to RuntimeWarning so that it will show
by default but still meet the criteria that we original chose
ImportWarning based on.
mtreinish added a commit that referenced this pull request Aug 14, 2019
Recently we started emitting on failed imports for IBMQ and Aer in #2842
to tell users if they have a misconfigured or missing qiskit-aer or
qiskit-ibmq-provider package. However, in that PR we set the warning
class to ImportWarning which is ignored by default in python. This
defeats the whole purpose of emitting the warning because no one will
see it unless they explicit enable printing ImportWarnings to stderr.
ImportWarning was chosen because it seems to map the best to what we're
warning about and provides a unique enough class that is easy to filter
for those users who do not wish to install either Aer or IBMQ. This
commit changes the warning class to RuntimeWarning so that it will show
by default but still meet the criteria that we original chose
ImportWarning based on.
mtreinish added a commit to mtreinish/qiskit that referenced this pull request Aug 14, 2019
This commit adds details to the install guide and the install from
source guide on new warnings being emitted by terra in the 0.9 release.
Added in Qiskit/qiskit#2842 when qiskit-aer or
qiskit-ibmq-provider can not be found by terra on initial import it will
emit a warning to inform the user of that state. This is done because
today the user will have no idea if they forgot to install these
components (or more likely python packaging screwed up the installation)
and aer or ibmq can't be found. They will then try to use either
qiskit.Aer or qiskit.IBMQ only to be met by a confusing ImportError.
This is a very common occurrence for users and causes a great deal of
confusion. However, since emitting a warning on import is potentially
undesirable behavior for any users that only use qiskit-terra by
itself. If they never have any intent of importing qiskit.Aer or
qiskit.IBMQ then emitting a warning is fairly annoying. This commit
documents these warnings and more importantly how to suppress them for
these users, so that they do not have to be concerned about seeing the
warnings in perpetuity moving forward if they do not want to.

This updates both the install guide and the contributing guide since
it's conceivable a user would refer to either guide when installing
terra as a standalone component.

At the same time a stale reference to a warning that as of Qiskit#304 merging
no longer will be emitted when installing the qiskit metapackage is
removed from the install documentation.
jaygambetta pushed a commit to Qiskit/qiskit-metapackage that referenced this pull request Aug 14, 2019
This commit adds details to the install guide and the install from
source guide on new warnings being emitted by terra in the 0.9 release.
Added in Qiskit/qiskit#2842 when qiskit-aer or
qiskit-ibmq-provider can not be found by terra on initial import it will
emit a warning to inform the user of that state. This is done because
today the user will have no idea if they forgot to install these
components (or more likely python packaging screwed up the installation)
and aer or ibmq can't be found. They will then try to use either
qiskit.Aer or qiskit.IBMQ only to be met by a confusing ImportError.
This is a very common occurrence for users and causes a great deal of
confusion. However, since emitting a warning on import is potentially
undesirable behavior for any users that only use qiskit-terra by
itself. If they never have any intent of importing qiskit.Aer or
qiskit.IBMQ then emitting a warning is fairly annoying. This commit
documents these warnings and more importantly how to suppress them for
these users, so that they do not have to be concerned about seeing the
warnings in perpetuity moving forward if they do not want to.

This updates both the install guide and the contributing guide since
it's conceivable a user would refer to either guide when installing
terra as a standalone component.

At the same time a stale reference to a warning that as of #304 merging
no longer will be emitted when installing the qiskit metapackage is
removed from the install documentation.
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* Add warning on Aer and IBMQ ImportError

This commit adds a warning whenever qiskit is imported if it can't
import qiskit-aer or qiskit-ibmq-provider. Right now if a user installs
terra and either does not install aer or the ibmq-provider, or also
equally as likely installs them but python packaging messes up the
namespace and there is no indication that these features are missing
until they go to use qiskit.Aer, or qiskit.IBMQ. To address this
commit adds a warning that will only be displayed once on the first
import of anything from the qiskit namespace in a python process, using
python's stdlib warning mechanism (which is configurable and
suppressible). This will hopefully remove the surprise when users try
to use Aer or IBMQ like in documentation and tutorials and they just
get an empty AttributeError.

Related Qiskit#2483

* Update warning message

* Fix review comments and change warning class
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
Recently we started emitting on failed imports for IBMQ and Aer in Qiskit#2842
to tell users if they have a misconfigured or missing qiskit-aer or
qiskit-ibmq-provider package. However, in that PR we set the warning
class to ImportWarning which is ignored by default in python. This
defeats the whole purpose of emitting the warning because no one will
see it unless they explicit enable printing ImportWarnings to stderr.
ImportWarning was chosen because it seems to map the best to what we're
warning about and provides a unique enough class that is easy to filter
for those users who do not wish to install either Aer or IBMQ. This
commit changes the warning class to RuntimeWarning so that it will show
by default but still meet the criteria that we original chose
ImportWarning based on.
jakelishman pushed a commit to jakelishman/qiskit-terra that referenced this pull request Aug 11, 2023
…-metapackage#404)

This commit adds details to the install guide and the install from
source guide on new warnings being emitted by terra in the 0.9 release.
Added in Qiskit#2842 when qiskit-aer or
qiskit-ibmq-provider can not be found by terra on initial import it will
emit a warning to inform the user of that state. This is done because
today the user will have no idea if they forgot to install these
components (or more likely python packaging screwed up the installation)
and aer or ibmq can't be found. They will then try to use either
qiskit.Aer or qiskit.IBMQ only to be met by a confusing ImportError.
This is a very common occurrence for users and causes a great deal of
confusion. However, since emitting a warning on import is potentially
undesirable behavior for any users that only use qiskit-terra by
itself. If they never have any intent of importing qiskit.Aer or
qiskit.IBMQ then emitting a warning is fairly annoying. This commit
documents these warnings and more importantly how to suppress them for
these users, so that they do not have to be concerned about seeing the
warnings in perpetuity moving forward if they do not want to.

This updates both the install guide and the contributing guide since
it's conceivable a user would refer to either guide when installing
terra as a standalone component.

At the same time a stale reference to a warning that as of Qiskit/qiskit-metapackage#304 merging
no longer will be emitted when installing the qiskit metapackage is
removed from the install documentation.
SameerD-phys pushed a commit to SameerD-phys/qiskit-terra that referenced this pull request Sep 7, 2023
…-metapackage#404)

This commit adds details to the install guide and the install from
source guide on new warnings being emitted by terra in the 0.9 release.
Added in Qiskit#2842 when qiskit-aer or
qiskit-ibmq-provider can not be found by terra on initial import it will
emit a warning to inform the user of that state. This is done because
today the user will have no idea if they forgot to install these
components (or more likely python packaging screwed up the installation)
and aer or ibmq can't be found. They will then try to use either
qiskit.Aer or qiskit.IBMQ only to be met by a confusing ImportError.
This is a very common occurrence for users and causes a great deal of
confusion. However, since emitting a warning on import is potentially
undesirable behavior for any users that only use qiskit-terra by
itself. If they never have any intent of importing qiskit.Aer or
qiskit.IBMQ then emitting a warning is fairly annoying. This commit
documents these warnings and more importantly how to suppress them for
these users, so that they do not have to be concerned about seeing the
warnings in perpetuity moving forward if they do not want to.

This updates both the install guide and the contributing guide since
it's conceivable a user would refer to either guide when installing
terra as a standalone component.

At the same time a stale reference to a warning that as of Qiskit/qiskit-metapackage#304 merging
no longer will be emitted when installing the qiskit metapackage is
removed from the install documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants