Skip to content
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

bug loading MPL style from the configuration #11750

Merged
merged 6 commits into from Feb 15, 2024

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Feb 8, 2024

While testing mthree with rc1, I detected a small typo in qiskit.visualization.circuit.qcstyle.load_style introduced in #11536:

https://github.com/Qiskit-Extensions/mthree/actions/runs/7828157591/job/21357435372?pr=196

TypeError: expected str, bytes or os.PathLike object, not list

locally also is reproducible:

from qiskit import QuantumCircuit

qc = QuantumCircuit(6)
qc.reset(range(6))
qc.h(3)
qc.measure_all()
qc.draw('mpl')

@1ucian0 1ucian0 requested review from nonhermitian and a team as code owners February 8, 2024 10:51
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

@1ucian0 1ucian0 added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Feb 8, 2024
@1ucian0 1ucian0 added this to the 1.0.0 milestone Feb 8, 2024
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This looks right thanks, but can we add a regression test so it doesn't happen again?

@mtreinish mtreinish added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Feb 8, 2024
@coveralls
Copy link

coveralls commented Feb 8, 2024

Pull Request Test Coverage Report for Build 7916495351

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • 175 unchanged lines in 22 files lost coverage.
  • Overall coverage increased (+0.08%) to 89.289%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 91.94%
qiskit/synthesis/clifford/clifford_decompose_ag.py 1 98.72%
qiskit/synthesis/clifford/clifford_decompose_full.py 1 87.5%
qiskit/synthesis/linear/cnot_synth.py 1 98.0%
qiskit/synthesis/clifford/clifford_decompose_greedy.py 2 98.88%
qiskit/synthesis/linear/linear_depth_lnn.py 2 98.33%
qiskit/synthesis/stabilizer/stabilizer_decompose.py 2 96.83%
qiskit/synthesis/unitary/qsd.py 2 97.52%
qiskit/synthesis/clifford/clifford_decompose_bm.py 3 97.83%
qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py 3 96.05%
Totals Coverage Status
Change from base Build 7904240889: 0.08%
Covered Lines: 58901
Relevant Lines: 65967

💛 - Coveralls

@jakelishman
Copy link
Member

that's a pretty questionable decision by GitHub to allow a commit in an entirely separate organisation (let alone repo) to close this PR.

@jakelishman jakelishman reopened this Feb 8, 2024
@1ucian0 1ucian0 changed the title bug when loading MPL style from the configuration was fixed bug loading MPL style from the configuration Feb 8, 2024
@1ucian0
Copy link
Member Author

1ucian0 commented Feb 13, 2024

can we add a regression test so it doesn't happen again?

Added in dddca99

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for this Luciano. The spirit of the test looks good, though I had a minor comment. Let me know if you've not got time to respond and I can just do it if you prefer.

Comment on lines 54 to 61
with patch(
"qiskit.user_config.get_config",
return_value={
"circuit_drawer": "mpl",
"circuit_mpl_style": "quantum-light",
"circuit_mpl_style_path": ["~/.qiskit"],
},
):
Copy link
Member

Choose a reason for hiding this comment

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

This particular form causes the test to generate a warning (we don't forbid UserWarning in CI) unless mthree is installed, which drops the quantum-light.json file into ~/.qiskit.

We maybe want to make the test resilient against that - perhaps use a temporary directory as the style_path that includes a valid style file we can use?

Copy link
Member Author

@1ucian0 1ucian0 Feb 14, 2024

Choose a reason for hiding this comment

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

true. Done in ae5f93c I ended up with a kinda complicated solution. Any ideas how to improve it?

Copy link
Member

Choose a reason for hiding this comment

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

I think what you had was fine in principle - the interface of the circuit drawer is kind of missing a couple of things that would have made it a bit easier to do, so I think everything was always going to look a little messy. I tweaked it over to use TemporaryDirectory instead and to add a test of a failed lookup in 05eb769, but mostly just to expand the coverage more than anything else.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for this Luciano.

I think your test before was generally ok, but I've tweaked the test here to avoid using another internal function (load_style) and needing to do a direct JSON dump, in favour of copying over a known-valid style into a temporary directory and using that. I also expanded the test to test the behaviour if we're searching for a file that doesn't exist.

It's perhaps a bit cleaner to use a TemporaryDirectory directly instead of of a NamedTemporaryFile because it's technically a directory that we actually want to test, and NamedTemporaryFile has a few complications between POSIX and Windows around the rules for re-opening it, and stuff like that.

@jakelishman jakelishman added this pull request to the merge queue Feb 15, 2024
Merged via the queue into Qiskit:main with commit 19c15b7 Feb 15, 2024
12 checks passed
mergify bot pushed a commit that referenced this pull request Feb 15, 2024
* config path fixing

* reno

* add test

* temp file creation

* Avoid using more internal details in style test

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
(cherry picked from commit 19c15b7)
github-merge-queue bot pushed a commit that referenced this pull request Feb 15, 2024
* config path fixing

* reno

* add test

* temp file creation

* Avoid using more internal details in style test

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
(cherry picked from commit 19c15b7)

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants