-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 circuit drawer for instructions with circuit parameters #9942
Conversation
…arams of type QuantumCircuit
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:
|
Pull Request Test Coverage Report for Build 4748219270
💛 - Coveralls |
if ( | ||
not hasattr(op, "params") | ||
or any(isinstance(param, np.ndarray) for param in op.params) | ||
or any(isinstance(param, QuantumCircuit) for param in op.params) | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine. It would be good to add tests for these 3 cases. Though the code is in utils.py
, the easiest place to test it would probably be in test_circuit_text_drawer
. Also a simple release note indicating that a QuantumCircuit
as a parameter will no longer display in the circuit drawers due to formatting issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much @enavarro51. I wasn't sure if additional tests were needed since this code was a minor change for something I thought was already being tested.
Also, thanks for pointing out where the tests should go. I will look into test_circuit_text_drawer
and add them. Just to double check, are tests only for the text drawer enough? Or do other drawers (like mpl) need them too?
I'll add the reno as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there apparently aren't any tests for these 3 options. The text drawer is sufficient. You're really just checking the call to _get_param_str
returns "". You could do that in test_utils
if you want, but I think it's nice to have a visual output for visualizations.
Merge branch 'main'
Hi @enavarro51. I added a test to check that the drawer does not display parameters when they are of type
Thanks! and sorry for having so many questions. |
Also I think you need to run |
About |
Hi @jakelishman. Sorry, I am bit confused now. Should I implement a test for the @enavarro51, for the |
Oh my bad, I'd misread what Edwin said. Adding a direct test with a name like "test ndarray parameter" absolutely wouldn't hurt - let's just do that. It should already be covered as you say, but at the moment, I think it's just covered coincidentally rather than having a specific unit test for it. |
The |
Merge branch 'main' into fix-drawer-for-instr
@enavarro51, I added the extra tests and the release notes. Please let me know if you would like for me to change/add anything. Thanks so much for your feedback and your help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. Thanks for taking this on.
fixes: | ||
- | | ||
Fixes the circuit drawer from displaying parameters when they are of type `QuantumCircuit` | ||
since this resulted in an illegible drawing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small thing. Release notes should have a blank line at the end. The lint catcher didn't get it, but it might in a docs build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify - it's just a trailing newline that's missing, though if your editor doesn't add them automatically I guess it probably appears as a blank line. I don't think it will cause any failures in the build, but I could be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor tweak to the release note aside, this looks good to me. Thanks for all the work, and thanks Edwin for helping guide this PR to the end as well.
@@ -0,0 +1,4 @@ | |||
fixes: | |||
- | | |||
Fixes the circuit drawer from displaying parameters when they are of type `QuantumCircuit` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the circuit drawer from displaying parameters when they are of type `QuantumCircuit` | |
Fixes the circuit drawer from displaying parameters when they are of type :class:`.QuantumCircuit` |
this makes it a Sphinx cross-reference, so the link will be clickable
fixes: | ||
- | | ||
Fixes the circuit drawer from displaying parameters when they are of type `QuantumCircuit` | ||
since this resulted in an illegible drawing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify - it's just a trailing newline that's missing, though if your editor doesn't add them automatically I guess it probably appears as a blank line. I don't think it will cause any failures in the build, but I could be wrong.
Thanks so much @enavarro51 and @jakelishman, this is good to know. I have made the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
) * fix: modify get_param_str to prevent circuit drawer from displaying params of type QuantumCircuit * fix lint errors * test: add circuit drawer test for instructions with parameters of type QuantumCircuit * test: add circuit drawer tests for no parameters and params of type ndarray * fix lint errors * remove variable to fix lint error * add reno * update releasenotes/notes/fix-circuit-drawer-for-qc-params
Summary
Fixes #9908. For instructions containing circuits as parameters, the circuit drawer includes the gate names (and their corresponding parameters), making the drawing illegible. This PR addresses this issue by adding a conditional statement to ignore adding the parameters to the drawing if they are of type
QuantumCircuit
.Details and comments
Adding this condition also allowed removing the separate
if
statement needed forControlFlowOp
, which had a similar issue.