feijoa.models package#

Submodules#

feijoa.models.configuration module#

Configuration model class module.

class feijoa.models.configuration.Configuration(*args, requestor='UNKNOWN', request_id=0, **kwargs)#

Bases: dict

Configuration model, inherited from built-in dict.

Example:

from feijoa.model.configuration import Configuration

configuration = Configuration(
    {"foo": 1, "bar": 2},
    requestor="simple",
    request_id=0,
)
Parameters
  • 1st – configuration dict.

  • requestor (str, optional) – Name of requestor (oracle).

  • request_id (int, optional) – Index of requested configuration for specified requestor.

clear() None.  Remove all items from D.#
copy() a shallow copy of D#
fromkeys(value=None, /)#

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() (k, v), remove and return some (key, value) pair as a#

2-tuple; but raise KeyError if D is empty.

setdefault(key, default=None, /)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#

feijoa.models.experiment module#

Experiment model class module.

class feijoa.models.experiment.Experiment(*, id, job_id, state, hash=None, objective_result=None, params, create_timestamp, finish_timestamp=None, metrics=None)#

Bases: pydantic.main.BaseModel

Experiment model.

Lifecycle of experiment:

  1. Create experiment from params (state=WIP)

  2. Suggest experiment to job

  3. Measure it

  4. If all metrics are collected set OK state, if error caused - ERROR.

  5. Finish experiment - calculate hash, set finish timestamp

6) Tell to optimizers 6) Save to storage

Parameters
  • id (int) – Index of experiment.

  • job_id (int) – Job index.

  • state (ExperimentState) – Experiment state. Must be WIP, OK or ERROR

  • hash (str, optional) – Hash of experiment.

  • objective_result (Optional[Any]) – Objective result of experiment. Now is float only, but in next version can be tuple/array.

  • create_timestamp (float) – Experiment creation timestamp.

  • finish_timestamp (float) – Experiment finish timestamp.

  • metrics (dict, optional) – Metrics of experiment.

  • params (feijoa.models.configuration.Configuration) –

Raises

AnyError – If anything bad happens.

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

class Config#

Bases: object

orm_mode = True#
apply(result)#

Apply result to experiment.

Parameters

result (float) – Objective result.

Returns

None

Raises

AnyError – If anything bad happens.

classmethod construct(_fields_set=None, **values)#

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

Parameters
  • _fields_set (Optional[SetStr]) –

  • values (Any) –

Return type

Model

copy(*, include=None, exclude=None, update=None, deep=False)#

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model

  • exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include

  • update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep (bool) – set to True to make a deep copy of the model

  • self (Model) –

Returns

new model instance

Return type

Model

create_timestamp: float#
dict(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False)#

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Parameters
  • include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • by_alias (bool) –

  • skip_defaults (Optional[bool]) –

  • exclude_unset (bool) –

  • exclude_defaults (bool) –

  • exclude_none (bool) –

Return type

DictStrAny

error_finish()#

Finish experiment with error state.

finish_timestamp: Optional[float]#
classmethod from_orm(obj)#
Parameters

obj (Any) –

Return type

Model

hash: Optional[str]#
id: int#
is_finished()#

Check if experiment is finished.

job_id: int#
json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)#

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

Parameters
  • include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • by_alias (bool) –

  • skip_defaults (Optional[bool]) –

  • exclude_unset (bool) –

  • exclude_defaults (bool) –

  • exclude_none (bool) –

  • encoder (Optional[Callable[[Any], Any]]) –

  • models_as_dict (bool) –

  • dumps_kwargs (Any) –

Return type

unicode

metrics: Optional[dict]#
objective_result: Optional[Any]#
params: feijoa.models.configuration.Configuration#
classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)#
Parameters
  • path (Union[str, pathlib.Path]) –

  • content_type (unicode) –

  • encoding (unicode) –

  • proto (pydantic.parse.Protocol) –

  • allow_pickle (bool) –

Return type

Model

classmethod parse_obj(obj)#
Parameters

