parametric_component
parametric_component( decorated_function: collections.abc.Callable[..., photonforge.Component] | None = None, name_prefix: str | None = None, gdsii_safe_name: bool = True, use_parametric_cache_default: bool = True,) -> collections.abc.Callable[..., photonforge.Component]Decorator to create parametric components from functions.
If the name of the created component is empty, this decorator sets it with name prefix and the values of the function arguments when called.
Components can be cached to avoid duplication. They are cached based on
the calling arguments (specifically, argument id). Regardless of the
default setting, each component can use or skip caching by setting the
bool keyword argument use_parametric_cache in the decorated
function call.
Args
- decorated_function: Function that returns a Component.
- name_prefix: Prefix for the component name. If
None, the decorated function name is used. - gdsii_safe_name: If set, only use GDSII-safe characters in the name (
name_prefixis not modified by this flag). - use_parametric_cache_default: Controls the default caching behavior for the decorated function.
Examples
>>> @pf.parametric_component... def straight(*, length, port_spec_name, technology):... port_spec = technology.ports[port_spec_name]... c = pf.Component(technology=technology)... for layer, path in port_spec.get_paths((0, 0)):... c.add(layer, path.segment((length, 0)))... c.add_port(pf.Port(center=(0, 0), input_direction=0, spec=port_spec))... c.add_port(pf.Port(center=(length, 0), input_direction=180, spec=port_spec))... c.add_model(pf.Tidy3DModel(port_symmetries=[(1, 0)]))... return c...>>> technology = pf.basic_technology()>>> component = straight(length=5, port_spec_name="Strip", technology=technology)>>> print(component.name)straight_...Caching behavior:
>>> component1 = straight(length=2, port_spec_name="Strip", technology=technology)>>> component2 = straight(length=2, port_spec_name="Strip", technology=technology)>>> component3 = straight(... length=2, port_spec_name="Strip", technology=technology, use_parametric_cache=False... )>>> component2 == component1True>>> component2 is component1True>>> component3 == component1True>>> component3 is component1FalseNote
It is generally a good idea to force parametric components to accept
only keyword arguments (by using the * as first argument in the
argument list), because those are stored for future updates of the
created component with Component.update.
See Also