-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add circuit diagrams to source code #7350
Conversation
Pull Request Test Coverage Report for Build 1796262884
💛 - Coveralls |
Not fully sure (I did not check the generated documentation by this PR), but shouldn't they be |
I see your point. You mean the style like this, right? The circuit will keep its format in the generated document. I was following the styles of test_dynamical_decoupling.py and test_instruction_alignments.py. Maybe it is also OK? |
I was thinking about helping people read the source code. So I put some circuit diagrams in the middle of the program, close to the lines of the implementation. Should we consider more for the generated documentation? In that case, I will move more circuits to the docstring. |
I see the problem. The following docstring generates this document, which is not nice. As a comparison, this one produces the right format. I will change the docstrings that will be included in the documentation. However, for those that will not (e.g., test files and functions start with |
Sometimes I'm not sure about the difference with |
Yes, I also noticed that. I searched |
I think is make sense to have all the circuit diagrams as |
I have changed related |
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 is great work! Thanks a lot for taking your time to add all these diagrams.
* Add circuit diagrams to test_hoare_opt.py * Add circuit diagram to equivalence_library.py * Add a TODO in equivalence_library.py * Add circuit diagram to echo_rzx_weyl_decomposition * Add circuit diagram to merge_adjacent_barriers.py * Add circuit diagram to test/python/circuit/library * Add circuit diagram to test/python/circuit * Add circuit diagram to test/python/compiler * Add circuit diagram to test/python/dagcircuit * Add circuit diagram to test/python * Format source code with black * Chang block comment from string to line annotation * Add circuit diagram to standard_gates * Add parsed-literal before circuit diagram * fix a lint problem * Update circuit diagram in test * Fix a lint problem * Add blank lines before and after parsed-literal Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
* Add circuit diagrams to test_hoare_opt.py * Add circuit diagram to equivalence_library.py * Add a TODO in equivalence_library.py * Add circuit diagram to echo_rzx_weyl_decomposition * Add circuit diagram to merge_adjacent_barriers.py * Add circuit diagram to test/python/circuit/library * Add circuit diagram to test/python/circuit * Add circuit diagram to test/python/compiler * Add circuit diagram to test/python/dagcircuit * Add circuit diagram to test/python * Format source code with black * Chang block comment from string to line annotation * Add circuit diagram to standard_gates * Add parsed-literal before circuit diagram * fix a lint problem * Update circuit diagram in test * Fix a lint problem * Add blank lines before and after parsed-literal Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Summary
This PR finishes the task proposed by #7283.
When reading source code that is related to some circuits, it is often useful to be able to see the circuit. This PR adds circuit diagrams to source files that did not provide them.
Details and comments
I use the
QuantumCircuit.draw
function to generate the diagrams and copy them to the source code. Sometimes, I edit the diagram a little to make it more concise.Other than the two files mentioned in the issue, this PR also modifies many other files. Nevertheless, there must be some files that have not been covered by this PR. If you find such a case, please let me know.
If the related function is included in the documentation (i.e., not test functions or internal functions), I will try to put the circuit diagram in the docstring under a
.. parsed-literal::
directive. In this case, the diagram will be included in the generated documentation. For test functions or internal functions, I usually annotate the circuit diagram as line comments (start with#
). It is closer to the corresponding code lines compared with the docstring style, so probably easier to be understood.I did not try to add circuit diagram to the following types of source code:
In these cases, I think the circuit diagram would be too complex that it cannot help the reader to better understand the circuit.
In addition, I think there is no need to add a circuit diagram to
close #7283