cosapp.ports.variable¶
This module define the basic class encapsulating a variable attributes.
Classes
|
Base class for variable detail container. |
|
Variable detail container. |
-
class
cosapp.ports.variable.BaseVariable(name: str, port: cosapp.ports.port.BasePort, value: Any, unit: str = '', dtype: Optional[Union[Any, Tuple[Any, ...]]] = None, desc: str = '', scope: cosapp.ports.enum.Scope = <Scope.PRIVATE: 1>)[source]¶ Bases:
abc.ABCBase class for variable detail container.
- Parameters
name [str] (-) – Variable name.
port [BasePort] (-) – Port to which variable belongs.
value [Any] (-) – Variable value.
unit [str (-) – Variable unit; default empty string (i.e. dimensionless)
optional] – Variable unit; default empty string (i.e. dimensionless)
dtype [type or iterable of type (-) – Variable type; default None (i.e. type of initial value).
optional] – Variable type; default None (i.e. type of initial value).
desc [str (-) – Variable description; default to ‘’.
optional] – Variable description; default to ‘’.
scope [Scope] (-) – Variable visibility; defaults to PRIVATE.
-
abstract
copy(port: BasePort, name: Optional[str] = None) → BaseVariable[source]¶
-
property
description¶ Variable description
- Type
str
-
property
dtype¶ Type of the variable; default None (i.e. type of default value is set)
- Type
Type[Any] or Tuple of Type[Any] or None
-
property
full_name¶
-
property
name¶ Variable name
- Type
str
-
to_dict() → Dict[source]¶ Convert this variable into a dictionary.
- Returns
Dictionary representing variable. Attributes with None value are filtered out.
- Return type
Dict[str, Any]
-
property
unit¶ Variable unit; empty string means dimensionless
- Type
str
-
property
value¶
-
class
cosapp.ports.variable.Variable(name: str, port: cosapp.ports.port.BasePort, value: Any, unit: str = '', dtype: Optional[Union[Any, Tuple[Any, ...]]] = None, valid_range: Optional[Tuple[Any, Any]] = None, invalid_comment: str = '', limits: Optional[Tuple[Any, Any]] = None, out_of_limits_comment: str = '', desc: str = '', distribution: Optional[cosapp.utils.distributions.distribution.Distribution] = None, scope: cosapp.ports.enum.Scope = <Scope.PRIVATE: 1>)[source]¶ Bases:
cosapp.ports.variable.BaseVariableVariable detail container.
The valid_range defines the range of value for which a model is known to behave correctly. The limits are at least as large as the validity range.
- Parameters
name [str] (-) – Variable name.
port [BasePort] (-) – Port to which variable belongs.
value [Any] (-) – Variable value.
unit [str (-) – Variable unit; default empty string (i.e. dimensionless)
optional] – Variable unit; default empty string (i.e. dimensionless)
dtype [type or iterable of type (-) – Variable type; default None (i.e. type of initial value).
optional] – Variable type; default None (i.e. type of initial value).
desc [str (-) – Variable description; default to ‘’.
optional] – Variable description; default to ‘’.
valid_range [Tuple[Any (-) – Validity range of the variable; default None (i.e. all values are valid). Tuple[Any, Any] in case of scalar value, tuple of tuples in case of vector value.
or Tuple[Tuple] (Any]) – Validity range of the variable; default None (i.e. all values are valid). Tuple[Any, Any] in case of scalar value, tuple of tuples in case of vector value.
optional] – Validity range of the variable; default None (i.e. all values are valid). Tuple[Any, Any] in case of scalar value, tuple of tuples in case of vector value.
invalid_comment [str (-) – Comment to show in case the value is not valid; default ‘’
optional] – Comment to show in case the value is not valid; default ‘’
limits [Tuple[Any (-) – Limits over which the use of the model is wrong; default valid_range. Tuple[Any, Any] in case of scalar value, tuple of tuples in case of vector value.
or Tuple[Tuple] – Limits over which the use of the model is wrong; default valid_range. Tuple[Any, Any] in case of scalar value, tuple of tuples in case of vector value.
optional] – Limits over which the use of the model is wrong; default valid_range. Tuple[Any, Any] in case of scalar value, tuple of tuples in case of vector value.
out_of_limits_comment [str (-) – Comment to show in case the value is not valid; default ‘’
optional] – Comment to show in case the value is not valid; default ‘’
distribution [Distribution (-) – Variable random distribution; default None (no distribution)
optional] – Variable random distribution; default None (no distribution)
scope [Scope] (-) – Variable visibility; defaults to PRIVATE.
-
check_range_type(value: Iterable) → cosapp.ports.enum.RangeType[source]¶ Get type of valid_range of limits of variable. This function checks if value is a size 2 tuple of scalar or a tuple of (lower, upper) tuples.
- Parameters
value (Any) – value need to be checked
- Returns
Type of value
- Return type
int (from enum RangeType)
-
property
distribution¶ Random distribution of the variable.
- Type
Optional[Distribution]
-
get_validity_comment(status: cosapp.ports.enum.Validity) → str[source]¶ Get the ground arguments used to established the variable validity range.
The status Validity.OK has no ground arguments.
- Parameters
status (Validity.{OK, WARNING, ERROR}) – Validity status for which the reasons are looked for.
- Returns
Validity comment
- Return type
str
-
property
invalid_comment¶ Comment explaining the reasons of the validity range
- Type
str
-
is_valid() → cosapp.ports.enum.Validity[source]¶ Get the variable value validity.
- Returns
Variable value validity
- Return type
-
property
limits¶ Variable limits and optional comment if unvalid
- Type
Tuple[Any, Any] or None
-
property
out_of_limits_comment¶ Comment explaining the reasons of the limits
- Type
str
-
property
valid_range¶ alidity range of the variable and optional comment if unvalid
- Type
Tuple[Any, Any] or None