-
Notifications
You must be signed in to change notification settings - Fork 21
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
Pretty print #245
base: master
Are you sure you want to change the base?
Pretty print #245
Conversation
…ng: see tests_patterns, tests_tnsim and tests_transpiler
One last thing that prevents the checks to be successful is the adding of qiskit module for drawing circuit. I didn't want to change anything regarding this, since my work didn't involve anything in the runner tests so maybe we should discuss how to correct this issue to make sure we agree on what to do. Maybe either by replacing this method with the new appropriate one (in the |
@benjvmin93 was qiskit added to required module in this PR? I agree updating tests to be compatible with latest qiskit would be good. |
@@ -20,6 +20,62 @@ | |||
Node = int | |||
|
|||
|
|||
def command_to_latex(cmd: Command) -> str: |
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.
Maybe better to be implemented as methods?
import PIL | ||
|
||
try: | ||
subprocess.run( |
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.
Let's setup ruff rule S to check insecure operations.
"""Return a string representation of the Circuit.""" | ||
return self.draw() | ||
|
||
def draw(self, output: str = "text") -> TextDrawing | matplotlib.figure | PIL.Image | str: |
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.
Let's use @typing.overload
for better UX.
@@ -6,7 +7,9 @@ networkx>3.0 | |||
numpy>=1.24,<2 | |||
opt_einsum>=3.2 | |||
pydantic | |||
pylatexenc |
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.
Please make this optional since all users need to set up LaTeX if pylatexenc is listed here.
quimb>=1.4.0 | ||
scipy | ||
sympy>=1.9 | ||
typing_extensions | ||
qiskit_qasm3_import |
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.
Same as above (import only when necessary)
@@ -668,3 +669,22 @@ def test_remove_qubit(self) -> None: | |||
|
|||
def assert_equal_edge(edge: Sequence[int], ref: Sequence[int]) -> bool: | |||
return any(all(ei == ri for ei, ri in zip(edge, other)) for other in (ref, reversed(ref))) | |||
|
|||
|
|||
def test_draw_pattern(): |
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.
def test_draw_pattern(): | |
def test_draw_pattern() -> None: |
|
||
|
||
@pytest.mark.skipif(which("latex") is None, reason="latex not installed") | ||
def test_draw_pattern_latex(): |
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.
def test_draw_pattern_latex(): | |
def test_draw_pattern_latex() -> None: |
MEMO: It may better to make big packages optional (ex. qiskit, matplotlib, etc.) for better usability. |
Before submitting, please check the following:
nox
)ruff
CONTRIBUTING.md
for more detailsThen, please fill in below:
Context (if applicable):
#239
Description of the change:
New
draw()
methods inCircuit
andPattern
classes.Circuit.draw()
generates the corresponding Qasm3 code and pass it toqiskit.draw()
method. It relates on the same arguments (seeqiskit.draw()
method documentation).pattern.draw()
locally generates the appropriate visualization object (in the ascii, unicode, png, or latex formats)More details on the different changes are described in the
CHANGELOG.md
file.Related issue: