Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Qiskit Ignis fails if optional matplotlib not installed #532

Closed
drewrisinger opened this issue Nov 4, 2020 · 3 comments · Fixed by #533
Closed

Qiskit Ignis fails if optional matplotlib not installed #532

drewrisinger opened this issue Nov 4, 2020 · 3 comments · Fixed by #533
Labels
bug Something isn't working

Comments

@drewrisinger
Copy link
Contributor

Informations

  • Qiskit Ignis version: master (& v0.5.0)
  • Python version: All
  • Operating system: All

What is the current behavior?

Running/importing base_meas_mitigation.py fails without matplotlib installed.

Steps to reproduce the problem

Problem source:
https://github.com/Qiskit/qiskit-ignis/blob/c572b34c41a90011cad52e19e09d3a0e446608fe/qiskit/ignis/mitigation/expval/base_meas_mitigator.py#L22-L26

Error lines:
https://github.com/Qiskit/qiskit-ignis/blob/c572b34c41a90011cad52e19e09d3a0e446608fe/qiskit/ignis/mitigation/expval/base_meas_mitigator.py#L168-L170
https://github.com/Qiskit/qiskit-ignis/blob/c572b34c41a90011cad52e19e09d3a0e446608fe/qiskit/ignis/mitigation/expval/base_meas_mitigator.py#L197-L199
https://github.com/Qiskit/qiskit-ignis/blob/c572b34c41a90011cad52e19e09d3a0e446608fe/qiskit/ignis/mitigation/expval/base_meas_mitigator.py#L250

Issue is that plt isn't defined if matplotlib isn't installed.

What is the expected behavior?

Ignis should run if matplotlib is not installed in the environment because it is an optional dependency.

Suggested solutions

a. On case of ImportError, set plt = unittest.mock.MagicMock()
b. Have plt.axes references be forward references by changing to "plt.axes" (enclosing in string quotes).

@drewrisinger drewrisinger added the bug Something isn't working label Nov 4, 2020
@mtreinish
Copy link
Collaborator

Ugh, type hints they just cause more trouble than they solve anything. I'll push up a fix removing them there and fix this. Although I'm surprised the minimal dep CI job didn't catch this since it should run all the unit tests without matplotlib.

We're probably going to push out a qiskit-terra 0.16.1 in the next week. I'll plan to include an ignis 0.5.1 at the same time to bundle this in the 0.23.1 metapackage release.

@mtreinish
Copy link
Collaborator

oh, it looks like we lost the minimal deps CI job in the migration to github actions. I'll add that back too

mtreinish added a commit to mtreinish/qiskit-ignis that referenced this issue Nov 4, 2020
In qiskit-community#500 type hints were added for the plotting functions using the
optional matplotlib dependencies. This breaks ignis installations
without matplotlib present since it's an optional dependency. Since type
hints are really just for documentation and not necessary this commit
just removes those problematic hints and uses the docstring to document
the types.

At the same time the testing job verifying ignis works without any
optional dependencies that was lost in the migration from travis to
github actions is restored to verify that everything works moving
forward.

Fixes qiskit-community#532
mtreinish added a commit to mtreinish/qiskit-ignis that referenced this issue Nov 4, 2020
In qiskit-community#500 type hints were added for the plotting functions using the
optional matplotlib dependencies. This breaks ignis installations
without matplotlib present since it's an optional dependency. Since type
hints are really just for documentation and not necessary this commit
just removes those problematic hints and uses the docstring to document
the types.

At the same time the testing job verifying ignis works without any
optional dependencies that was lost in the migration from travis to
github actions is restored to verify that everything works moving
forward.

Fixes qiskit-community#532
@drewrisinger
Copy link
Contributor Author

Thanks @mtreinish for the fix. I assumed it was something like that, but thanks for the quick fix :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants