4.7.2 pde.tools.config module

Handles configuration variables of the package.

Parameter

Class representing a single parameter.

Config

Class handling general configurations.

get_package_versions

Tries to load certain python packages and returns their version.

parse_version_str

Helper function converting a version string into a list of integers.

check_package_version

Checks whether a package has a sufficient version.

packages_from_requirements

Read package names from a requirements file.

get_ffmpeg_version

Read version number of ffmpeg program.

is_hpc_environment

Check whether the code is running in a high-performance computing environment.

environment

Obtain information about the compute environment.

class Config(items=None, mode='update')[source]

Bases: UserDict

Class handling general configurations.

Configurations are basically dictionaries with string keys that hold Parameter values, which contain a value with some extra information. For user-friendliness, we also allow basic values, like strings or numbers as values.

Parameters:
  • items (dict, optional) – Configuration values that should be added or overwritten to initialize the configuration.

  • mode (str) –

    Defines the mode in which the configuration is used. Possible values are

    • insert: any new configuration key can be inserted

    • update: only the values of pre-existing items can be updated

    • locked: no values can be changed

    Note that the items specified by items will always be inserted, independent of the mode.

data: dict[str, str | float | int | bool | None | Parameter]
to_dict(*, ret_values=False)[source]

Convert the configuration to a simple dictionary.

Parameters:

ret_values (bool) – Only return values (and not Parameter instances)

Returns:

A representation of the configuration in a normal dict.

Return type:

dict

class GlobalConfig(items=None, mode='update')[source]

Bases: object

Class handling the global package configuration.

This class contains additional logic that allows managing multiple configurations, e.g., including the ones defined in pde.backends. The class also contains logic to deal with deprecated configuration options.

Parameters:
  • items (dict, optional) – Configuration values that should be added or overwritten to initialize the configuration.

  • mode (str) –

    Defines the mode in which the configuration is used. Possible values are

    • insert: any new configuration key can be inserted

    • update: only the values of pre-existing items can be updated

    • locked: no values can be changed

    Note that the items specified by items will always be inserted, independent of the mode.

items(just_values=True)[source]

Iterate over configuration items.

Parameters:

just_values (bool) – Whether to yield converted parameter values (True) or raw Parameter objects (False).

Yields:

tuple

Key-value pairs of configuration items, including items from all

backend configurations with keys prefixed by backend.<name>..

to_dict(*, ret_values=False, incl_backends=True)[source]

Convert the configuration to a simple dictionary.

Parameters:
  • ret_values (bool) – Only return values (and not Parameter instances)

  • incl_backends (bool) – Whether to include items from the backends

Returns:

A representation of the configuration in a normal dict.

Return type:

dict

update(items)[source]
Parameters:

items (dict[str, Any])

Return type:

None

class Parameter(name, default_value=None, cls=<class 'object'>, description='', hidden=False, extra=None)[source]

Bases: object

Class representing a single parameter.

Initialize a parameter.

Parameters:
  • name (str) – The name of the parameter

  • default_value – The default value

  • cls – The type of the parameter, which is used for conversion

  • description (str) – A string describing the impact of this parameter. This description appears in the parameter help

  • hidden (bool) – Whether the parameter is hidden in the description summary

  • extra (dict) – Extra arguments that are stored with the parameter

convert(value=None)[source]

Converts a value into the correct type for this parameter. If value is not given, the default value is converted.

Note that this does not make a copy of the values, which could lead to unexpected effects where the default value is changed by an instance.

Parameters:

value – The value to convert

Returns:

The converted value, which is of type self.cls

check_package_version(package_name, min_version)[source]

Checks whether a package has a sufficient version.

Parameters:
  • package_name (str)

  • min_version (str)

environment()[source]

Obtain information about the compute environment.

Returns:

information about the python installation and packages

Return type:

dict

get_ffmpeg_version()[source]

Read version number of ffmpeg program.

Return type:

str | None

get_package_versions(packages, *, na_str='not available')[source]

Tries to load certain python packages and returns their version.

Parameters:
  • packages (list) – The names of all packages

  • na_str (str) – Text to return if package is not available

Returns:

Dictionary with version for each package name

Return type:

dict

is_hpc_environment()[source]

Check whether the code is running in a high-performance computing environment.

Returns:

True if running in an HPC environment, False otherwise.

Return type:

bool

packages_from_requirements(requirements_file)[source]

Read package names from a requirements file.

Parameters:

requirements_file (str or Path) – The file from which everything is read

Returns:

list of package names

Return type:

list[str]

parse_version_str(ver_str)[source]

Helper function converting a version string into a list of integers.

Parameters:

ver_str (str)

Return type:

list[int]