libmuscle.settings_manager module

class libmuscle.settings_manager.SettingsManager[source]

Bases: object

Manages the current settings for a component instance.

get_setting(instance: Reference, setting_name: Reference, typ: str | None = None) str | int | float | bool | List[float] | List[List[float]] | bool_union_fix[source]

Returns the value of a setting.

Parameters:
  • instance – The instance that this value is for.

  • setting_name – The name of the setting to get the value of.

  • typ – An optional type designation; if specified the type is checked for a match before returning. Valid values are ‘str’, ‘int’, ‘float’, ‘bool’, ‘[float]’ and ‘[[float]]’.

Raises:
  • KeyError – If the setting has not been set.

  • TypeError – If the setting was set to a value that does not match typ.

  • ValueError – If an invalid value was specified for typ

list_settings(instance_id: Reference) List[str][source]

Returns the names of all the settings.

This returns the names of all the settings, as the model would pass them to request settings. It returns

  • <setting_name> as-is

  • <instance_id>.<setting_name> as <setting_name>

  • <other_id>.<setting_name> not at all

  • <setting>.<setting> not at all

Note that we don’t return global settings with multipart names. Those are legal, but currently indistinguishable from settings intended for other components. We’re not actually telling anyone that they’re legal, so we can probably get away with that. If it becomes an issue, we’ll have to get a list of instance ids from the manager so we can recognise them correctly.

Parameters:

instance_id – Our instance id.

Returns:

A list of setting names.

libmuscle.settings_manager.has_setting_type(value: str | int | float | bool | List[float] | List[List[float]] | bool_union_fix, typ: str) bool[source]

Checks whether the value has the given type.

Parameters:
  • value – A setting value.

  • typ – A setting type. Valid values are ‘str’, ‘int’, ‘float’, ‘bool’, ‘[float]’, and ‘[[float]]’.

Returns:

True if the type of value matches typ.

Raises:

ValueError – If the type specified is not valid.