Skip to content

Commit

Permalink
Wrap qiskit.Aer and qiskit.IBMQ with lazy loading object (Qiskit/qisk…
Browse files Browse the repository at this point in the history
…it#5619)

* Wrap qiskit.Aer and qiskit.IBMQ with lazy loading object

This commit migrates the qiskit.Aer and qiskit.IBMQ module attributes to
be lazy loading instances of lazy loading wrapper classes. The intent
here is to avoid importing from qiskit-aer or qiskit-ibmq-provider from
qiskit-terra, while this is safe while the packages share a shared
namespace we've been actively working to remove the use of namespace
packaging (see Qiskit/qiskit#5089, Qiskit/qiskit#4767, and Qiskit/qiskit#559) and the circular
dependency caused by re-exporting these attributes is blocking progress
on this. By using a lazy loading wrapper class we avoid an import type
circular dependency and opportunistically use qiskit-aer and/or
qiskit-ibmq-provider at runtime only if they're present after everything
is imported. This also may have some benefit for the overall import
performance of qiskit (being tracked in Qiskit/qiskit#5100) as it removes qiskit-aer
and qiskit-ibmq-provider from the import path unless they're being used.
Although the presence of qiskit.__qiskit_version__ might prevent any
performance improvements as it still imports all the elements to get
version information (and will be tackled in a separate PR).

Fixes Qiskit/qiskit#5532

* Fix lint

* Fix test lint

* DNM: test with ignis patch

* Revert "DNM: test with ignis patch"

This reverts commit ac9611c3ace30d101a70bda06e1987df14662182.

* Use ignis from source for tutorial job

* Update release note to be more clear
  • Loading branch information
mtreinish committed Feb 5, 2021
1 parent 6948eea commit 255ec09
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/test_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# pylint: disable=no-name-in-module,import-error

""" Test VQE """

import unittest
Expand Down Expand Up @@ -167,7 +169,7 @@ def test_with_aer_statevector(self):
"""Test VQE with Aer's statevector_simulator."""
try:
# pylint: disable=import-outside-toplevel
from qiskit import Aer
from qiskit.providers.aer import Aer
except Exception as ex: # pylint: disable=broad-except
self.skipTest("Aer doesn't appear to be installed. Error: '{}'".format(str(ex)))
return
Expand All @@ -190,7 +192,7 @@ def test_with_aer_qasm(self):
"""Test VQE with Aer's qasm_simulator."""
try:
# pylint: disable=import-outside-toplevel
from qiskit import Aer
from qiskit.providers.aer import Aer
except Exception as ex: # pylint: disable=broad-except
self.skipTest("Aer doesn't appear to be installed. Error: '{}'".format(str(ex)))
return
Expand All @@ -215,7 +217,7 @@ def test_with_aer_qasm_snapshot_mode(self):
"""Test the VQE using Aer's qasm_simulator snapshot mode."""
try:
# pylint: disable=import-outside-toplevel
from qiskit import Aer
from qiskit.providers.aer import Aer
except Exception as ex: # pylint: disable=broad-except
self.skipTest("Aer doesn't appear to be installed. Error: '{}'".format(str(ex)))
return
Expand Down Expand Up @@ -308,7 +310,7 @@ def test_vqe_expectation_select(self):
"""Test expectation selection with Aer's qasm_simulator."""
try:
# pylint: disable=import-outside-toplevel
from qiskit import Aer
from qiskit.providers.aer import Aer
except Exception as ex: # pylint: disable=broad-except
self.skipTest("Aer doesn't appear to be installed. Error: '{}'".format(str(ex)))
return
Expand Down

0 comments on commit 255ec09

Please sign in to comment.