Skip to content

stabrank

Stabilizer rank decomposition for non-Clifford ZX graphs.

find_stab

find_stab(
    graph: BaseGraph, strategy: DecompositionStrategy
) -> list[BaseGraph]

Decompose a ZX-graph into a sum of stabilizer components.

This is the main entry point for stabilizer rank decomposition. It first removes U3 phases, then decomposes T gates via BSS decompositions, producing a sum of scalar graphs.

Parameters:

Name Type Description Default
graph BaseGraph

The ZX graph to decompose.

required
strategy DecompositionStrategy

Decomposition strategy. Must be one of "cat5", "bss", "cutting".

required

Returns:

Type Description
list[BaseGraph]

A list of scalar graphs whose sum equals the original graph.

Source code in src/tsim/compile/stabrank.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def find_stab(graph: BaseGraph, strategy: DecompositionStrategy) -> list[BaseGraph]:
    """Decompose a ZX-graph into a sum of stabilizer components.

    This is the main entry point for stabilizer rank decomposition. It first removes
    U3 phases, then decomposes T gates via BSS decompositions, producing a sum of
    scalar graphs.

    Args:
        graph: The ZX graph to decompose.
        strategy: Decomposition strategy. Must be one of "cat5", "bss", "cutting".

    Returns:
        A list of scalar graphs whose sum equals the original graph.

    """
    zx.full_reduce(graph, paramSafe=True)
    graphs = find_stab_u3([graph], strategy=strategy)
    return find_stab_magic(graphs, strategy=strategy)

find_stab_magic

find_stab_magic(
    graphs: Iterable[BaseGraph],
    strategy: DecompositionStrategy,
) -> list[BaseGraph]

Recursively decompose ZX-graphs into stabilizer components via magic-state removal.

Source code in src/tsim/compile/stabrank.py
31
32
33
34
35
36
37
38
39
40
41
def find_stab_magic(
    graphs: Iterable[BaseGraph], strategy: DecompositionStrategy
) -> list[BaseGraph]:
    """Recursively decompose ZX-graphs into stabilizer components via magic-state removal."""
    return _decompose(
        list(graphs),
        count_fn=zx.simplify.tcount,
        replace_fn=lambda g: zx.simulate.replace_magic_states(
            g, pick_random=False, strategy=strategy
        ),
    )

find_stab_u3

find_stab_u3(
    graphs: Iterable[BaseGraph],
    strategy: DecompositionStrategy,
) -> list[BaseGraph]

Recursively decompose ZX-graphs by removing U3 phases.

Source code in src/tsim/compile/stabrank.py
44
45
46
47
48
49
50
51
52
def find_stab_u3(
    graphs: Iterable[BaseGraph], strategy: DecompositionStrategy
) -> list[BaseGraph]:
    """Recursively decompose ZX-graphs by removing U3 phases."""
    return _decompose(
        list(graphs),
        count_fn=zx.simplify.u3_count,
        replace_fn=lambda g: zx.simulate.replace_u3_states(g, strategy=strategy),
    )