Skip to content

Fixes crash when printing circuit with controlled MatrixGate #7293

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

Merged
merged 2 commits into from
Apr 23, 2025

Conversation

RevanthGundala
Copy link
Contributor

Description

Fixes #7243
This PR corrects the way Cirq prints a controlled 1×1 MatrixGate in ASCII/Unicode circuit diagrams and tidies up the underlying protocol behavior. Previously, attempting to draw a 1×1 controlled gate raised a TypeError. Now it will render correctly, and a unit test has been created to verify the output.

Changes:

matrix_gates.py
Early‑return NotImplemented for zero‑qubit MatrixGate, deferring to the fallback renderer.

circuit_diagram_info_protocol_test.py
Updated test_controlled_1x1_matrixgate_diagram_error to assert the exact rendered string:
0: ───C[[0.+1.j]]───

Testing:

Ran pytest cirq/protocols/circuit_diagram_info_protocol_test.py — all relevant tests pass.

@RevanthGundala RevanthGundala requested review from vtomole and a team as code owners April 21, 2025 22:50
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.67%. Comparing base (5112418) to head (8e178a0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7293   +/-   ##
=======================================
  Coverage   98.66%   98.67%           
=======================================
  Files        1106     1106           
  Lines       96086    96093    +7     
=======================================
+ Hits        94808    94815    +7     
  Misses       1278     1278           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link
Collaborator

@daxfohl daxfohl left a comment

Choose a reason for hiding this comment

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

Lgtm cc @mhucka same thing as #6880

Copy link
Contributor

@mhucka mhucka left a comment

Choose a reason for hiding this comment

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

Thank you for doing this. LGTM.

@mhucka mhucka enabled auto-merge April 23, 2025 23:03
@mhucka mhucka added this pull request to the merge queue Apr 23, 2025
Merged via the queue into quantumlib:main with commit 197c83a Apr 23, 2025
39 checks passed
@RevanthGundala RevanthGundala deleted the visual branch April 24, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when printing circuit with controlled MatrixGate
3 participants