gdsfactoryplus

GDSFactoryplus python library.

Modules:

Name Description
bbox

Generate cell bbox.

cli

GDSFactory+ CLI.

cli_test

Test Component Builds.

core

Core GDSFactory+ utilities.

export_spice

Uses VLSIRTools to convert from Klayout's DB Netlist to common spice formats.

freeze

Freeze a python cell as schematic netlist.

gdsfactoryplus

A Python module implemented in Rust.

generate_svg

Generate SVG from cell.

logger

GDSFactory+ Logger.

models

GDSFactory+ Pydantic models.

project

Find the GDSFactory+ project folder.

serve

GDSFactory+ Server.

settings

Parse the GDSFactory+ settings.

show

General Show function.

show3d

3D viewer.

show_cell

Show a python object in a vscode panel.

simulate

Simulate a factory.

version

Simply the GDSFactory+ version.

Classes:

Name Description
FrozenPdk

A frozen PDK that prevents modification of its attributes.

Functions:

Name Description
activate_pdk_by_name

Activate a PDK by name (deprecated).

add_components

Add multiple components to the database simultaneously.

add_factories

Add multiple factories to the database.

add_models

Add multiple models to the database.

build_by_names

Build multiple GDS cells by names.

check_conn

Run connectivity check on the given GDS file.

check_drc

Run DRC check on the given GDS file.

clear_cells_from_cache

Clear cells from cache by factory names.

cli_environment

Get a CLI environment.

create_callgraph

Create a directed graph from the call graph data.

default_lib_paths

Return default library paths.

extract_function_arguments

Extract function arguments and serialize them as JSON.

find_models

Find all models in the current project.

find_partial_definition

Find a partial function definition.

find_project_dir

Find the GDSFactory+ project folder.

generate_multipolygon

Generate a MultiPolygon from a component.

get_all_factories

Get all factory records from the database.

get_all_factory_names

Get all factory names from the database.

get_all_models

Get all model records from the database.

get_base_pdk

Get the base PDK, which is the generic PDK.

get_base_schema

Get base netlist schema.

get_build_dir

Get the build directory.

get_cells_from_regex

Find all cells in a python file decorated with @cell using a regex.

get_components_by_factories

Get all component records belonging to specific factories.

get_db_path

Get the path to the database.

get_factories_by_components

Get factory records for multiple components.

get_factories_by_idxs

Get factory records by their kcl indices.

get_factories_by_name

Get multiple factory records by their names.

get_factories_by_source

Get factory names for each given source file.

get_factory_sources_by_name

Get source file paths for multiple factories by their names.

get_gds_dir

Get the output GDS directory.

get_log_dir

Get the log directory.

get_logger

Get the GDSFactory+ logger.

get_model_sources_by_name

Get source file paths for multiple models by their factory names.

get_models_by_name

Get multiple model records by their factory names.

get_netlist_schema

Get the schema for a specific netlist.

get_pdk

Import a PDK by name.

get_pdk_name

Get the name of the pdk used in the project.

get_pics_dir

Get the PICs directory.

get_ports

Get the ports from a component.

get_project_dir

Get the project root directory.

get_project_name

Get the name of the project.

get_runtime_factories_dependency_graph

Get a dependency graph for multiple factories.

get_runtime_factory_dependencies

Get the dependencies of a factory.

get_schematic_recnet

Get a schematic record netlist.

get_settings

Get the gdsfactoryplus settings.

get_static_records

Get static records from a call graph.

get_svg

Get the (possible cached) svg for a cell.

get_wls

Get the wavelengths used in the project.

get_ws_port

Get the websocket port from the project directory.

ignore_prints

Ignore any output to stdout or stderr.

ignored_paths

Get paths to ignore.

import_modules

Import all modules from a given directory.

import_path

Import a module from a given path.

import_picyml

Import a yaml file as a module.

is_a_pdk

Check if the settings are for a pdk or a project.

lazy_import

Lazily import a module.

lazy_setattr

Lazily set an attribute on a LazyModule.

maybe_find_project_dir

Maybe find the GDSFactory+ project folder.

merge_rdb_strings

Merge RDB Strings.

none

Serialize as None.

parse_oc_spice

Parse OC spice.

plot_callgraph

Plot a call graph.

print_to_file

