lib.parameter.ParameterCollection

class lib.parameter.ParameterCollection(data=None, parser=None)

Bases: lib.utils.BaseOrderedCollection

Class holding a collection of parameters.

Initialize ParameterCollection.

Parameters
  • data (list, tuple, string, dict, ParameterCollection) –

    Can be:

    • list (or tuple) of parameters (Parameter or dictionary to initialize Parameter).

    • path to a configuration yaml file to decode

    • dictionary of name: parameter

    • ParameterCollection instance

  • string (string) – If not None, yaml format string to decode. Added on top of data.

  • parser (callable, default=yaml_parser) – Function that parses yaml string into a dictionary. Used when data is string, or string is not None.

Methods

clear

Empty collection.

concatenate

Concatenate input collections.

copy

Return shallow copy of self.

deepcopy

extend

Extend collection with other.

from_state

Instantiate and initalize class with state dictionary.

get

Return parameter of name name in collection.

index

Return index of parameter name.

is_mpi_broadcast

is_mpi_gathered

is_mpi_root

is_mpi_scattered

load

Load class in numpy binary format from disk.

load_auto

If different formats are possible, this method should between them based on file name extension.

log_critical

log_debug

log_error

log_info

log_warning

names

Return names of parameters (ParamName instances) in collection.

reorder

Reorder collection following index list indices.

save

Save class to disk.

save_auto

If different formats are possible, this method should between them based on file name extension.

select

Return new collection, after selection of parameters whose attribute match input values.

set

Set parameter param in collection.

setdefault

Set parameter param in collection if not already in it.

unique

Return list of unique attribute key of collection items.

Attributes

logger

mpiattrs

MPI attributes

mpicomm

mpiroot

mpistate

__add__(other)

Addition of two collections is defined as concatenation.

clear()

Empty collection.

classmethod concatenate(*others)

Concatenate input collections. Unique items only are kept.

copy()

Return shallow copy of self.

extend(other)

Extend collection with other. Unique items only are kept.

classmethod from_state(state, mpiroot=0, mpicomm=None)

Instantiate and initalize class with state dictionary.

get(name)

Return parameter of name name in collection.

Parameters

name (Parameter, ParamName, string, tuple) – Parameter name. If Parameter instance, search for parameter with same name.

Returns

param

Return type

Parameter

index(name)

Return index of parameter name.

Parameters

name (Parameter, ParamName, string, tuple, int) – Parameter name. If Parameter instance, search for parameter with same name. If integer, index in collection.

Returns

index

Return type

int

classmethod load(filename, mpiroot=0, mpicomm=None)

Load class in numpy binary format from disk. If the loaded state contains __class__ and that exists in cls._registry, return instance of cls._registry[__class__] (instead of cls).

load_auto(*args, **kwargs)

If different formats are possible, this method should between them based on file name extension.

property mpiattrs

MPI attributes

names()

Return names of parameters (ParamName instances) in collection.

reorder(indices)

Reorder collection following index list indices.

save(filename)

Save class to disk.

save_auto(*args, **kwargs)

If different formats are possible, this method should between them based on file name extension.

select(**kwargs)

Return new collection, after selection of parameters whose attribute match input values:

collection.select(fixed=True)

returns collection of fixed parameters. If ‘name’ is provided, consider all matching parameters, e.g.:

collection.select(varied=True,name='a_[0:2]')

returns a collection of varied parameters, with name in ['a_0', 'a_1'].

set(param)

Set parameter param in collection. If there is already a parameter with same name in collection, replace this stored parameter by the input one. Else, append parameter to collection.

setdefault(param)

Set parameter param in collection if not already in it.

unique(key)

Return list of unique attribute key of collection items.