bag.util.cache

This module defines classes used to cache existing design masters

Module Contents

Classes

DesignMaster

A design master instance.

MasterDB

A database of existing design masters.

Functions

format_cell_name(→ str)

_netlist_used_names_iter(→ Iterable[str])

Attributes

MasterType

DBType

bag.util.cache.MasterType[source]
bag.util.cache.DBType[source]
bag.util.cache.format_cell_name(cell_name: str, rename_dict: Dict[str, str], name_prefix: str, name_suffix: str, exact_cell_names: Set[str], supply_wrap_mode: pybag.enum.SupplyWrapMode) str[source]
class bag.util.cache.DesignMaster(master_db: MasterDB, params: bag.util.immutable.Param, log_file: str, log_level: pybag.enum.LogLevel = LogLevel.DEBUG, *, key: Any = None, copy_state: Optional[Dict[str, Any]] = None)[source]

Bases: bag.util.logging.LoggingBase

A design master instance.

This class represents a design master in the design database.

Parameters:
  • master_db (MasterDB) – the master database.

  • params (Param) – the parameters dictionary.

  • log_file (str) – the log file path.

  • log_level (LogLevel) – the logging level.

  • key (Any) – If not None, the unique ID for this master instance.

  • copy_state (Optional[Dict[str, Any]]) – If not None, set content of this master from this dictionary.

params[source]

the parameters dictionary.

Type:

Param

property master_db: MasterDB[source]

Returns the database used to create design masters.

property lib_name: str[source]

The master library name

property cell_name: str[source]

The master cell name

property key: Optional[Any][source]

A unique key representing this master.

property finalized: bool[source]

Returns True if this DesignMaster is finalized.

property params: bag.util.immutable.Param[source]
classmethod get_qualified_name() str[source]

Returns the qualified name of this class.

classmethod populate_params(table: Mapping[str, Any], params_info: Mapping[str, str], default_params: Mapping[str, Any]) bag.util.immutable.Param[source]

Fill params dictionary with values from table and default_params

classmethod compute_unique_key(params: bag.util.immutable.Param) Any[source]

Returns a unique hashable object (usually tuple or string) that represents this instance.

Parameters:

params (Param) – the parameters object. All default and hidden parameters have been processed already.

Returns:

unique_id – a hashable unique ID representing the given parameters.

Return type:

Any

classmethod process_params(params: Mapping[str, Any]) Tuple[bag.util.immutable.Param, Any][source]

Process the given parameters dictionary.

This method computes the final parameters dictionary from the user given one by filling in default and hidden parameter values, and also compute the unique ID of this master instance.

Parameters:

params (Mapping[str, Any]) – the parameter dictionary specified by the user.

Returns:

unique_id – a hashable unique ID representing the given parameters.

Return type:

Any

update_signature(key: Any) None[source]
get_copy_state_with(new_params: bag.util.immutable.Param) Dict[str, Any][source]
get_copy_with(new_params: bag.util.immutable.Param) MasterType[source]

Returns a copy of this master instance.

classmethod to_immutable_id(val: Any) Any[source]

Convert the given object to an immutable type for use as keys in dictionary.

abstract classmethod get_params_info() Mapping[str, str][source]

Returns a dictionary from parameter names to descriptions.

Returns:

param_info – dictionary from parameter names to descriptions.

Return type:

Mapping[str, str]

classmethod get_default_param_values() Mapping[str, Any][source]

Returns a dictionary containing default parameter values.

Override this method to define default parameter values. As good practice, you should avoid defining default values for technology-dependent parameters (such as channel length, transistor width, etc.), but only define default values for technology-independent parameters (such as number of tracks).

Returns:

default_params – dictionary of default parameter values.

Return type:

Mapping[str, Any]

classmethod get_hidden_params() Dict[str, Any][source]

Returns a dictionary of hidden parameter values.

hidden parameters are parameters are invisible to the user and only used and computed internally.

Returns:

hidden_params – dictionary of hidden parameter values.

Return type:

Dict[str, Any]

abstract get_master_basename() str[source]

Returns the base name to use for this instance.

Returns:

basename – the base name for this instance.

Return type:

str

abstract get_content(output_type: pybag.enum.DesignOutput, rename_dict: Dict[str, str], name_prefix: str, name_suffix: str, shell: bool, exact_cell_names: Set[str], supply_wrap_mode: pybag.enum.SupplyWrapMode) Tuple[str, Any][source]

Returns the content of this master instance.

Parameters:
  • output_type (DesignOutput) – the output type.

  • rename_dict (Dict[str, str]) – the renaming dictionary.

  • name_prefix (str) – the name prefix.

  • name_suffix (str) – the name suffix.

  • shell (bool) – True if we’re just producing a shell content (i.e. just top level block).

  • exact_cell_names (Set[str]) – set of cell names to keep exact (don’t add prefix and suffix)

  • supply_wrap_mode (SupplyWrapMode) – the netlisting supply wrap mode.