Print content to a file.

register_cells

Register PDK cells.

register_models

Register all models in the current project.

remove_components

Remove multiple components from the database simultaneously.

remove_components_by_factories

Remove all components belonging to specific factories from the database.

remove_factories

Remove multiple factories and all their child components from the database.

remove_factories_by_source

Remove factories from the database by their source.

remove_models

Remove multiple models from the database.

reset_timestamps

Reset the timestamps of all factories to the current time.

reset_ws_port

Reset the websocket port.

resolve_modname

Resolve the module name from a given path.

send_message

Send a message to vscode.

set_all_factories_has_model

Set the has_model field for all factories in the database.

set_factories_has_model_by_names

Set the has_model field for multiple factories by their names.

set_factories_status_by_names

Modify the status of multiple factories by their names.

set_ws_port

Set the websocket port.

sync_from_kcl

Sync all cells from gf.kcl into the components table of the database.

try_func

Try to execute a function and return the result.

unlazy

Get the underlying object of a lazy import.

validate_access

Validates the API key and returns the license information.

FrozenPdk

Bases: Pdk

A frozen PDK that prevents modification of its attributes.

activate_pdk_by_name

activate_pdk_by_name(name: str) -> Pdk

Activate a PDK by name (deprecated).

Parameters:

Name Type Description Default
name str

Name of the PDK to activate. (deprecated, will be ignored)

required

Returns:

Type Description
Pdk

gf.Pdk: The activated PDK object.

add_components

add_components(*records: ComponentRecord) -> None

Add multiple components to the database simultaneously.

Parameters:

Name Type Description Default
records ComponentRecord

ComponentRecord objects containing component information.

()

add_factories

add_factories(*records: FactoryRecord, update_last_modified: bool = True) -> None

Add multiple factories to the database.

Parameters:

Name Type Description Default
records FactoryRecord

FactoryRecord objects containing factory information.

()
update_last_modified bool

If True, updates the last_updated timestamp to current time. If False, preserves existing timestamp or uses default.

True

add_models

add_models(*records: ModelRecord) -> None

Add multiple models to the database.

Parameters:

Name Type Description Default
records ModelRecord

ModelRecord objects containing model information.

()

build_by_names

build_by_names(*names: str, with_metadata: bool = True) -> None

Build multiple GDS cells by names.

Parameters:

Name Type Description Default
names str

List of cell names to build.

()
with_metadata bool

Whether to include metadata in the GDS files.

True

check_conn

check_conn(path: str | Path, *, verbose: bool = True) -> str

Run connectivity check on the given GDS file.

Parameters:

Name Type Description Default
path str | Path

path to the GDS file to run the check on.

required
verbose bool

if True, print status messages to stderr.

True

check_drc

check_drc(
    path: str | Path,
    pdk: str = SETTINGS["drc"]["pdk"] or SETTINGS["pdk"]["name"],
    process: str = SETTINGS["drc"]["process"],
    timeout: int = SETTINGS["drc"]["timeout"],
    host: str = SETTINGS["drc"]["host"],
    api_key: str = SETTINGS["api"]["key"],
    *,
    verbose: bool = True,
) -> str

Run DRC check on the given GDS file.

Parameters:

Name Type Description Default
path str | Path

path to the GDS file to run the check on.

required
pdk str

PDK to use for the check.

SETTINGS['drc']['pdk'] or SETTINGS['pdk']['name']
process str

the drc rules might be slightly different depending on the process

SETTINGS['drc']['process']
timeout int

timeout in seconds for the check (DRC only).

SETTINGS['drc']['timeout']
host str

api host (DRC only).

SETTINGS['drc']['host']
api_key str

the api key (DRC only).

SETTINGS['api']['key']
verbose bool

if True, print status messages to stderr.

True
Note

the connectivity check runs locally, so for this check the api parameters timeout, host, api_key will be ignored.

clear_cells_from_cache

clear_cells_from_cache(*factory_names: str, remove_unnamed: bool = True) -> list[int]

Clear cells from cache by factory names.

cli_environment

cli_environment(*, no_stdout: bool, no_stderr: bool) -> Iterator[None]

Get a CLI environment.

create_callgraph

create_callgraph(
    graph_data: dict | None = None, /, *, lib_paths: dict[str, Path] | None = None
) -> DiGraph

