sax.netlist module#

SAX netlist parsing and utilities

class NetlistDict[source]#

Bases: TypedDict

instances: dict#
connections: dict[str, str]#
ports: dict[str, str]#
settings: dict[str, Any]#
class BaseModel[source]#

Bases: BaseModel

Show JSON schema
{
   "title": "BaseModel",
   "type": "object",
   "properties": {}
}

class Component[source]#

Bases: BaseModel

Show JSON schema
{
   "title": "Component",
   "type": "object",
   "properties": {
      "component": {
         "title": "Component",
         "type": "string"
      },
      "settings": {
         "title": "Settings",
         "type": "object"
      }
   },
   "required": [
      "component"
   ]
}

Fields:
attribute component: ComponentStr [Required]#
Constraints:
  • func = <function _validate_str at 0x7f21b9762980>

attribute settings: dict[str, Any] [Optional]#
class Placement[source]#

Bases: BaseModel

Show JSON schema
{
   "title": "Placement",
   "type": "object",
   "properties": {
      "x": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            }
         ],
         "default": 0.0,
         "title": "X"
      },
      "y": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            }
         ],
         "default": 0.0,
         "title": "Y"
      },
      "dx": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            }
         ],
         "default": 0.0,
         "title": "Dx"
      },
      "dy": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            }
         ],
         "default": 0.0,
         "title": "Dy"
      },
      "rotation": {
         "default": 0.0,
         "title": "Rotation",
         "type": "number"
      },
      "mirror": {
         "default": false,
         "title": "Mirror",
         "type": "boolean"
      },
      "xmin": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Xmin"
      },
      "xmax": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Xmax"
      },
      "ymin": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Ymin"
      },
      "ymax": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "number"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Ymax"
      },
      "port": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "enum": [
                  "ce",
                  "cw",
                  "nc",
                  "ne",
                  "nw",
                  "sc",
                  "se",
                  "sw",
                  "cc",
                  "center"
               ],
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Port"
      }
   }
}

Fields:
attribute x: str | float = 0.0#
attribute y: str | float = 0.0#
attribute dx: str | float = 0.0#
attribute dy: str | float = 0.0#
attribute rotation: float = 0.0#
attribute mirror: bool = False#
attribute xmin: str | float | None = None#
attribute xmax: str | float | None = None#
attribute ymin: str | float | None = None#
attribute ymax: str | float | None = None#
attribute port: str | PortPlacement | None = None#
class Netlist[source]#

Bases: BaseModel

Show JSON schema
{
   "title": "Netlist",
   "type": "object",
   "properties": {
      "instances": {
         "additionalProperties": {
            "$ref": "#/$defs/Component"
         },
         "title": "Instances",
         "type": "object"
      },
      "connections": {
         "additionalProperties": {
            "type": "string"
         },
         "title": "Connections",
         "type": "object"
      },
      "ports": {
         "additionalProperties": {
            "type": "string"
         },
         "title": "Ports",
         "type": "object"
      },
      "placements": {
         "additionalProperties": {
            "$ref": "#/$defs/Placement"
         },
         "title": "Placements",
         "type": "object"
      },
      "settings": {
         "title": "Settings",
         "type": "object"
      }
   },
   "$defs": {
      "Component": {
         "properties": {
            "component": {
               "title": "Component",
               "type": "string"
            },
            "settings": {
               "title": "Settings",
               "type": "object"
            }
         },
         "required": [
            "component"
         ],
         "title": "Component",
         "type": "object"
      },
      "Placement": {
         "properties": {
            "x": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "X"
            },
            "y": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "Y"
            },
            "dx": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "Dx"
            },
            "dy": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "Dy"
            },
            "rotation": {
               "default": 0.0,
               "title": "Rotation",
               "type": "number"
            },
            "mirror": {
               "default": false,
               "title": "Mirror",
               "type": "boolean"
            },
            "xmin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Xmin"
            },
            "xmax": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Xmax"
            },
            "ymin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Ymin"
            },
            "ymax": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Ymax"
            },
            "port": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "enum": [
                        "ce",
                        "cw",
                        "nc",
                        "ne",
                        "nw",
                        "sc",
                        "se",
                        "sw",
                        "cc",
                        "center"
                     ],
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Port"
            }
         },
         "title": "Placement",
         "type": "object"
      }
   }
}

Fields:
attribute instances: dict[InstanceStr, CoercingComponent] [Optional]#
Validated by:
  • coerce_nets_into_connections

attribute connections: dict[InstancePortStr, InstancePortStr] [Optional]#
Validated by:
  • coerce_nets_into_connections

attribute ports: dict[PortStr, InstancePortStr] [Optional]#
Validated by:
  • coerce_nets_into_connections

attribute placements: dict[InstanceStr, Placement] [Optional]#
Validated by:
  • coerce_nets_into_connections

attribute settings: dict[str, Any] [Optional]#
Validated by:
  • coerce_nets_into_connections

class RecursiveNetlist[source]#

Bases: RootModel

Show JSON schema
{
   "title": "RecursiveNetlist",
   "type": "object",
   "$defs": {
      "Component": {
         "properties": {
            "component": {
               "title": "Component",
               "type": "string"
            },
            "settings": {
               "title": "Settings",
               "type": "object"
            }
         },
         "required": [
            "component"
         ],
         "title": "Component",
         "type": "object"
      },
      "Netlist": {
         "properties": {
            "instances": {
               "additionalProperties": {
                  "$ref": "#/$defs/Component"
               },
               "title": "Instances",
               "type": "object"
            },
            "connections": {
               "additionalProperties": {
                  "type": "string"
               },
               "title": "Connections",
               "type": "object"
            },
            "ports": {
               "additionalProperties": {
                  "type": "string"
               },
               "title": "Ports",
               "type": "object"
            },
            "placements": {
               "additionalProperties": {
                  "$ref": "#/$defs/Placement"
               },
               "title": "Placements",
               "type": "object"
            },
            "settings": {
               "title": "Settings",
               "type": "object"
            }
         },
         "title": "Netlist",
         "type": "object"
      },
      "Placement": {
         "properties": {
            "x": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "X"
            },
            "y": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "Y"
            },
            "dx": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "Dx"
            },
            "dy": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  }
               ],
               "default": 0.0,
               "title": "Dy"
            },
            "rotation": {
               "default": 0.0,
               "title": "Rotation",
               "type": "number"
            },
            "mirror": {
               "default": false,
               "title": "Mirror",
               "type": "boolean"
            },
            "xmin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Xmin"
            },
            "xmax": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Xmax"
            },
            "ymin": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Ymin"
            },
            "ymax": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "number"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Ymax"
            },
            "port": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "enum": [
                        "ce",
                        "cw",
                        "nc",
                        "ne",
                        "nw",
                        "sc",
                        "se",
                        "sw",
                        "cc",
                        "center"
                     ],
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Port"
            }
         },
         "title": "Placement",
         "type": "object"
      }
   },
   "additionalProperties": {
      "$ref": "#/$defs/Netlist"
   }
}

Fields:
attribute root: dict[str, Netlist] [Required]#
netlist(netlist, with_unconnected_instances=True, with_placements=True)[source]#

return a netlist from a given dictionary

Parameters:
  • netlist (Any) –

  • with_unconnected_instances (bool) –

Return type:

RecursiveNetlist

flatten_netlist(recnet, sep='~')[source]#
Parameters:
load_netlist(pic_path)[source]#
Parameters:

pic_path (str) –

Return type:

Netlist

load_recursive_netlist(pic_path, ext='.yml')[source]#
Parameters:
  • pic_path (str) –

  • ext (str) –

is_recursive(netlist)[source]#
Parameters:

netlist (sax.netlist.Netlist | sax.netlist.NetlistDict | sax.netlist.RecursiveNetlist | dict[str, sax.netlist.NetlistDict]) –

is_not_recursive(netlist)[source]#
Parameters:

netlist (sax.netlist.Netlist | sax.netlist.NetlistDict | sax.netlist.RecursiveNetlist | dict[str, sax.netlist.NetlistDict]) –

get_netlist_instances_by_prefix(recursive_netlist, prefix)[source]#

Returns a list of all instances with a given prefix in a recursive netlist.

Parameters:
  • recursive_netlist (RecursiveNetlist) – The recursive netlist to search.

  • prefix (str) – The prefix to search for.

Returns:

A list of all instances with the given prefix.

get_component_instances(recursive_netlist, top_level_prefix, component_name_prefix)[source]#

Returns a dictionary of all instances of a given component in a recursive netlist.

Parameters:
  • recursive_netlist (RecursiveNetlist) – The recursive netlist to search.

  • top_level_prefix (str) – The prefix of the top level instance.

  • component_name_prefix (str) – The name of the component to search for.

Returns:

A dictionary of all instances of the given component.