Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5fdadd0
add pattern draft
masa10-f May 5, 2025
27ba246
simplify ImmutablePattern
masa10-f May 5, 2025
95600d4
remove base class for MutablePattern
masa10-f May 5, 2025
e77031d
fix docstrings
masa10-f May 5, 2025
ddb4841
reduce pattern API
masa10-f May 12, 2025
08a6074
add pattern test
masa10-f May 12, 2025
9b2c9b8
docs for pattern
masa10-f May 12, 2025
5d422ed
remove unnecesary pytest.main()
masa10-f May 12, 2025
db25c6c
fix docstring
masa10-f May 21, 2025
1c62a4a
improve data type in the immutable pattern
masa10-f May 21, 2025
a45bd13
fix wrong use of cached_property
masa10-f May 21, 2025
dccaf54
refactor rule checkers
masa10-f May 23, 2025
a1b8af0
update pattern document
masa10-f May 23, 2025
e148aa8
implement __str__
masa10-f May 23, 2025
38d17ef
improve the code quality
masa10-f May 23, 2025
6fd41f5
remove print_command
masa10-f May 23, 2025
5c0ddca
refactor mutalbepattern
masa10-f May 23, 2025
d3b8d3b
remove MutablePattern
masa10-f May 25, 2025
2d6b003
update check_rulex
masa10-f May 25, 2025
a8e0ddf
simplify pattern data structure
masa10-f May 25, 2025
0efda14
add file argument to print_pattern
masa10-f May 25, 2025
ab5c20d
update docs
masa10-f May 25, 2025
63b338c
use disjoint
masa10-f May 25, 2025
c7b66d4
set cbit default value
masa10-f May 25, 2025
d8b6275
fix logic errors
masa10-f May 25, 2025
22cbc8b
update test
masa10-f May 25, 2025
9855de5
fix docstring
masa10-f May 25, 2025
fe107af
update __str__ of command
masa10-f Jun 2, 2025
64909f1
use None as a default value for cbit
masa10-f Jun 2, 2025
b350a33
make is_runnable to return None
masa10-f Jun 2, 2025
39b4789
generalize cmd_filter
masa10-f Jun 2, 2025
ecce5cf
fix pyright error
masa10-f Jun 2, 2025
ac3b512
add from __future__ import annotations
masa10-f Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/source/pattern.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Pattern
=======

:mod:`graphix_zx.pattern` module
++++++++++++++++++++++++++++++++

.. automodule:: graphix_zx.pattern

Pattern Classes
---------------

.. autoclass:: graphix_zx.pattern.Pattern
:members:
:member-order: bysource

Helper Functions
----------------

.. autofunction:: graphix_zx.pattern.is_runnable

.. autofunction:: graphix_zx.pattern.print_pattern
1 change: 1 addition & 0 deletions docs/source/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Module reference
focus_flow
command
decoder_backend
pattern
51 changes: 41 additions & 10 deletions graphix_zx/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class N:

node: int

def __str__(self) -> str:
return f"N: node={self.node}"


@dataclasses.dataclass
class E:
Expand All @@ -49,6 +52,9 @@ class E:

nodes: tuple[int, int]

def __str__(self) -> str:
return f"E: nodes={self.nodes}"


@dataclasses.dataclass
class M:
Expand All @@ -60,22 +66,30 @@ class M:
The node index to be measured.
meas_basis : MeasBasis
The measurement basis.
s_cbit : `int`
s_cbit : `int` | `None`
The index of s_domain control classical bit.
t_cbit : `int`
Default is None, meaning the flag is always False.
t_cbit : `int` | `None`
The index of t_domain control classical bit.
Default is None, meaning the flag is always False.
"""

node: int
meas_basis: MeasBasis
s_cbit: int
t_cbit: int
s_cbit: int | None = None
t_cbit: int | None = None

def __str__(self) -> str:
return (
f"M: node={self.node}, plane={self.meas_basis.plane}, "
f"angle={self.meas_basis.angle}, s_cbit={self.s_cbit}, t_cbit={self.t_cbit}"
)


@dataclasses.dataclass
class _Correction:
node: int
cbit: int
cbit: int | None = None


@dataclasses.dataclass
Expand All @@ -86,10 +100,14 @@ class X(_Correction):
----------
node : `int`
The node index to apply the correction.
cbit : `int`
cbit : `int` | `None`
The index of the classical bit to control the correction.
If cbit is None, the flag is always False, meaning the correction will not be applied.
"""

def __str__(self) -> str:
return f"X: node={self.node}, cbit={self.cbit}"


@dataclasses.dataclass
class Z(_Correction):
Expand All @@ -99,10 +117,14 @@ class Z(_Correction):
----------
node : `int`
The node index to apply the correction.
cbit : `int`
cbit : `int` | `None`
The index of the classical bit to control the correction.
If cbit is None, the flag is always False, meaning the correction will not be applied.
"""

def __str__(self) -> str:
return f"Z: node={self.node}, cbit={self.cbit}"


@dataclasses.dataclass
class Clifford:
Expand All @@ -119,25 +141,34 @@ class Clifford:
node: int
local_clifford: LocalClifford

def __str__(self) -> str:
return (
f"Clifford: node={self.node}, alpha={self.local_clifford.alpha}, "
f"beta={self.local_clifford.beta}, gamma={self.local_clifford.gamma}"
)


@dataclasses.dataclass
class D:
r"""Decode command.

Attributes
----------
input_cbits : `dict`\[`int`, `bool`\]
A dictionary mapping classical bit indices to their boolean values.
input_cbits : `list`\[`int`\]
A list of classical bit indices that will serve as input to the decoder.
output_cbits : `list`\[`int`\]
A list of classical bit indices that will store the decoding results.
decoder : `BaseDecoder`
The decoder instance used to process the input classical bits and produce the output.
"""

input_cbits: dict[int, bool]
input_cbits: list[int]
output_cbits: list[int]
decoder: BaseDecoder

def __str__(self) -> str:
return f"D: input_cbits={self.input_cbits}, output_cbits={self.output_cbits}, decoder={self.decoder}"


if sys.version_info >= (3, 10):
Command = N | E | M | X | Z | Clifford | D
Expand Down
Loading