Skip to content

Check if cregbundle is None to avoid warning statement#15956

Open
amruthpremjith wants to merge 3 commits intoQiskit:mainfrom
amruthpremjith:cregbundle-warn
Open

Check if cregbundle is None to avoid warning statement#15956
amruthpremjith wants to merge 3 commits intoQiskit:mainfrom
amruthpremjith:cregbundle-warn

Conversation

@amruthpremjith
Copy link
Copy Markdown

Summary

fixes #15949

Details and comments

Added check to see if cregbundle is set to None to avoid warning output

Tested by running the same code as the issue and didn't see the warning with the change.

  • Without change
(qiskit-dev) amruthpremjith@Amruths-MacBook-Pro qiskit % python3 test.py
/Users/amruthpremjith/qiskit/fork/qiskit/qiskit/visualization/circuit/circuit_visualization.py:301: RuntimeWarning: Cregbundle set to False since an instruction needs to refer to individual classical wire
  if check_clbit_in_inst(block, cregbundle) is False:
  • With change
(qiskit-dev) amruthpremjith@Amruths-MacBook-Pro qiskit % python3 test.py
(qiskit-dev) amruthpremjith@Amruths-MacBook-Pro qiskit % 

@amruthpremjith amruthpremjith requested a review from a team as a code owner April 7, 2026 14:48
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Apr 7, 2026
@qiskit-bot
Copy link
Copy Markdown
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 following people are relevant to this code:

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 7, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
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.

Can you add a bugfix release note, and a test that this works? For testing: you can add a small case in test/python/visualization/test_circuit_text_drawer.py that triggers the spurious warning without your change. For the test, you can use the warnings.catch_warnings context manager, and assert that there aren't any warnings emitted by that code block (for example) - the test should fail without your code change and pass with it.

@jakelishman jakelishman added Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. mod: visualization qiskit.visualization stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. labels Apr 7, 2026
@amruthpremjith
Copy link
Copy Markdown
Author

amruthpremjith commented Apr 7, 2026

I used the same circuit as in the original issue but used a "text" output instead cause the "mpl" one needs matplotlib and latex dependencies to run the test cases.

Test run without changes

python3 -m stestr run --no-discover test.python.visualization.test_circuit_text_drawer.TestCircuitAnnotatedOperations.test_warning_for_none_cregbundle
{0} test.python.visualization.test_circuit_text_drawer.TestCircuitAnnotatedOperations.test_warning_for_none_cregbundle [0.005022s] ... FAILED

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/Users/amruthpremjith/qiskit/fork/qiskit/test/python/visualization/test_circuit_text_drawer.py", line 4775, in test_warning_for_none_cregbundle
    self.assertEqual(w, [])

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 1091, in assertListEqual
    self.assertSequenceEqual(list1, list2, msg, seq_type=list)

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 1073, in assertSequenceEqual
    self.fail(msg)

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 715, in fail
    raise self.failureException(msg)

    AssertionError: Lists differ: [<warnings.WarningMessage object at 0x107313920>] != []

First list contains 1 additional elements.
First extra element 0:
<warnings.WarningMessage object at 0x107313920>

- [<warnings.WarningMessage object at 0x107313920>]
+ []


==============================
Failed 1 tests - output below:
==============================

test.python.visualization.test_circuit_text_drawer.TestCircuitAnnotatedOperations.test_warning_for_none_cregbundle
------------------------------------------------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/Users/amruthpremjith/qiskit/fork/qiskit/test/python/visualization/test_circuit_text_drawer.py", line 4775, in test_warning_for_none_cregbundle
    self.assertEqual(w, [])

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 1091, in assertListEqual
    self.assertSequenceEqual(list1, list2, msg, seq_type=list)

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 1073, in assertSequenceEqual
    self.fail(msg)

      File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 715, in fail
    raise self.failureException(msg)

    AssertionError: Lists differ: [<warnings.WarningMessage object at 0x107313920>] != []

First list contains 1 additional elements.
First extra element 0:
<warnings.WarningMessage object at 0x107313920>

- [<warnings.WarningMessage object at 0x107313920>]
+ []



======
Totals
======
Ran: 1 tests in 0.0050 sec.
 - Passed: 0
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 1
Sum of execute time for each test: 0.0050 sec.

==============
Worker Balance
==============
 - Worker 0 (1 tests) => 0:00:00.005022

No tests were successful during the run

Test with changes

python3 -m stestr run --no-discover test.python.visualization.test_circuit_text_drawer.TestCircuitAnnotatedOperations.test_warning_for_none_cregbundle
{0} test.python.visualization.test_circuit_text_drawer.TestCircuitAnnotatedOperations.test_warning_for_none_cregbundle [0.003843s] ... ok

======
Totals
======
Ran: 1 tests in 0.0038 sec.
 - Passed: 1
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 0
Sum of execute time for each test: 0.0038 sec.

==============
Worker Balance
==============
 - Worker 0 (1 tests) => 0:00:00.003843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: visualization qiskit.visualization stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

RuntimeWarning "Cregbundle set to False" fires when user never set cregbundle

4 participants