Returns:

  • cell_name (str) – the master cell name.

  • content (Any) – the master content data structure.

finalize() None[source]

Finalize this master instance.

add_child_key(child_key: object) None[source]

Registers the given child key.

clear_children_key() None[source]

Remove all children keys.

children() Iterator[object][source]

Iterate over all children’s key.

class bag.util.cache.MasterDB(lib_name: str, log_file: str, prj: Optional[bag.core.BagProject] = None, name_prefix: str = '', name_suffix: str = '', log_level: pybag.enum.LogLevel = LogLevel.DEBUG)[source]

Bases: bag.util.logging.LoggingBase

A database of existing design masters.

This class keeps track of existing design masters and maintain design dependency hierarchy.

Parameters:
  • lib_name (str) – the library to put all generated templates in.

  • log_file (str) – the log file path.

  • prj (Optional[BagProject]) – the BagProject instance.

  • name_prefix (str) – generated master name prefix.

  • name_suffix (str) – generated master name suffix.

  • log_level (LogLevel) – the logging level.

property prj: bag.core.BagProject[source]
abstract property tech_info: bag.layout.tech.TechInfo[source]

the TechInfo object.

Type:

TechInfo

property lib_name: str[source]

Returns the master library name.

property cell_prefix: str[source]

Returns the cell name prefix.

property cell_suffix: str[source]

Returns the cell name suffix.

property used_cell_names: Set[str][source]
create_masters_in_db(output: pybag.enum.DesignOutput, lib_name: str, content_list: List[Any], top_list: List[str], supply_wrap_mode: pybag.enum.SupplyWrapMode = SupplyWrapMode.NONE, debug: bool = False, **kwargs: Any) None[source]

Create the masters in the design database.

Parameters:
  • output (DesignOutput) – the output type.

  • lib_name (str) – library to create the designs in.

  • content_list (Sequence[Any]) – a list of the master contents. Must be created in this order.

  • top_list (List[str]) – list of top level cells.

  • supply_wrap_mode (SupplyWrapMode) – the supply wrapping mode.

  • debug (bool) – True to print debug messages

  • **kwargs (Any) – parameters associated with the given output type.

clear()[source]

Clear all existing schematic masters.

new_master(gen_cls: Type[MasterType], params: Optional[Mapping[str, Any]] = None, debug: bool = False, **kwargs) MasterType[source]

Create a generator instance.

Parameters:
  • gen_cls (Type[MasterType]) – the generator class to instantiate. Overrides lib_name and cell_name.

  • params (Optional[Dict[str, Any]]) – the parameter dictionary.

  • debug (bool) – True to print debug messages.

  • **kwargs – optional arguments for generator.

Returns:

master – the generator instance.

Return type:

MasterType

find_master(key: Any) Optional[MasterType][source]
register_master(key: Any, master: MasterType) None[source]
instantiate_master(output: pybag.enum.DesignOutput, master: DesignMaster, top_cell_name: str = '', **kwargs) None[source]

Instantiate the given master.

Parameters:
  • output (DesignOutput) – the design output type.

  • master (DesignMaster) – the TemplateBase to instantiate.

  • top_cell_name (str) – name of the top level cell. If empty, a default name is used.

  • **kwargs (Any) – optional arguments for batch_output().

batch_output(output: pybag.enum.DesignOutput, info_list: Sequence[Tuple[DesignMaster, str]], debug: bool = False, rename_dict: Optional[Dict[str, str]] = None, **kwargs: Any) None[source]

create all given masters in the database.

Parameters:
  • output (DesignOutput) – The output type.

  • info_list (Sequence[Tuple[DesignMaster, str]]) – Sequence of (master, cell_name) tuples to instantiate. Use empty string cell_name to use default names.

  • debug (bool) – True to print debugging messages

  • rename_dict (Optional[Dict[str, str]]) – optional master cell renaming dictionary.

  • **kwargs (Any) – parameters associated with the given output type.

_batch_output_helper(info_dict: Dict[str, DesignMaster], master: DesignMaster, rename: Dict[str, str], rev_rename: Dict[str, str], used_names: Set[str]) None[source]

Helper method for batch_layout().

Parameters:
  • info_dict (Dict[str, DesignMaster]) – dictionary from existing master cell name to master objects.

  • master (DesignMaster) – the master object to create.

exclude_model(lib_name: str, cell_name: str) bool[source]

True to exclude the given schematic generator when generating behavioral models.

bag.util.cache._netlist_used_names_iter(used_names: Set[str], prefix: str, suffix: str, sup_wrap_mode: pybag.enum.SupplyWrapMode) Iterable[str][source]