Create a directed graph from the call graph data.

Parameters:

Name Type Description Default
graph_data dict | None

Optional pre-generated call graph data.

None
lib_paths dict[str, Path] | None

module name -> library path mapping of all relevant python libraries.

None

default_lib_paths cached

default_lib_paths() -> dict[str, Path]

Return default library paths.

extract_function_arguments

extract_function_arguments(func: Callable) -> dict

Extract function arguments and serialize them as JSON.

Parameters:

Name Type Description Default
func Callable

The function to extract arguments from.

required

Returns:

Type Description
dict

JSON string in format {argument_name: default_value} or None if extraction fails.

dict

Arguments without defaults have None as default.

dict

*args and **kwargs are ignored.

find_models

find_models(lib_paths: dict[str, Path] | None = None) -> dict[str, ModelRecord]

Find all models in the current project.

Parameters:

Name Type Description Default
lib_paths dict[str, Path] | None

module name -> library path mapping of all relevant python libraries.

None

Returns:

Type Description
dict[str, ModelRecord]

dict[str, ModelRecord]: mapping of model names to their records.

find_partial_definition

find_partial_definition(partial_name: str) -> Path | None

Find a partial function definition.

Parameters:

Name Type Description Default
partial_name str

Name of the partial function to find.

required

Returns:

Type Description
Path | None

Path to the file containing the partial definition, or None if not found.

find_project_dir

find_project_dir() -> Path

Find the GDSFactory+ project folder.

Returns:

Type Description
Path

The path to the GDSFactory+ project folder.

Raises:

Type Description
FileNotFoundError

if no project dir is found.

generate_multipolygon

generate_multipolygon(comp: Component) -> MultiPolygon

Generate a MultiPolygon from a component.

get_all_factories

get_all_factories() -> dict[str, FactoryRecord]

Get all factory records from the database.

Returns:

Type Description
dict[str, FactoryRecord]

Dict mapping factory names to their FactoryRecord objects.

get_all_factory_names

get_all_factory_names() -> list[str]

Get all factory names from the database.

get_all_models

get_all_models() -> dict[str, ModelRecord]

Get all model records from the database.

Returns:

Type Description
dict[str, ModelRecord]

Dict mapping factory names to their ModelRecord objects.

get_base_pdk cached

get_base_pdk() -> Pdk | FrozenPdk

Get the base PDK, which is the generic PDK.

Returns:

Type Description
Pdk | FrozenPdk

gf.Pdk: The base PDK object.

get_base_schema

get_base_schema() -> Schema

Get base netlist schema.

get_build_dir

get_build_dir() -> Path

Get the build directory.

get_cells_from_regex

get_cells_from_regex(path: Path) -> list[str]

Find all cells in a python file decorated with @cell using a regex.

Parameters:

Name Type Description Default
path Path

the path to the python file.

required

get_components_by_factories

get_components_by_factories(*factory_names: str) -> dict[str, list[ComponentRecord]]

Get all component records belonging to specific factories.

Parameters:

Name Type Description Default
factory_names str

Names of the factories to get components for.

()

Returns:

Type Description
dict[str, list[ComponentRecord]]

List of ComponentRecords that belong to the specified factories.

get_db_path

get_db_path() -> Path

Get the path to the database.

get_factories_by_components

get_factories_by_components(*components: str) -> dict[str, FactoryRecord]

Get factory records for multiple components.

Parameters:

Name Type Description Default
components str

Names of components to get factories for.

()

Returns:

Type Description
dict[str, FactoryRecord]

List of FactoryRecord objects for the components' factories.

dict[str, FactoryRecord]

Components with missing factories are skipped.

get_factories_by_idxs

get_factories_by_idxs(*idxs: int) -> dict[int, FactoryRecord]

Get factory records by their kcl indices.

Parameters:

Name Type Description Default
idxs int

KCL indices of the factories.

()

Returns:

Type Description
dict[int, FactoryRecord]

List of FactoryRecord objects for the factories. Skips any not found.

get_factories_by_name

get_factories_by_name(*names: str) -> dict[str, FactoryRecord]

Get multiple factory records by their names.

Parameters:

Name Type Description Default
names str

Names of the factories to get.

()

Returns:

Type Description
dict[str, FactoryRecord]