obj (Any) –

Return type

Model

classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)#
Parameters
  • b (Union[str, bytes]) –

  • content_type (unicode) –

  • encoding (unicode) –

  • proto (pydantic.parse.Protocol) –

  • allow_pickle (bool) –

Return type

Model

classmethod schema(by_alias=True, ref_template='#/definitions/{model}')#
Parameters
  • by_alias (bool) –

  • ref_template (unicode) –

Return type

DictStrAny

classmethod schema_json(*, by_alias=True, ref_template='#/definitions/{model}', **dumps_kwargs)#
Parameters
  • by_alias (bool) –

  • ref_template (unicode) –

  • dumps_kwargs (Any) –

Return type

unicode

set_error()#

Set error state to experiment.

state: feijoa.models.experiment.ExperimentState#
success_finish()#

Finish experiment with success state.

classmethod update_forward_refs(**localns)#

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Parameters

localns (Any) –

Return type

None

classmethod validate(value)#
Parameters

value (Any) –

Return type

Model

class feijoa.models.experiment.ExperimentState(value)#

Bases: str, enum.Enum

An enumeration.

ERROR = 'ERROR'#
OK = 'OK'#
WIP = 'WIP'#

feijoa.models.result module#

Result model class module.

class feijoa.models.result.Result(*, objective_result, metrics=None)#

Bases: pydantic.main.BaseModel

Result model.

Parameters
  • objective_result (float) – Objective value.

  • metrics (Optional[Dict[str, float]]) – Metrics for result.

Returns

None

Raises

AnyError – If anything bad happens.

Return type

None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Config#

alias of pydantic.config.BaseConfig

classmethod construct(_fields_set=None, **values)#

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

Parameters
  • _fields_set (Optional[SetStr]) –

  • values (Any) –

Return type

Model

copy(*, include=None, exclude=None, update=None, deep=False)#

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model

  • exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include

  • update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep (bool) – set to True to make a deep copy of the model

  • self (Model) –

Returns

new model instance

Return type

Model

dict(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False)#

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Parameters
  • include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • by_alias (bool) –

  • skip_defaults (Optional[bool]) –

  • exclude_unset (bool) –

  • exclude_defaults (bool) –

  • exclude_none (bool) –

Return type

DictStrAny

classmethod from_orm(obj)#
Parameters

obj (Any) –

Return type

Model

json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)#

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

Parameters
  • include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –

  • by_alias (bool) –

  • skip_defaults (Optional[bool]) –

  • exclude_unset (bool) –

  • exclude_defaults (bool) –

  • exclude_none (bool) –

  • encoder (Optional[Callable[[Any], Any]]) –

  • models_as_dict (bool) –

  • dumps_kwargs (Any) –

Return type

unicode

metrics: Optional[Dict[str, float]]#
objective_result: float#
classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)#
Parameters
  • path (Union[str, pathlib.Path]) –

  • content_type (unicode) –

  • encoding (unicode) –

  • proto (pydantic.parse.Protocol) –

  • allow_pickle (bool) –

Return type

Model

classmethod parse_obj(obj)#
Parameters

obj (Any) –

Return type

Model

classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)#
Parameters
  • b (Union[str, bytes]) –

  • content_type (unicode) –

  • encoding (unicode) –

  • proto (pydantic.parse.Protocol) –

  • allow_pickle (bool) –

Return type

Model

classmethod schema(by_alias=True, ref_template='#/definitions/{model}')#
Parameters
  • by_alias (bool) –

  • ref_template (unicode) –

Return type

DictStrAny

classmethod schema_json(*, by_alias=True, ref_template='#/definitions/{model}', **dumps_kwargs)#
Parameters
  • by_alias (bool) –

  • ref_template (unicode) –

  • dumps_kwargs (Any) –

Return type

unicode

classmethod update_forward_refs(**localns)#

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Parameters

localns (Any) –

Return type

None

classmethod validate(value)#
Parameters

value (Any) –

Return type

Model

Module contents#