Skip to content
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

Minor improvement to CircuitDrawer class interface #1640

Merged
merged 105 commits into from
Sep 13, 2021

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Sep 10, 2021

Currently, the qml.circuit_drawer.CircuitDrawer class has a keyword charset that accepts a special class CharSet. Higher-level functions accept charset as a string, either "unicode" or "ascii". graph.draw() has to import the CHARSETS dictionary and convert between a string and a CharSet instance.

Since the CharSet class is an internal implementation detail, I'd like to remove it from API to create a circuit drawer. After this PR. creating a circuit drawer class is simpler, because you can just pass it the relevant string, and the class handles the rest.

This change simply moves relevant circuit drawing code into the circuit drawing classes.

albi3ro and others added 30 commits July 29, 2021 10:28
Co-authored-by: Josh Izaac <josh146@gmail.com>
@albi3ro albi3ro added code quality 🎓 Discussion and improvements to code quality review-ready 👌 PRs which are ready for review by someone from the core team. labels Sep 10, 2021
@albi3ro albi3ro requested review from antalszava and thisac and removed request for antalszava September 13, 2021 09:02
Copy link
Contributor

@thisac thisac left a comment

Choose a reason for hiding this comment

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

Looks good @albi3ro! 💯 Only one minor suggestion for the readability of the error message.

self.charset = charset

if charset is None:
self.charset = CHARSETS["unicode"]()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is CHARSETS["unicode"]() the same as charsets.UnicodeCharSet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An instance of that, yes. Another change in this PR is that we use instances of that class instead of the class itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another change in this PR is that we use instances of that class instead of the class itself.

Could this change have any downsides or raise potential unexpected issues, e.g. when passing it along to the representation resolver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. everything is static methods.

pennylane/circuit_drawer/circuit_drawer.py Outdated Show resolved Hide resolved
tests/circuit_drawer/test_circuit_drawer.py Outdated Show resolved Hide resolved
@albi3ro albi3ro merged commit 2ad582d into master Sep 13, 2021
@albi3ro albi3ro deleted the circuit-drawer-charsets branch September 13, 2021 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality 🎓 Discussion and improvements to code quality review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants