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

Fix QuantumCircuit.draw() not outputting pdf in latex mode #10212

Merged
merged 3 commits into from
Jun 6, 2023

Conversation

JoshuaLau0220
Copy link
Contributor

Summary

Per the discussion in #10211 I've filed this quick fix.

When calling QuantumCircuit.draw('latex', out.pdf), the program breaking when qiskit tries to move the compiled pdf from the tmp folder to the target directory. The generated pdf is then deleted alongside the tmp folder.

The bug is due to 'os.rename(...)' not working properly across filesystems.
Resorting to shutil.move(...) solved the problem.

Details and comments

I'm afraid there isn't a test I can add for the bug since it is device-dependent.

@JoshuaLau0220 JoshuaLau0220 requested review from a team and nonhermitian as code owners June 6, 2023 12:56
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 6, 2023
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

@CLAassistant
Copy link

CLAassistant commented Jun 6, 2023

CLA assistant check
All committers have signed the CLA.

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! I also can't think of a sensible way to test this - we made the same fix in #8629 and couldn't think of a test there either.

Please could you add a short "bugfix" release note (reno new --edit <some identifier>) that mentions that we've fixed this regression in the LaTeX drawer of QuantumCircuit?

@@ -495,7 +495,8 @@ def _latex_circuit_drawer(
image = trim_image(image)
if filename:
if filename.endswith(".pdf"):
os.rename(base + ".pdf", filename)
import shutil
Copy link
Member

Choose a reason for hiding this comment

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

Super minor: can we put shutil up at the top of the file with the other imports? It's in the standard library, so no need to protect it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I've created the release note and moved shutil to the top.

@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Jun 6, 2023
@coveralls
Copy link

coveralls commented Jun 6, 2023

Pull Request Test Coverage Report for Build 5189877371

  • 1 of 2 (50.0%) changed or added relevant lines in 1 file are covered.
  • 7 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.07%) to 85.92%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/visualization/circuit/circuit_visualization.py 1 2 50.0%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/sabre_swap/mod.rs 1 99.77%
crates/qasm2/src/expr.rs 1 93.76%
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 1 90.39%
crates/qasm2/src/lex.rs 4 90.38%
Totals Coverage Status
Change from base Build 5177933484: 0.07%
Covered Lines: 71354
Relevant Lines: 83047

💛 - Coveralls

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.

Super, thanks!

@jakelishman jakelishman added this to the 0.24.2 milestone Jun 6, 2023
@jakelishman jakelishman added this pull request to the merge queue Jun 6, 2023
Merged via the queue into Qiskit:main with commit 84d13d7 Jun 6, 2023
mergify bot pushed a commit that referenced this pull request Jun 6, 2023
* Fix QuantumCircuit.draw() not outputting pdf in latex mode

* Added bugfix release note; moved import to the top

* Fixup release note

---------

Co-authored-by: Jake Lishman <[email protected]>
(cherry picked from commit 84d13d7)
jakelishman pushed a commit that referenced this pull request Jun 6, 2023
…10217)

* Fix QuantumCircuit.draw() not outputting pdf in latex mode

* Added bugfix release note; moved import to the top

* Fixup release note

---------

Co-authored-by: Jake Lishman <[email protected]>
(cherry picked from commit 84d13d7)

Co-authored-by: Mu-Te Joshua Lau <[email protected]>
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 Community PR PRs from contributors that are not 'members' of the Qiskit repo stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants