You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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)
The command sequence represents the following sequence:
40
37
41
-
* starting with an input qubit :math:`|\psi_{in}\rangle_0`, we first prepare an ancilla qubit :math:`|+\rangle_1` with ['N', 1] command
42
-
* We then apply CZ-gate by ['E', (0, 1)] command to create entanglement.
43
-
* We measure the qubit 0 in Pauli X basis, by ['M'] command.
38
+
* starting with an input qubit :math:`|\psi_{in}\rangle_0`, we first prepare an ancilla qubit :math:`|+\rangle_1` with N(1) command
39
+
* We then apply CZ-gate by E((0, 1)) command to create entanglement.
40
+
* We measure the qubit 0 in Pauli X basis, by M(0) command.
44
41
* If the measurement outcome is :math:`s_0 = 1` (i.e. if the qubit is projected to :math:`|-\rangle`, the Pauli X eigenstate with eigenvalue of :math:`(-1)^{s_0} = -1`), the 'X' command is applied to qubit 1 to 'correct' the measurement byproduct (see :doc:`intro`) that ensure deterministic computation.
45
42
* Tracing out the qubit 0 (since the measurement is destructive), we have :math:`H|\psi_{in}\rangle_1` - the input qubit has teleported to qubit 1, while being transformed by Hadamard gate.
46
43
@@ -86,19 +83,9 @@ As a more complex example than above, we show measurement patterns and graph sta
Notice that all measurements with angle=0 (Pauli X measurements) disappeared - this means that a part of quantum computation was `classically` (and efficiently) preprocessed such that we only need much smaller quantum resource.
@@ -290,18 +212,8 @@ We exploit this fact to minimize the `space` of the pattern, which is crucial fo
290
212
We can simply call :meth:`~graphix.pattern.Pattern.minimize_space()` to reduce the `space`:
291
213
292
214
>>> pattern.minimize_space()
293
-
>>> pattern.print_pattern(lim=20)
294
-
N, node = 3
295
-
E, nodes = (0, 3)
296
-
M, node = 0, plane = XY, angle(pi) = -0.2975038024267561, s-domain = [], t_domain = [], Clifford index = 6
297
-
E, nodes = (1, 3)
298
-
N, node = 7
299
-
E, nodes = (1, 7)
300
-
M, node = 1, plane = XY, angle(pi) = -0.14788446865973076, s-domain = [], t_domain = [], Clifford index = 6
0 commit comments