RepeatedConfigurationContainer

class ase2sprkkr.common.repeated_configuration_containers.RepeatedConfigurationContainer(definition, container=None)[source]

A container for configuration (problem-definition) options and/or sections.

Options in the configuration (problem-definition) files are grouped to sections, sections are then grouped in a configuration file object. This is a base class for these containers.

Class hierarchy

Inheritance diagram of ase2sprkkr.common.repeated_configuration_containers.RepeatedConfigurationContainer

Constructor

__init__(definition, container=None)[source]

Create the container and its members, according to the definition

add(id)[source]
clear(do_not_check_required=False, call_hooks=True, generated=None)[source]

Erase all values (or reset to default) from all options in the container (ad subcontainers)

Parameters:
  • do_not_check_required (bool) – Do not check validity of the values after clearing. If False (default) is passed as this argument, the required option without a default value (or a section containing such value) throw an exception, which prevents the clearing (neverthenless, previous values in the section will be cleared anyway).

  • call_hooks (bool) – If False, the cleared values do not raise theirs hooks

  • generated (bool) – If True

get(name=None, unknown='find')[source]

Get the value, either of self or of a child of a given name.

Parameters:
  • name (None or str) – If None, return contained values as a dictionary. Otherwise, return the value of the member with the given name.

  • unknown (str or None) – If unknown == ‘find’ and there is no member with a given name, try to find the first such in descendant conainers.

Returns:

value

Return type:

mixed

set(values={}, value=None, *, unknown='find', error=None, **kwargs)[source]
Parameters:

values (Dict[str, Any] | str | None)

_set(values={}, value=None, *, unknown='find', error=None, **kwargs)[source]

Set the value(s) of parameter(s). Usage:

> input_parameters.set({‘NITER’: 5, ‘NE’: [10]}) or > input_parameters.set(NITER=5, NE=[10])

Parameters:
  • values (Dict[str, Any] | str | None) – Dictionary of values to be set, or the name of the value, if the value is given.

  • value – Value to be set. Setting this argument require to pass string name to the values argument.

  • unkwnown ('add', 'find' or None) – How to handle unknown (not known by the definition) parameters. If ‘find’, try to find the values in descendant containers. If ‘add’, add unknown values as custom values. If None, throw an exception. Keyword only argument.

  • **kwargs (dict) – The values to be set (an alternative syntax as syntactical sugar)

items()[source]
values()[source]
as_dict(only_changed='basic', generated=False, copy=False)[source]

Return the content of the container as a dictionary. Nested containers will be transformed to dictionaries as well.

Parameters:
  • only_changed (bool | str) – Return only changed values, or all of them? If True, return only the values, that differ from the defaults. If False, return all the values. The default value ‘basic’ means, return all non-expert values and all changed expert values.

  • generated (bool) – Add generated values

is_changed()[source]
_save_to_file(file, always=False, name_in_grammar=None, delimiter='')[source]

Save the content of the container to the file (according to the definition)

Parameters:
  • file (file) – File object (open for writing), where the data should be written

  • always – Do not consider conditions

Returns:

If any value have been written return True, otherwise return False.

Return type:

something_have_been_written

_validate(why='save')[source]

Validate the configuration data. Raise an exception, if the validation fail.

Parameters:

why (str) – Type of the validation. Possible values save - Full validation, during save. set - Validation on user input. Allow required values not to be set. parse - Validation during parsing - some check, that are enforced by the parser, can be skipped.