-
Notifications
You must be signed in to change notification settings - Fork 39
Pretty print #245
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
Conversation
…ng: see tests_patterns, tests_tnsim and tests_transpiler
thierry-martinez
left a comment
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.
There are still some fixes needed, and I made some remarks to clean the code and make it more general.
graphix/pattern.py
Outdated
|
|
||
| output.write(self.to_latex(left_to_right)) | ||
|
|
||
| output.write("\n\\end{document}") |
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.
Beware that \n is an escape form.
| """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.
I don't understand your argument. I think it would be more efficient if you provided a direct code suggestion, assuming you believe it's worthwhile.
Co-authored-by: thierry-martinez <[email protected]>
…presenting pi in the proper format
|
if possible, can we move the implementation of drawing methods out of |
|
@benjvmin93 (CC: @shinich1 ) Additionally, if you're planning to add bunch of features to Are there any updates on |
- Add dedicated pretty-printing functions for patterns. - Improve str() and repr() for circuits, patterns, and core data types (Sign, Axis, Plane, Command, Instruction). This is a focused extract from PR TeamGraphix#245, removing any external dependencies: - Render patterns as ASCII, Unicode, or LaTeX snippets (PDF/image output removed). - Provide evaluable representations for patterns, circuits, and other core types. Per Shinichi’s suggestion (TeamGraphix#245 (comment)), move most code from `pattern.py` into a new module `pretty_print.py`. Per EarlMilktea’s suggestion (TeamGraphix#245 (comment)), add type checking to `pretty_print.py` and its tests (`test_pretty_print.py`).
- Add dedicated pretty-printing functions for patterns. - Improve str() and repr() for circuits, patterns, and core data types (Sign, Axis, Plane, Command, Instruction). This is a focused extract from PR TeamGraphix#245, removing any external dependencies: - Render patterns as ASCII, Unicode, or LaTeX snippets (PDF/image output removed). - Provide evaluable representations for patterns, circuits, and other core types. Per Shinichi’s suggestion (TeamGraphix#245 (comment)), move most code from `pattern.py` into a new module `pretty_print.py`. Per EarlMilktea’s suggestion (TeamGraphix#245 (comment)), add type checking to `pretty_print.py` and its tests (`test_pretty_print.py`).
* Pretty-print circuits and patterns - Add dedicated pretty-printing functions for patterns. - Improve str() and repr() for circuits, patterns, and core data types (Sign, Axis, Plane, Command, Instruction). This is a focused extract from PR #245, removing any external dependencies: - Render patterns as ASCII, Unicode, or LaTeX snippets (PDF/image output removed). - Provide evaluable representations for patterns, circuits, and other core types. Per Shinichi’s suggestion (#245 (comment)), move most code from `pattern.py` into a new module `pretty_print.py`. Per EarlMilktea’s suggestion (#245 (comment)), add type checking to `pretty_print.py` and its tests (`test_pretty_print.py`). * Fix use of `print_pattern` in examples * Add missing import * Update documentation * Update tutorial * Restore deprecated print_pattern and add arguments to converters * Add to CHANGELOG * Use `Iterable` in `Circuit.__init__` Suggested by EarlMilktea: #277 (comment) * Remove useless list collection before calling `join` Suggested by EarlMilktea: #277 (comment) * Use `Iterable` in `Pattern.__init__` and `Pattern.extend` Suggested by EarlMilktea: #277 (comment) * Use `enum.auto` instead of strings Suggested by EarlMilktea: #277 (comment) * Use the simpler `to_ascii` method in examples * Mixin for pretty-printing dataclasses * Mixin for pretty-printing Enum * Check instance of Enum in EnumMixin Suggested by EarlMilktea: #277 (comment) * Use `is not None` with `Iterable | None` EarlMilktea reported that Iterable does not implement __bool__. #277 (comment) * Annotate `self` with `DataclassInstance` Suggested by EarlMilktea: #277 (comment) * Fix ruff * Include `output_nodes` in `repr` * ruff fix with new linters * Fix swap and better code coverage * Use raw f-string Suggested by EarlMilktea: #277 (comment) * Update tutorial with `output_nodes` * Use `is not None` for `target` in `pattern_to_str` Reported by EarlMilktea: #277 (comment) * Add result type for `Circuit.__init__` Suggested by EarlMilktea: #277 (comment) * Rename `DataclassPrettyPrintMixin` and `EnumPrettyPrintMixin` Suggested by EarlMilktea: #277 (comment)
This commit introduces an OpenQASM 3 exporter for Graphix circuits. The functionality was originally proposed in TeamGraphix#245 but has not yet been merged. The added tests verify that a round-trip through the OpenQASM 3 representation preserves Graphix circuits, using the `graphix-qasm3-parser` plugin. These tests are executed by CI when the reverse-dependency is checked. In the long term the `qasm3_exporter` module will also host the pattern exporter, but that feature is intentionally omitted from this PR to keep the change focused.
This commit introduces an OpenQASM 3 exporter for Graphix circuits. The functionality was originally proposed in TeamGraphix#245 but has not yet been merged. The added tests verify that a round-trip through the OpenQASM 3 representation preserves Graphix circuits, using the graphix-qasm3-parser plugin. This plugin is therefore added as a `requirements-dev.txt` dependency. CI is updated so that `pip install .` can detect the current version number of Graphix, instead of the default `0.1`: to do so, the whole history and the tags should be available. We removed the "-e" option from CI because it is useless in the CI context. In the long term the `qasm3_exporter` module will also host the pattern exporter, but that feature is intentionally omitted from this PR to keep the change focused.
|
I think that most of the functionalities introduced in this PR were covered in #277. A missing part was the QASM3 exporter, which is covered with #343. The other parts were the direct export to image files or PDF (through LaTeX compilation), and the drawing of circuits using Qiskit. I think that it is preferable to leave these operations to the user, due to the dependency and maintenance costs. |
This commit introduces an OpenQASM 3 exporter for Graphix circuits. The functionality was originally proposed in TeamGraphix#245 but has not yet been merged. The added tests verify that a round-trip through the OpenQASM 3 representation preserves Graphix circuits, using the graphix-qasm3-parser plugin. This plugin is therefore added as a `requirements-dev.txt` dependency. CI is updated so that `pip install .` can detect the current version number of Graphix, instead of the default `0.1`: to do so, the whole history and the tags should be available. We removed the "-e" option from CI because it is useless in the CI context. In the long term the `qasm3_exporter` module will also host the pattern exporter, but that feature is intentionally omitted from this PR to keep the change focused.
This commit introduces an OpenQASM 3 exporter for Graphix circuits. The functionality was originally proposed in #245 but has not yet been merged. The added tests verify that a round-trip through the OpenQASM 3 representation preserves Graphix circuits, using the graphix-qasm3-parser plugin. This plugin is therefore added as a `requirements-dev.txt` dependency. CI is updated so that `pip install .` can detect the current version number of Graphix, instead of the default `0.1`: to do so, the whole history and the tags should be available. We removed the "-e" option from CI because it is useless in the CI context. In the long term the `qasm3_exporter` module will also host the pattern exporter, but that feature is intentionally omitted from this PR to keep the change focused.
Before submitting, please check the following:
nox)ruffCONTRIBUTING.mdfor more detailsThen, please fill in below:
Context (if applicable):
#239
Description of the change:
New
draw()methods inCircuitandPatternclasses.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)pattern.__repr__()returns the pythonic representation useful to initialize the same object. It involves handling__repr__method for commands. Thus, directly related to the writing of aclass Command.More details on the different changes are described in the
CHANGELOG.mdfile.Related issue: