openlane.state API

The State Module

This module manages the State of a Design before and after the execution of an OpenLane step. The State is essentially a list of views in various formats in addition to the cumulative set of metrics created by previous Steps.

class openlane.state.DesignFormat(id: str, extension: str, full_name: str, alts: ~typing.List[str] = <factory>, folder_override: str | None = None, multiple: bool = False)

Bases: object

Metadata about the various possible text or binary representations (views) of any design.

For example, DesignFormat.nl has the metadata for Netlist views.

Parameters:
  • id (str) – A lowercase alphanumeric/underscore identifier for the design format.

  • extension (str) – The file extension for designs saved in this format.

  • full_name (str) – A human-readable name for this design format.

  • alts (List[str]) – A list of alternate ids used to access the DesignFormat by the subscript operator. Includes its OpenLane <3.0.0 enumeration name for limited backwards compatibility.

  • folder_override (Optional[str]) – The subdirectory when openlane.state.State.save_snapshot() is called on a state. If unset, the value for id will be used.

  • multiple (bool) – Whether this view may have multiple files (typically, files that are different across multiple corners or similar.)

property value: DesignFormat

Deprecated since version 3.0.0: The DesignFormat is directly returned now, no need for .value

property name: str

Deprecated since version 3.0.0: .name has been removed because it’s redundant, use .id

static by_id(id: str) DesignFormat | None

Deprecated since version 3.0.0: Use DesignFormat.factory.get

Parameters:

id (str)

Return type:

DesignFormat | None

class DesignFormatFactory

Bases: object

A factory singleton for DesignFormats, allowing them to be registered and then retrieved by a string name.

See https://en.wikipedia.org/wiki/Factory_(object-oriented_programming) for a primer.

classmethod register(df: DesignFormat) DesignFormat

Adds a DesignFormat to the registry using its DesignFormat.id, DesignFormat.name and DesignFormat.alts attributes.

Parameters:

df (DesignFormat)

Return type:

DesignFormat

classmethod get(name: str) DesignFormat | None

Retrieves a DesignFormat type from the registry using a lookup string.

Parameters:

name (str) – The registered name of the Step. Case-insensitive.

Return type:

DesignFormat | None

classmethod list() List[str]
Returns:

A list of IDs of all registered DesignFormat.

Return type:

List[str]

factory

alias of DesignFormatFactory

class openlane.state.State(copying: Mapping[str, Path | List[Path] | Dict[str, Path | List[Path]] | None] | Mapping[DesignFormat, Path | List[Path] | Dict[str, Path | List[Path]] | None] | None = None, *args, overrides: Mapping[str, Path | List[Path] | Dict[str, Path | List[Path]] | None] | Mapping[DesignFormat, Path | List[Path] | Dict[str, Path | List[Path]] | None] | None = None, metrics: Mapping[str, Any] | None = None, **kwargs)

Bases: GenericImmutableDict[str, Path | List[Path] | Dict[str, Path | List[Path]] | None]

Basically, a dictionary from DesignFormats and values of (nested dictionaries of) openlane.common.Path.

The state is the only thing that can be altered by steps other than the filesystem.

States are immutable. To construct a new state with some modifications, you may do so as follows:

state_b = State(
    copying=state_a,
    overrides={
        …
    },
    metrics=GenericImmutableDict(copying=state_a.metrics, overrides={
        …
    })
)

Though in the majority of cases, you do not have to construct States on your own: after executing a Step, you only return your deltas and then the Flow is responsible for the creation of a new Step object.

Parameters:
  • copying (Optional[Union[Mapping[str, StateElement], Mapping[DesignFormat, StateElement]]]) – A mutable or immutable mapping to use as the starting value for this State.

  • overrides (Optional[Union[Mapping[str, StateElement], Mapping[DesignFormat, StateElement]]]) – A mutable or immutable mapping to override the starting values with.

  • metrics (Optional[Mapping[str, Any]]) – A dictionary that carries statistics about the design: area, wire length, et cetera, but also miscellaneous data, for example, whether it passed a certain check or not.

to_raw_dict(metrics: bool = True) Dict[str, Any]
Returns:

A copy of the underlying Python built-in dict for this class.

Parameters:

metrics (bool)

Return type:

Dict[str, Any]

copy() State

Convenience replacement for object.__class__(object), which would create a copy of the GenericDict object.

Returns:

The copy

Parameters:

self (State)

Return type:

State

save_snapshot(path: str | PathLike)

Validates the current state then saves all views to a folder by design format, including the metrics.

Parameters:

path (str | PathLike) – The folder that would contain other folders.

validate()

Ensures that all paths exist in a State.

exception openlane.state.InvalidState

Bases: RuntimeError