Dict mapping factory names to their FactoryRecord objects.

dict[str, FactoryRecord]

Raises ValueError if any factory not found.

get_factories_by_source

get_factories_by_source(*sources: Path | str) -> dict[str, list[str]]

Get factory names for each given source file.

Parameters:

Name Type Description Default
sources Path | str

Source file paths to match factories.

()

Returns:

Type Description
dict[str, list[str]]

Dict mapping each source path (as relative string) to a list of

dict[str, list[str]]

factory names using that source.

get_factory_sources_by_name

get_factory_sources_by_name(*names: str) -> dict[str, Path]

Get source file paths for multiple factories by their names.

Parameters:

Name Type Description Default
names str

Names of the factories to get sources for.

()

Returns:

Type Description
dict[str, Path]

Dict mapping factory names to their source file paths.

dict[str, Path]

Source paths are relative to project root, or None if not found.

get_gds_dir

get_gds_dir() -> Path

Get the output GDS directory.

get_log_dir

get_log_dir() -> Path

Get the log directory.

get_logger cached

get_logger(source: str = 'server') -> Logger

Get the GDSFactory+ logger.

get_model_sources_by_name

get_model_sources_by_name(*names: str) -> dict[str, Path]

Get source file paths for multiple models by their factory names.

Parameters:

Name Type Description Default
names str

Names of the factories to get model sources for.

()

Returns:

Type Description
dict[str, Path]

Dict mapping factory names to their source file paths.

dict[str, Path]

Source paths are relative to project root, or None if not found.

get_models_by_name

get_models_by_name(*names: str) -> dict[str, ModelRecord]

Get multiple model records by their factory names.

Parameters:

Name Type Description Default
names str

Names of the factories to get models for.

()

Returns:

Type Description
dict[str, ModelRecord]

Dict mapping factory names to their ModelRecord objects.

dict[str, ModelRecord]

Raises ValueError if any model not found.

get_netlist_schema

get_netlist_schema(netlist: dict) -> Schema

Get the schema for a specific netlist.

get_pdk

get_pdk() -> Pdk

Import a PDK by name.

Returns:

Type Description
Pdk

gf.Pdk: The imported PDK object.

Raises:

Type Description
ImportError

If the specified PDK cannot be found.

get_pdk_name

get_pdk_name() -> str

Get the name of the pdk used in the project.

get_pics_dir

get_pics_dir() -> Path

Get the PICs directory.

get_ports

get_ports(comp: str, **kwargs: Any) -> dict[str, str]

Get the ports from a component.

Parameters:

Name Type Description Default
comp str

Name of the component to get ports from.

required
**kwargs Any

Additional keyword arguments.

{}

Returns:

Type Description
dict[str, str]

A dictionary mapping port names to their directions.

get_project_dir

get_project_dir() -> Path

Get the project root directory.

get_project_name

get_project_name() -> str

Get the name of the project.

get_runtime_factories_dependency_graph

get_runtime_factories_dependency_graph(*names: str) -> DiGraph

Get a dependency graph for multiple factories.

Parameters:

Name Type Description Default
names str

Names of the factories to build the dependency graph for.

()

Returns:

Type Description
DiGraph

NetworkX DiGraph with factory dependencies. Edges represent dependencies

DiGraph

where an edge from A to B means A depends on B (B is a child of A).

get_runtime_factory_dependencies

get_runtime_factory_dependencies(name: str) -> tuple[list[str], list[str]]

Get the dependencies of a factory.

Parameters:

Name Type Description Default
name str

Name of the factory to get dependencies for.

required

Returns:

Type Description
tuple[list[str], list[str]]

Tuple of lists of factory names: (parents, children)

get_schematic_recnet

get_schematic_recnet(name: str) -> dict

Get a schematic record netlist.

Parameters:

Name Type Description Default
name str

name of the factory.

required

Returns:

Name Type Description
recnet dict

recursive netlist.

get_settings cached

get_settings() -> dict

Get the gdsfactoryplus settings.

Returns a dict with the merged settings from: 1. Environment variables (GFP_*) 2. pyproject.toml ([tool.gdsfactoryplus]) 3. ~/.gdsfactory/gdsfactoryplus.toml

get_static_records

