InputParameterMap

class pydsol.core.parameters.InputParameterMap(key: str, name: str, display_priority: float, *, parent: InputParameterMap | None = None, description: str | None = None)[source]

Bases: InputParameter

The InputParameterMap contains a number of InputParameters, each of which can also be an InputParameterMap again. The InputParameterMap provides functions to add and remove sub-parameters, to retrieve sub-parameters based on their key, and to return a sorted set of InputParameters based on their displayValue.

The InputParameterMap has all attributes of the InputParameter. The _value attribute is of the type dict[str, InputParameter].

__init__(key: str, name: str, display_priority: float, *, parent: InputParameterMap | None = None, description: str | None = None)[source]

Create a new InputParameterMap. This can be the root map, or a sub-map. The InputParameterMap has no default value, and is read-only by definition.

Parameters:
  • key (str) – The key of the parameter that can be a part of the dot-notation to uniquely identify the model parameter. The key does not contain the name of the parent, and should not contain any periods. It should also be unique within its node of the input parameter tree. The key is set at time of construction and it is immutable.

  • name (str) – Concise description of the input parameter, which can be used in a GUI to identify the parameter to the user.

  • display_priority (Union[int, float]) – A number indicating the order of display of the parameter in the parent parameter map. Floats are allowed to make it easy to insert an extra parameter between parameters that have already been allocated subsequent integer values.

  • parent (InputParameterMap (optional)) – The parent map in which the parameter can be retrieved using its key. Typically, only the root InputParameterMap has no parent, and all other parameters have an InputParameterMap as parent.

  • description (str (optional)) – A description or explanation of the InputParameter. For instance, an indication of the bounds or the type. This value is purely there for the user interface.

Raises:
  • TypeError – when key is not a string

  • ValueError – when key is an empty string, or key contains a period

  • ValueError – when key is not unique in the parent InputParameterMap

  • TypeError – when name is not a string

  • ValueError – when name is an empty string

  • TypeError – when display priority is not a number

  • TypeError – when parent is not an InputParametermap or None

property value: Dict[str, InputParameter]

Returns the dict defined in this InputParameterMap, which is the value.

Returns:

The dict defined in this InputParameterMap.

Return type:

dict[str, InputParameter]

set_value(value)[source]

Note that InputParameterMap does not have a setter for the value.

Warning

InputParameterMap does not have a setter for the value.

Raises:

NotImplementedError – when called.

add(input_parameter: InputParameter)[source]

Add an input parameter to the map, and sort the members based on the display_priorities.

Parameters:

input_parameter (InputParameter) – The input parameter to add to the map.

Raises:
  • TypeError – when input_parameter is not an InputParameter.

  • ValueError – when the input parameter has a key that is already present in the map

get(key: str) InputParameter[source]

Return an input parameter from the map based on its key. The key can an extended key with a dot-notation. In that case, get will travese into the tree and return the parameter from the correct sub-map.

Returns:

The input parameter from the map or sub-map based on its key.

Return type:

InputParameter

Raises:
  • KeyError – when the key or the first sub-part of the key cannot be found in the map

  • KeyError – when a sub-part of the key does not point to an InputParameterMap

remove(key) InputParameter[source]

Remove an input parameter from the map based on its key. The key can an extended key with a dot-notation. In that case, remove will travese into the tree and removes the parameter from the correct sub-map. When the key in the final (sub)map cannot be found, the method returns None and exits silently.

Returns:

The input parameter that was removed from the map or sub-map based on its key, or None when the key was not found.

Return type:

InputParameter

Raises:
  • KeyError – when the sub-part of the key cannot be found in the map

  • KeyError – when a sub-part of the key does not point to an InputParameterMap

print_values(*, depth: int = 0) str[source]

Make a string with the keys and values of the map, including sub-maps and their parameters. Indentation indicates the depth of the map and of the parameters.

Parameters:

depth (int (optional)) – The depth of the map traversal. For each further depth, two spaces will be added to the indentation of the output.

Returns:

A string with the keys and values of the map, including sub-maps and their parameters.

Return type:

str

property default_value: object

Returns the default (initial) value of the parameter. The actual return type will be defined in subclasses of InputParameter. The default value is immutable.

Returns:

The default (initial) value of the parameter.

Return type:

object

property description: str

Returns a description or explanation of the InputParameter. For instance, an indication of the bounds or the type. This value is purely there for the user interface.

Returns:

A description or explanation of the InputParameter.

Return type:

str

property display_priority: float

Return the number indicating the order of display of the parameter in the parent parameter map. Floats make it easy to insert an extra parameter between parameters that have already been allocated subsequent integer values.

Returns:

The number indicating the order of display of the parameter in the parent parameter map.

Return type:

float

extended_key()

Return the extended key of this InputParameter including parents with a dot-notation. The name of this parameter is the last entry in the dot notation.

Returns:

The extended key of this InputParameter including parents with a dot-notation.

Return type:

str

property key: str

Return the key of the parameter that can be a part of the dot-notation to uniquely identify the model parameter. The key does not contain the name of the parent. The key is set at time of construction and it is immutable.

Returns:

The key of the parameter that can be a part of the dot-notation to uniquely identify the model parameter.

Return type:

str

property name: str

Returns the concise description of the input parameter, which can be used in a GUI to identify the parameter to the user.

Returns:

The concise description of the input parameter, which can be used in a GUI to identify the parameter to the user.

Return type:

str

property parent: InputParameterMap

Return the parent map in which the parameter can be retrieved using its key. Typically, only the root InputParameterMap has no parent, and all other parameters have an InputParameterMap as parent.

Returns:

the parent map in which the parameter can be retrieved using its key.

Return type:

InputParameterMap

property read_only: bool

Return whether a user is prohibited from changing the value of the parameter or not.

Returns:

Whether a user is prohibited from changing the value of the parameter or not.

Return type:

bool