Skip to content

params

Integer parameter IDs for error bits, error-basis bits and output bits.

ParamKind module-attribute

ParamKind = Literal['e', 'f', 'm']

Error bit, error-basis bit or output bit.

ParamLayout dataclass

ParamLayout(num_errors: int)

Integer IDs for Tsim's parameters, fixed by the number of error bits.

Error bit j has ID j, so error IDs are error indices. Above them, error-basis and output bits are interleaved: basis bit j has ID num_errors + 2j and output bit i has ID num_errors + 2i + 1. An ID therefore means the same thing at every pipeline stage, whatever the numbers of basis and output bits; names exist only for drawing.

basis

basis(j: int) -> int

Return the ID of error-basis bit j.

Source code in src/tsim/core/params.py
30
31
32
def basis(self, j: int) -> int:
    """Return the ID of error-basis bit ``j``."""
    return self.num_errors + 2 * j

basis_index

basis_index(param: int) -> int

Return j for the error-basis bit whose ID is param.

Source code in src/tsim/core/params.py
45
46
47
48
49
50
def basis_index(self, param: int) -> int:
    """Return ``j`` for the error-basis bit whose ID is ``param``."""
    kind, j = self.kind(param)
    if kind != "f":
        raise ValueError(f"parameter {param} is not an error-basis bit")
    return j

error

error(j: int) -> int

Return the ID of error bit j.

Source code in src/tsim/core/params.py
26
27
28
def error(self, j: int) -> int:
    """Return the ID of error bit ``j``."""
    return j

kind

kind(param: int) -> tuple[ParamKind, int]

Return the kind of the bit with ID param and its index.

Source code in src/tsim/core/params.py
38
39
40
41
42
43
def kind(self, param: int) -> tuple[ParamKind, int]:
    """Return the kind of the bit with ID ``param`` and its index."""
    if param < self.num_errors:
        return "e", param
    index, is_output = divmod(param - self.num_errors, 2)
    return ("m" if is_output else "f"), index

name

name(param: int) -> str

Return the display name e{j}, f{j} or m{i} of param.

Source code in src/tsim/core/params.py
52
53
54
55
def name(self, param: int) -> str:
    """Return the display name ``e{j}``, ``f{j}`` or ``m{i}`` of ``param``."""
    kind, index = self.kind(param)
    return f"{kind}{index}"

names

names(params: Iterable[int]) -> dict[int, str]

Return the display names of params, by ID.

Source code in src/tsim/core/params.py
57
58
59
def names(self, params: Iterable[int]) -> dict[int, str]:
    """Return the display names of ``params``, by ID."""
    return {p: self.name(p) for p in params}

output

output(i: int) -> int

Return the ID of output bit i.

Source code in src/tsim/core/params.py
34
35
36
def output(self, i: int) -> int:
    """Return the ID of output bit ``i``."""
    return self.num_errors + 2 * i + 1