get_static_records(
    G: DiGraph | None = None, /, *, paths: Iterable[Path] = ()
) -> dict[str, FactoryRecord]

Get static records from a call graph.

Parameters:

Name Type Description Default
G DiGraph | None

the call graph to extract records from (will be generated if not given).

None
paths Iterable[Path]

list of paths to filter the records by. If empty, reutrns all records.

()

Returns:

Type Description
dict[str, FactoryRecord]

A dictionary mapping factory names to their corresponding FactoryRecord.

get_svg cached

get_svg(comp: Component, width: int, height: int, theme: str = 'dark') -> str

Get the (possible cached) svg for a cell.

get_wls

get_wls() -> dict

Get the wavelengths used in the project.

get_ws_port

get_ws_port() -> int

Get the websocket port from the project directory.

Reads the port from {project_dir}/build/log/.wsport.log. Returns 7777 as the default port if the file doesn't exist or can't be read.

ignore_prints

ignore_prints(*, stdout: bool = True, stderr: bool = False) -> Iterator[None]

Ignore any output to stdout or stderr.

ignored_paths

ignored_paths() -> list[Path]

Get paths to ignore.

import_modules

import_modules(
    *, reload: bool = False, paths: Iterable[Path] = (), from_project: bool = True
) -> tuple[dict[Path, ModuleType], dict[Path, tuple[str, Exception]]]

Import all modules from a given directory.

Parameters:

Name Type Description Default
reload bool

If True, reloads the modules if they are already imported.

False
paths Iterable[Path]

An iterable of paths of specific files to import. If empty, all Python files in the pics_dir will be imported.

()
from_project bool

If True, only imports modules from the project directory.

True

Returns:

Type Description
tuple[dict[Path, ModuleType], dict[Path, tuple[str, Exception]]]

list[ModuleType]: A list of imported modules.

Raises:

Type Description
NotADirectoryError

If the given path is not a directory.

import_path

import_path(path: Path, *, reload: bool = False) -> ModuleType

Import a module from a given path.

Parameters:

Name Type Description Default
path Path

The path to the module or package.

required
reload bool

If True, reloads the module if it is already imported.

False

Returns:

Name Type Description
ModuleType ModuleType

The imported module.

import_picyml

import_picyml(
    path: Path, module_name: str | None = None, *, reload: bool = False
) -> ModuleType

Import a yaml file as a module.

Parameters:

Name Type Description Default
path Path

the path to the yaml file.

required
module_name str | None

the name of the module to create (if not given, derive from path).

None
reload bool

whether to reload the module if it was already imported.

False

Returns:

Name Type Description
ModuleType ModuleType

The imported module.

is_a_pdk

is_a_pdk() -> bool

Check if the settings are for a pdk or a project.

lazy_import

lazy_import(module_name: str, *callables: str) -> Any

Lazily import a module.

lazy_setattr

lazy_setattr(module_with_attrs: str, value: Any) -> None

Lazily set an attribute on a LazyModule.

maybe_find_project_dir

maybe_find_project_dir() -> Path | None

Maybe find the GDSFactory+ project folder.

Returns:

Type Description
Path | None

The path to the GDSFactory+ project folder or None if not found.

merge_rdb_strings

merge_rdb_strings(*xml_strings: str) -> str

Merge RDB Strings.

none

none(_: Any) -> None

Serialize as None.

parse_oc_spice

parse_oc_spice(
    path_or_buf: str | Path,
    settings_keymap: dict[str, Any] | None = None,
    component_map: dict[str, Any] | None = None,
    **kwargs: Any,
) -> dict[str, Any]

Parse OC spice.

plot_callgraph

plot_callgraph(G: DiGraph, /, *, prog: str = 'neato', show: bool = True) -> None

Plot a call graph.

Parameters:

Name Type Description Default
G DiGraph

the call graph to plot

required
prog str

the graphviz program to use for layout (e.g., 'neato', 'dot')

'neato'
show bool

whether to show the plot

True

print_to_file

print_to_file(path: str, value: str) -> None

Print content to a file.

register_cells

register_cells(
    *, paths: Iterable[Path] = (), reload: bool = True
) -> tuple[list[str], list[str]]

Register PDK cells.

Parameters:

Name Type Description Default
paths Iterable[Path]

Paths to Python modules containing PDK cells. If empty, it will import all modules.

