Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Add new Quantikz rendering modules and enhance existing functions for visualization

Open zlatko-minev opened this issue 7 months ago • 3 comments

Feature(vis): Enhance circuit_to_latex_render and GIF creation

This PR introduces cirq.vis.render_circuit and create_gif_from_ipython_images.

The functionality is showcased and described here: in this Jupyter notebook https://drive.google.com/file/d/1KXQjBmQ9rNUjZHJ6QuGolthLN19_K9yK/view?usp=drivesdk (colab: https://colab.sandbox.google.com/drive/1KXQjBmQ9rNUjZHJ6QuGolthLN19_K9yK)

Notes on render_circuit: * Performs upfront checks for pdflatex and pdftoppm executables. Issues informative warnings and disables relevant functionality if they are not found, preventing unexpected failures. * If pdflatex fails and an output_tex_path is specified, the problematic .tex file is copied to the specified path for easier user inspection.

Example outputs: image

image

image

image

image

zlatko-minev avatar May 17 '25 06:05 zlatko-minev

Ideally, we should have some tests, at least for 'circuit_to_latex_quantikz.py'

dstrain115 avatar May 17 '25 14:05 dstrain115

I think i resolved all comments as you suggested and added a test file.

  • All the tests run and pass on my end.
  • ps. I don't think i fixed all the lint issues image

zlatko-minev avatar May 17 '25 17:05 zlatko-minev

Anyone to help clean up and merge in?

zlatko-minev avatar May 28 '25 04:05 zlatko-minev

Pushed some changes here that fix all the CI errors and also fixes (1) and (2) from Eliott's comments.

dstrain115 avatar Aug 01 '25 14:08 dstrain115

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 99.37%. Comparing base (63cfe53) to head (53a9a75). :warning: Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7354    +/-   ##
========================================
  Coverage   99.37%   99.37%            
========================================
  Files        1082     1087     +5     
  Lines       96691    97205   +514     
========================================
+ Hits        96086    96598   +512     
- Misses        605      607     +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Aug 01 '25 18:08 codecov[bot]

@eliottrosenberg I don't think you can do the over/under brace in quantikz as far as I can tell.

I added classical control. The control dots look a little goofy, but it works now. There's better support for classical controls in the 2023 version of quantikz but it looks like colab currently has the 2020 version which is a bit more limited.

dstrain115 avatar Aug 04 '25 13:08 dstrain115

Yes, that’s a good point. It’s probably better to update to the latest version. It’s just what was internally deployed I think was the older one. The new version has one or two small syntax updates to the default behavior of meter for instance, and having its content already been in math mode or not. So that might be something to be a bit careful with when switching.Sent from my iPhoneOn Aug 4, 2025, at 6:09 AM, Doug Strain @.***> wrote:dstrain115 left a comment (quantumlib/Cirq#7354) @eliottrosenberg I don't think you can do the over/under brace in quantikz as far as I can tell. I added classical control. The control dots look a little goofy, but it works now. There's better support for classical controls in the 2023 version of quantikz but it looks like colab currently has the 2020 version which is a bit more limited.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

zlatko-minev avatar Aug 04 '25 13:08 zlatko-minev

Yes, that’s a good point. It’s probably better to update to the latest version. It’s just what was internally deployed I think was the older one. The new version has one or two small syntax updates to the default behavior of meter for instance, and having its content already been in math mode or not. So that might be something to be a bit careful with when switching.

@zlatko-minev Thank you for your work. It's not clear from your last comments whether you are planning to do something more with this PR. Could you let us know if we should wait further?

@dstrain115 I can't tell for certain from your last comment above whether anything needs to be done with respect to Colab compatibility. I sounds like the answer is "no", but it seemed better to double-check with you.

mhucka avatar Aug 10 '25 19:08 mhucka

@mhucka No, the PR as it stands is compatible with colab. It's just that for controlled gates the dot looks a little funny due to the old specification. However, controlled gates weren't even supported in the original PR so I think this is fine.

dstrain115 avatar Aug 13 '25 17:08 dstrain115

@mhucka No, the PR as it stands is compatible with colab. It's just that for controlled gates the dot looks a little funny due to the old specification. However, controlled gates weren't even supported in the original PR so I think this is fine.

Got it. Thanks.

@zlatko-minev It's not clear from your last comments whether you are planning to do something more with this PR. Could you let us know if we should wait further?

mhucka avatar Aug 14 '25 19:08 mhucka

Happy to merge it!

Message ID: @.***>

zlatko-minev avatar Aug 14 '25 22:08 zlatko-minev

@mhucka @pavoljuhas Could we get a review/approval for this? It has been sitting here for a long time.

dstrain115 avatar Aug 23 '25 14:08 dstrain115

+1, thank you

From: Doug Strain @.> Date: Saturday, August 23, 2025 at 7:24 AM To: quantumlib/Cirq @.> Cc: Zlatko Minev @.>, Mention @.> Subject: Re: [quantumlib/Cirq] Add new Quantikz rendering modules and enhance existing functions for visualization (PR #7354)

[https://avatars.githubusercontent.com/u/22484728?s=20&v=4]dstrain115 left a comment (quantumlib/Cirq#7354)https://github.com/quantumlib/Cirq/pull/7354#issuecomment-3217044494

@mhuckahttps://github.com/mhucka @pavoljuhashttps://github.com/pavoljuhas Could we get a review/approval for this? It has been sitting here for a long time.

— Reply to this email directly, view it on GitHubhttps://github.com/quantumlib/Cirq/pull/7354#issuecomment-3217044494, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZS5ZWA45WVB6S2PZ37DBL3PB2SVAVCNFSM6AAAAAB5KHMRPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEMJXGA2DINBZGQ. You are receiving this because you were mentioned.

zlatko-minev avatar Aug 24 '25 00:08 zlatko-minev

@zlatko-minev I was holding off approving it because there are comments by @dstrain115 in the review that have not been addressed:

  • https://github.com/quantumlib/Cirq/pull/7354/files#r2094138349
  • https://github.com/quantumlib/Cirq/pull/7354/files#r2094139042

mhucka avatar Aug 24 '25 01:08 mhucka

Thanks, Mike. For some reason, the links don't point me to the comments you're pointing to. But I don't think there are any essential comments left. There were some possible enhancements that could be left for the future about more specific cases. For now we can I think he better as is with the current version of quantikz

zlatko-minev avatar Sep 01 '25 17:09 zlatko-minev

Hi Mike, thanks for finding these. It would be great if someone from the cirq team has the time at the moment to push these small edits over.

zlatko-minev avatar Sep 03 '25 19:09 zlatko-minev

@zlatko-minev Just to follow up on the status (although you may have inferred it from the activity on this PR): Pavol is actively working on getting the code into shape for incorporation into Cirq.

mhucka avatar Sep 23 '25 17:09 mhucka

Glad to hear, thank you, @mhucka and @pavoljuhas

zlatko-minev avatar Sep 23 '25 17:09 zlatko-minev

@zlatko-minev - can you please give this a quick look if this is OK to merge from your side?

pavoljuhas avatar Sep 25 '25 21:09 pavoljuhas