flowserv.model.parameter.numeric module

Declarations for numeric parameter values. Numeric parameters can specify ranges of valid values or minimum and maximum values.

class flowserv.model.parameter.numeric.Boundary(value: Optional[Union[int, float, str]] = None, is_closed: Optional[bool] = True)

Bases: object

Boundary definition for a range interval. Contains the interval boundary value and a flag defining whether the interval is open (i.e., excludes the defined value) or closed (i.e., includes the defined value).

is_closed: Optional[bool] = True
to_left_boundary() str

Return a left-boundary representation.

Return type

string

to_right_boundary() str

Return a left-boundary representation.

Return type

string

value: Union[int, float, str] = None
class flowserv.model.parameter.numeric.Float(name: str, index: Optional[int] = 0, label: Optional[str] = None, help: Optional[str] = None, default: Optional[float] = None, required: Optional[bool] = False, group: Optional[str] = None, min: Optional[Union[int, float, str, flowserv.model.parameter.numeric.Boundary]] = None, max: Optional[Union[int, float, str, flowserv.model.parameter.numeric.Boundary]] = None)

Bases: flowserv.model.parameter.numeric.Numeric

Base class for float parameter types.

class flowserv.model.parameter.numeric.Int(name: str, index: Optional[int] = 0, label: Optional[str] = None, help: Optional[str] = None, default: Optional[int] = None, required: Optional[bool] = False, group: Optional[str] = None, min: Optional[Union[int, float, str, flowserv.model.parameter.numeric.Boundary]] = None, max: Optional[Union[int, float, str, flowserv.model.parameter.numeric.Boundary]] = None)

Bases: flowserv.model.parameter.numeric.Numeric

Base class for integer parameter types.

class flowserv.model.parameter.numeric.Numeric(dtype: str, name: str, index: Optional[int] = 0, label: Optional[str] = None, help: Optional[str] = None, default: Optional[Union[int, float]] = None, required: Optional[bool] = False, group: Optional[str] = None, constraint: Optional[flowserv.model.parameter.numeric.RangeConstraint] = None)

Bases: flowserv.model.parameter.base.Parameter

Base class for numeric parameter types. Extends the base class with an optional range constraint.

cast(value: Any) Any

Convert the given value into a numeric value. Raises an error if the value cannot be converted to the respective numeric type of if it does not satisfy the optional range constraint.

Parameters

value (any) – User-provided value for a template parameter.

Return type

sting, float, or int

Raises

flowserv.error.InvalidArgumentError

static from_dict(doc: Dict, validate: Optional[bool] = True) flowserv.model.parameter.numeric.Numeric

Get numeric parameter instance from a dictionary serialization.

Parameters
  • doc (dict) – Dictionary serialization for numeric parameter.

  • validate (bool, default=True) – Validate the serialized object if True.

Return type

flowserv.model.parameter.numeric.Numeric

Raises

flowserv.error.InvalidParameterError

to_dict() Dict

Get dictionary serialization for the parameter declaration. Adds a serialization for an optional range constraint to the serialization of the base class.

Return type

dict

class flowserv.model.parameter.numeric.RangeConstraint(left_boundary: Dict, right_boundary: Dict)

Bases: object

Range constraint for numeric parameter values. Range constraints are specified as strings following standard interval notation where square brackets denote closed intervals and round brackets denote open intervals. Infinity and negative infinity are represented as ‘inf’ and ‘-inf’, respectively. They may also be represented as an empty string.

Valid range interval strings are: [x,y], (x,y), [x,y), and (x,y] where x may either be a number, ‘’, or ‘-inf’, and y may either be a number, ‘’, or ‘inf’.

classmethod from_string(value: str)

Create range constraint instance from string representation.

Parameters

value (string) – String representation for a range constraint.

Return type

flowserv.model.parameter.numeric.RangeConstraint

Raises

ValueError

is_closed() bool

Returns True if both interval boundaries are closed.

Return type

bool

max_value() Union[int, float]

Get the right boundary value for the interval.

Return type

int or float

min_value() Union[int, float]

Get the left boundary value for the interval.

Return type

int or float

to_string() str

Get string representation for the range constraint.

Return type

string

validate(value: Union[int, float]) bool

Validate that the given value is within the interval. Raises an error if the value is not within the interval.

Parameters

value (int or float) – Value that is being tested.

Raises

flowserv.error.InvalidArgumentError

flowserv.model.parameter.numeric.range_constraint(left: Optional[Union[int, float, str, flowserv.model.parameter.numeric.Boundary]] = None, right: Optional[Union[int, float, str, flowserv.model.parameter.numeric.Boundary]] = None) flowserv.model.parameter.numeric.RangeConstraint

Create a range constraint instance from a given pair of interval boundaries. Returns None if no boundary is given.

Parameters
  • left (flowserv.model.parameter.numeric.IntervalBoundary, default=None) – Left boundary for range constraint.

  • right (flowserv.model.parameter.numeric.IntervalBoundary, default=None) – Right boundary for range constraint.

Return type

flowserv.model.parameter.numeric.RangeConstraint