()
reload bool

Whether to reload the modules we're importing from.

True

Returns:

Type Description
tuple[list[str], list[str]]

tuple[list[str], list[str]]: - List of names of newly registered cells. - List of names of deleted cells.

register_models

register_models(
    G: DiGraph | None = None, /, *, reload: bool = True
) -> tuple[list[str], list[str]]

Register all models in the current project.

Parameters:

Name Type Description Default
G DiGraph | None

(optional) the call graph to extract factory dependencies from.

None
reload bool

Whether to reload the modules containing the models.

True

Returns:

Type Description
tuple[list[str], list[str]]

tuple[list[str], list[str]]: - List of names of newly registered models. - List of names of deleted models.

remove_components

remove_components(*names: str) -> None

Remove multiple components from the database simultaneously.

Parameters:

Name Type Description Default
names str

List of component names to remove.

()

remove_components_by_factories

remove_components_by_factories(*factory_names: str) -> None

Remove all components belonging to specific factories from the database.

Parameters:

Name Type Description Default
factory_names str

Names of factories whose components should be removed.

()

remove_factories

remove_factories(*names: str) -> None

Remove multiple factories and all their child components from the database.

Parameters:

Name Type Description Default
names str

Names of the factories to remove.

()

remove_factories_by_source

remove_factories_by_source(*sources: Path | str) -> list[str]

Remove factories from the database by their source.

Parameters:

Name Type Description Default
sources Path | str

Source file paths to match factories for removal.

()

Returns:

Type Description
list[str]

List of factory names that were removed.

remove_models

remove_models(*names: str) -> None

Remove multiple models from the database.

Parameters:

Name Type Description Default
names str

Names of the models to remove.

()

reset_timestamps

reset_timestamps() -> None

Reset the timestamps of all factories to the current time.

reset_ws_port

reset_ws_port() -> None

Reset the websocket port.

Forces the next call to get_ws_port() to re-read from disk.

resolve_modname

resolve_modname(path: Path) -> str

Resolve the module name from a given path.

send_message

send_message(message: Message) -> None

Send a message to vscode.

Uses the high-performance Rust WebSocket implementation. This function will silently ignore errors and implement a cooldown period to avoid spamming failed connection attempts.

set_all_factories_has_model

set_all_factories_has_model(*, has_model: bool) -> None

Set the has_model field for all factories in the database.

Parameters:

Name Type Description Default
has_model bool

Boolean value to set for the has_model field.

required

set_factories_has_model_by_names

set_factories_has_model_by_names(*names: str, has_model: bool) -> None

Set the has_model field for multiple factories by their names.

Parameters:

Name Type Description Default
names str

Names of the factories to modify.

()
has_model bool

Boolean value to set for the has_model field.

required

set_factories_status_by_names

set_factories_status_by_names(*names: str, status: str) -> None

Modify the status of multiple factories by their names.

Parameters:

Name Type Description Default
names str

Names of the factories to modify.

()
status str

New status to set for the factories.

required

set_ws_port

set_ws_port(port: int | None) -> None

Set the websocket port.

Overrides the cached port value without reading from disk.

sync_from_kcl

sync_from_kcl() -> None

Sync all cells from gf.kcl into the components table of the database.

try_func

try_func(
    func: F | None = None,
    /,
    *,
    default: Any = None,
    default_factory: Callable | None = None,
) -> F

Try to execute a function and return the result.

Parameters:

Name Type Description Default
func F | None

The function to execute.

None
default Any

Default value to return if the function raises an exception.

None
default_factory Callable | None

Optional callable to generate a default value.

None

Returns:

Name Type Description
Callable F

A wrapped function that returns the result or a default value.

unlazy

unlazy(obj: Any) -> Any

Get the underlying object of a lazy import.

validate_access

validate_access(
    pdk_name: str,
    api_key: str = "",
    pdk_key: str = "",
    *,
    check_pdk_access: bool = False,
) -> dict[str, Any]

Validates the API key and returns the license information.

Parameters:

Name Type Description Default
pdk_name str

Name of the PDK to check access for.

required
api_key str

API key to validate.

''
pdk_key str

PDK secret key to validate.

''
check_pdk_access bool

Whether to check access to the specified PDK.

False
On This Page