spines.parameters

Parameters module for spines.

class spines.parameters.Parameter(*value_type, default: Optional[Any] = None, desc: Optional[str] = None)[source]

Bases: object

Parameter class

Parameters
  • value_type (type or Iterable of type) – The type(s) of values allowed for this parameter.

  • default (object, optional) – Default value for this parameter, if any.

  • desc (str, optional) – Description for this parameter, if any.

check(value: Any) → bool[source]

Checks the given value for validity

Based on this particular Parameter’s settings this method checks the given value to see if it’s in-line with the specifications.

Parameters

value – Parameter value to check validity of.

Returns

Whether or not the value is valid for the parameter.

Return type

bool

See also

preprocess()

default

Default value to use for this parameter.

Type

object

desc

Description of this parameter.

Type

str

name

Name of this parameter.

Type

str

preprocess(value: Any) → Any[source]

Pre-process/massage parameter values into correct type

This is used to try and convert parameter values to the allowed types (if possible). For instance the allowed type may be a float but the user provides 1, we would likely not want to break in that situation, but simply convert the int given into a float. However, this can also be used to perform more complex initialization or customization on given parameter values, if needed.

The default method is to try and cast the given value as the types given in this Parameter’s _value_types attribute and returning the first successful cast, otherwise returns the given input value.

This method can be easily extended or overridden for custom Parameter classes to handle more complex value types.

Parameters

value (object) – The value to pre-process for this parameter.

Returns

The pre-processed value.

Return type

object

Note

This method is, by default, only called if the given value fails this Parameter’s check call.

See also

check()

required

Whether or not this parameter is required to be set.

Type

bool

value_type

The types of values allowed for this option.

Type

tuple

class spines.parameters.HyperParameter(*value_type, default: Optional[Any] = None, desc: Optional[str] = None)[source]

Bases: spines.parameters.base.Parameter

Hyper-parameter

class spines.parameters.Bounded(*args, **kwargs)[source]

Bases: spines.parameters.mixins.Minimum, spines.parameters.mixins.Maximum, spines.parameters.base.Parameter

Bounded parameter (min/max)

class spines.parameters.HyperBounded(*args, **kwargs)[source]

Bases: spines.parameters.mixins.Minimum, spines.parameters.mixins.Maximum, spines.parameters.base.HyperParameter

Bounded hyper-parameter (min/max)

class spines.parameters.ParameterStore[source]

Bases: collections.abc.MutableMapping

Helper class for managing collections of Parameters.

add(parameter: Type[spines.parameters.base.Parameter]) → None[source]

Add a Parameter specification to this store

Parameters

parameter (Parameter) – Parameter specification to add to this parameter store.

Raises

ParameterExistsError – If a parameter option with the same name already exists.

copy(deep: bool = False) → Type[spines.parameters.store.ParameterStore][source]

Returns a copy of this parameter store object.

Parameters

deep (bool, optional) – Whether or not to do deep-copying of this stores contents.

Returns

Copied parameter store object.

Return type

ParameterStore

final

Whethor or not this set of parameters is finalized.

Type

bool

finalize() → None[source]

Finalizes the parameters stored

Raises

MissingParameterException – If a required parameter is not set.

parameters

Copy of the current set of parameters.

Type

dict

remove(name: str) → spines.parameters.base.Parameter[source]

Removes a Parameter specification

Parameters

name (str) – Name of the Parameter to remove.

Returns

The removed Parameter specified.

Return type

Parameter

Raises

KeyError – If the given name does not exist.

reset() → None[source]

Clears all of the parameters and options stored.

valid

Whether or not this is a fully valid set of parameters.

Type

bool

values

Copy of the current set of parameter values.

Type

dict

exception spines.parameters.InvalidParameterException[source]

Bases: spines.parameters.base.ParameterException

Thrown when an invalid parameter is given.

exception spines.parameters.MissingParameterException[source]

Bases: spines.parameters.base.ParameterException

Thrown when a required parameter is missing.