Skip to content

FunctionBuilder

Call a user-defined Python function to build or modify the HFSS model.

This builder is highly flexible and useful for dynamic setups.

Bases: BaseBuilder

Builder that delegates logic to a user-defined Python function.

This builder is highly flexible and useful when programmatic or external control over the build process is needed.

The user-supplied function must have the following signature:

def my_builder_function(hfss: Hfss, **kwargs) -> dict:
    ...
  • hfss: The active HFSS session object.
  • **kwargs: Arbitrary keyword arguments, typically containing build parameters.
  • The function must return a dictionary with any results or output parameters.
Example
def builder_function(hfss, name_value_dict):
    for name, value in name_value_dict.items():
        hfss[name] = value
    return {"status": "ok"}

Attributes:

Name Type Description
type Literal['function_builder']

Identifier for this builder type.

function Callable[[Hfss, ...], dict]

Callable object (excluded from serialization).

args dict

Static arguments passed to the function at runtime.

build

build(hfss: Hfss, parameters: dict | None = None) -> dict

Call the user-defined function with merged arguments.

Parameters:

Name Type Description Default
hfss Hfss

Active HFSS session.

required
parameters dict | None

Optional runtime parameters. These are merged with args and passed as keyword arguments to the function.

None

Returns:

Name Type Description
dict dict

Output of the user-defined function.

Raises:

Type Description
Exception

Any exception raised by the user-supplied function will propagate up.

Source code in src/quansys/workflow/builder/function_builder.py
def build(self, hfss: Hfss,
          parameters: dict | None = None) -> dict:
    """
    Call the user-defined function with merged arguments.

    Args:
        hfss: Active HFSS session.
        parameters: Optional runtime parameters. These are merged with `args` and passed as keyword arguments to the function.

    Returns:
        dict: Output of the user-defined function.

    Raises:
        Exception: Any exception raised by the user-supplied function will propagate up.
    """

    parameters = parameters or {}
    combined_args = merge_dicts(self.args, parameters)

    return self.function(hfss, **combined_args)