Model Definition Properties
This example shows how to create a model definition with a model name parameter that will netlist at the front of the netlist string
def components_with_and_without_a_model_param_parameter(library: de.Library, design: db_uu.Design) -> None:
# Example showing how an instance is netlisted differently when ModelDef.has_model_param is set
# This netlist callback is implemented here to show the netlist for an instance when the
# ModelDef.has_model_param property is or is not set. If you wish to use the default
# netlist behavior, there is no need to implement this callback.
def netlist_callback(std_inst: de.db.StandardInstance) -> str:
from keysight.ads.de.experimental.netlist_helper import NetlistStringBuilder
model_def = std_inst.model_def
assert model_def
netlist_builder = NetlistStringBuilder(std_inst)
netlist = netlist_builder.clear_and_get_default_netlist_str()
if model_def.has_model_param:
# When has_model_param is set, the value of the first parameter is treated as the Model name and will be
# netlisted at the front in quotes. The remaining parameters will be netlisted as normal.
assert netlist == '"MyComp":MC1 Length=5.0 mil '
else:
# When has_model_param is not set, the standard netlist format will be used and the first parameter,
# along with the remaining parameters, will be netlisted as normal.
assert netlist == "MyComponent:MC1 Model=MyComp Length=5.0 mil "
return netlist
# Typically create_itemdef would be a function in a module called itemdef.py in the cell for your component
def create_itemdef(cell: de.Cell) -> de.db.ModelDef:
assert cell.name == "MyComponent"
# Use the standard formset from the global model lib
standard_formset = de.db.model_lib.formsets["StdFormSet"]
# Create a model with a couple parameters, the first one being a string parameter representing the model name
param_model = de.db.ModelParam("Model", "Model instance name", standard_formset, de.db.ModelUnitType.STRING)
param_model.default_value = de.db.std_string_param("MyComp")
# The model name parameter should be set so that it is not evaluated by the expression evaluator
param_model.is_evaluated = False
param_length = de.db.ModelParam("Length", "Length", standard_formset, de.db.ModelUnitType.LENGTH)
param_length.default_value = de.db.std_string_param("5.0 mil")
my_component = de.db.ModelDef(cell.cell_name, cell.cell_name)
my_component.inst_name_prefix = "MC"
my_component.is_sub_design = False
my_component.parameters = [param_model, param_length]
my_component.callbacks = [(de.db.ModelCb(de.db.ModelCbType.ITEM_NETLIST, netlist_callback))]
de.add_model_definition(cell.library, my_component)
return my_component
# Starting with a clear schematic ...
assert design.is_schematic
design.clear_design()
my_comp_cell = library.create_cell("MyComponent")
mc_def = create_itemdef(my_comp_cell)
create_symbol(library, my_comp_cell)
design.add_instance((f"{library.name}", "MyComponent", "symbol"), (0, 0))
# See netlist_callback() for the effect ModelDef.has_model_param has on the netlist
assert mc_def.has_model_param is False
design.generate_netlist()
mc_def.has_model_param = True
design.generate_netlist()
This example shows the transmission line property on a model definition
def transmission_line_property(library: de.Library, design: db_uu.Design) -> None:
assert design.is_schematic
design.clear_design()
# Typically create_itemdef would be a function in a module called itemdef.py in the cell for your component
def create_itemdef(cell: de.Cell) -> de.db.ModelDef:
assert cell.name == "MyTLine"
# Use the standard formset from the global model lib
standard_formset = de.db.model_lib.formsets["StdFormSet"]
param_width = de.db.ModelParam("W", "Line Width", standard_formset, de.db.ModelUnitType.LENGTH)
param_width.default_value = de.db.std_string_param("25.0 mil")
param_length = de.db.ModelParam("L", "Line Length", standard_formset, de.db.ModelUnitType.LENGTH)
param_length.default_value = de.db.std_string_param("100.0 mil")
param_temp = de.db.ModelParam("Temp", "Temperature", standard_formset, de.db.ModelUnitType.TEMPERATURE)
param_temp.default_value = de.db.std_string_param("")
param_temp.is_displayed_by_default = False
my_tline = de.db.ModelDef(cell.cell_name, cell.cell_name)
my_tline.parameters = [param_width, param_length, param_temp]
my_tline.inst_name_prefix = "MTLn"
# When defining your own transmission line components, set the is_transmission_line property to True
my_tline.is_transmission_line = True
de.add_model_definition(cell.library, my_tline)
return my_tline
my_tline_cell = library.create_cell("MyTLine")
create_itemdef(my_tline_cell)
create_symbol(library, my_tline_cell)
tl_inst = design.add_instance((f"{library.name}", "MyTLine", "symbol"), (0, 0))
tl_model = tl_inst.model_def
assert tl_model
assert tl_model.is_transmission_line
# Any transmission line component provided by ADS will have the ModelDefl.is_transmission_line property set to True
mlin_inst = design.add_instance(("ads_tlines:MLIN:symbol"), (3, 0))
mlin_model = mlin_inst.model_def
assert mlin_model
assert mlin_model.is_transmission_line
This example shows the is_unique property on a model definition
def is_unique_property(library: de.Library, design: db_uu.Design) -> None:
assert design.is_schematic
design.clear_design()
# Typically create_itemdef would be a function in a module called itemdef.py in the cell for your component
def create_itemdef(cell: de.Cell) -> de.db.ModelDef:
# Nothing special about this component other than its is_unique property
assert cell.cell_name == "MyUniqComp"
my_uniq_comp = de.db.ModelDef(cell.cell_name, cell.cell_name)
my_uniq_comp.inst_name_prefix = "MUC"
my_uniq_comp.is_unique = True
de.add_model_definition(cell.library, my_uniq_comp)
return my_uniq_comp
my_uniq_cell = library.create_cell("MyUniqComp")
create_itemdef(my_uniq_cell)
create_symbol(library, my_uniq_cell)
# Placing one unique component is fine
design.add_instance((f"{library.name}", "MyUniqComp", "symbol"), (0, 0))
try:
# Attempting to place another results in an error
design.add_instance((f"{library.name}", "MyUniqComp", "symbol"), (3, 0))
except RuntimeError as e:
assert "This item is defined to be unique. Only one instance of this type can be placed." in str(e)