Interoperable Component Parameters
Example illustrating how to access and modify the value of a parameter of an interoperable component
def accessing_cdf_instance_parameters(design: db_uu.Design, library: de.Library) -> None:
from keysight.ads.de import experimental as exp
# inst_c1 is an interoperable instance placed in the design
inst_c1 = design.instances["C1"]
# Retrieve the cell CDF from the 'cap' cell
cell_cdf = exp.cdf.cell_cdf(library, "cap")
# Create the interface to the instance CDF parameters
inst_cdf = exp.cdf.InstanceParams(inst_c1) # CellCDF parameter is optional when passing in an Instance
assert cell_cdf == inst_cdf.cell_cdf
assert inst_cdf.parent_design_uu == inst_c1.parent
# Retrieve the parameter definition for the 'c' parameter
# Note: There are several ways to retrieve a parameter definition, as shown below
param_def = inst_cdf.find_param_def("c") # Returns None if not found
assert param_def is not None
assert param_def == inst_cdf.param_def("c") # Throws if not found
# The ParamDef on the instance is the same as the ParamDef on the CellCDF
assert param_def == cell_cdf.find_param("c") # Returns None if not found
assert param_def == cell_cdf.param("c") # Throws if not found
# Note: The CDF.params property creates a collection of all the parameter definitions and while
# that can be quite helpful for use with a debugger, it is not recommended for use cases requiring
# high performance
assert param_def == cell_cdf.params["c"] # Throws if not found
# Like ParamDef, there are multiple ways to retrieve a Parameter
parameter = inst_cdf.find_param("c") # Returns None if not found
assert parameter is not None
assert parameter == inst_cdf.param("c") # Throws if not found
# The parameter can also be retrieved using the ParamDef
assert parameter == inst_cdf.param(param_def) # Throws if not found
# Similar to CDF.params, the Instance.params property will create a collection of Parameter
# and may have a performance impact; consider using the param or find_param methods
assert parameter == inst_cdf.params["c"]
# Retrieve the value of the Parameter
value = parameter.value
assert value is not None
# There are multiple ways to get and set the value of a parameter
assert value == inst_cdf.param_value(param_def)
# param_value_no_default will only return a value if the value is not the default value
assert not inst_cdf.is_modified
assert inst_cdf.param_value_no_default(param_def) is None
# Set the value of the parameter
parameter.value = "3p"
assert inst_cdf.param_value(param_def) == "3p"
# The CDF instance is now modified and param_value_no_default will return the modified value
assert inst_cdf.is_modified
assert inst_cdf.param_value_no_default(param_def) == "3p"
# Set the value of the parameter using the ParamDef
inst_cdf.set_param_value(param_def, "4p")
assert parameter.value == "4p"
# Set the value of the parameter using the parameter name
inst_cdf.set_param_value("c", "5p")
assert parameter.value == "5p"
# Set the value of the parameter by indexing into the params collection
inst_cdf.params["c"].value = "6p"
assert parameter.value == "6p"
# NOTE: Be sure to call update_instance to apply the changes or they will be lost
inst_cdf.update_instance(inst_c1)
inst_c1 = design.instances["C1"]
assert inst_cdf.param("c").value == "6p"
Example illustrating how to add a new parameter definition to an interoperable component before placing an instance
def adding_a_new_parameter_definition_to_a_cell_cdf(design: db_uu.Design, library: de.Library) -> None:
from keysight.ads.de import experimental as exp
# Retrieve the cell CDF from the 'cap' cell
cell_cdf = exp.cdf.cell_cdf(library, "cap")
# Create an interface to the CDF parameters
inst_cdf_from_design = exp.cdf.InstanceParams(design, cell_cdf)
# Create a new ParamDef, new_param, with a display name of "New Parameter" and a default value of 10
new_param_def = exp.cdf.ParamDef("new_param", exp.cdf.ParamType.INT)
new_param_def.prompt = "New Parameter"
new_param_def.default_value = 10
# Add the new parameter to the CellCDF
inst_cdf_from_design.cell_cdf.add_param(new_param_def)
# Add a new instance of cap to the design
design.add_instance((library.lib_name, "cap", "symbol"), (0, 0), name="C2")
# Retrieve the instance just added
inst_c2 = design.instances["C2"]
# Create the interface to the CDF instance parameters
inst_cdf = exp.cdf.InstanceParams(inst_c2)
assert inst_cdf.param("new_param").value == 10
# Update the value after placing the instance, as desired
inst_cdf.param("new_param").value = 25
# NOTE: Be sure to call update_instance to apply the changes or they will be lost
inst_c2 = design.instances["C2"]
inst_cdf = exp.cdf.InstanceParams(inst_c2)
# Uh-oh, we forgot to call update_instance and the change was lost!
assert inst_cdf.param("new_param").value == 10
# So, let's try again ...
inst_cdf.param("new_param").value = 25
inst_cdf.update_instance(inst_c2)
# Verify the result by re-obtaining the instance and validating the parameter value
inst_c2 = design.instances["C2"]
inst_cdf = exp.cdf.InstanceParams(inst_c2)
assert inst_cdf.param("new_param").value == 25