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ΒΆ

expandListPorts(port)

Expand the .list file entry into a list of port strings.

parseList(…)

Parse a list file and expand the list file information into a list of tuples.

parseMatrix(fileName[, preserve_list_order])

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:
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_order is 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 plain 1 so 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 1 and 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.