parse_switchmatrixΒΆ
Parser functions for switch matrix and list file configurations.
This module provides utilities for parsing switch matrix CSV files and list files used in fabric definition. It handles expansion of port definitions, connection mappings, and validation of port configurations.
FunctionsΒΆ
|
Expand the .list file entry into a list of port strings. |
|
Parse a list file and expand the list file information into a list of tuples. |
|
Parse the matrix CSV into a dictionary from destination to source. |
Module ContentsΒΆ
- expandListPorts(port) list[str][source]ΒΆ
Expand the .list file entry into a list of port strings.
- Parameters:
port (str) β The port entry to expand. If it contains β[β, itβs split into multiple entries based on β|β.
- Raises:
ValueError β If the port entry contains β[β or β{β without matching closing bracket β]β/β}β.
- Returns:
The expanded list of port strings.
- parseList(filePath: Path, collect: Literal['pair'] = 'pair') list[tuple[str, str]][source]ΒΆ
- parseList(filePath: Path, collect: Literal['source', 'sink']) dict[str, list[str]]
Parse a list file and expand the list file information into a list of tuples.
- Parameters:
filePath (Path) β The path to the list file to parse.
collect (Literal["pair", "source", "sink"], optional) β Collect value by source, sink or just as (source, sink) pair. Defaults to βpairβ.
- Raises:
FileNotFoundError β The file does not exist.
InvalidListFileDefinition β Invalid format in the list file.
- Returns:
Return either a list of connection pairs or a dictionary of lists which is collected by the specified option, source or sink.
- parseMatrix(fileName, preserve_list_order=False) dict[str, list[str]][source]ΒΆ
Parse the matrix CSV into a dictionary from destination to source.
A non-zero cell denotes a configurable connection. When
preserve_list_orderis set, the cellβs integer encodes the mux input position (higher = earlier, MSB-first) and that order is kept; when unset, every connection is treated as a plain1so the inputs fall back to CSV-column order (legacy behaviour). Both sort by(-value, column).The top-left header cell is a label only (conventionally the tile name) and is not validated: the mux-input columns are
header[1:].- Parameters:
fileName (Path) β Directory of the matrix CSV file.
preserve_list_order (bool, optional) β Keep the cell-encoded mux-input order when True; otherwise treat every connection as
1and use CSV-column order. Defaults to False.
- Raises:
InvalidSwitchMatrixDefinition β A non-integer cell value in a row.
- Returns:
Dictionary from destination to a list of sources.