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: Types = None, desc: str = '', scope: Scope = Scope.PRIVATE)[source]¶
Bases:
ABC
Base class for variable detail container.
- Parameters:
[str] (- name) – Variable name.
[BasePort] (- port) – Port to which variable belongs.
[Any] (- value) – Variable value.
[str (- desc) – Variable unit; default empty string (i.e. dimensionless)
optional] – Variable unit; default empty string (i.e. dimensionless)
type (- dtype [type or iterable of) – Variable type; default None (i.e. type of initial value).
optional] – Variable type; default None (i.e. type of initial value).
[str – Variable description; default to ‘’.
optional] – Variable description; default to ‘’.
[Scope] (- scope) – Variable visibility; defaults to PRIVATE.
- abstract copy(port: cosapp.ports.port.BasePort, name: str | None = None) BaseVariable [source]¶
- property description: str¶
Variable description
- Type:
str
- property dtype: Any | Tuple[Any, ...] | None¶
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: str¶
- property name: str¶
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: str¶
Variable unit; empty string means dimensionless
- Type:
str
- property value: Any¶
- class cosapp.ports.variable.Variable(name: str, port: cosapp.ports.port.BasePort, value: Any, unit: str = '', dtype: Types = None, valid_range: RangeValue = None, invalid_comment: str = '', limits: RangeValue = None, out_of_limits_comment: str = '', desc: str = '', distribution: Distribution | None = None, scope: Scope = Scope.PRIVATE)[source]¶
Bases:
BaseVariable
Variable 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:
[str] (- name) – Variable name.
[BasePort] (- port) – Port to which variable belongs.
[Any] (- value) – Variable value.
[str (- out_of_limits_comment) – Variable unit; default empty string (i.e. dimensionless)
optional] – Variable unit; default empty string (i.e. dimensionless)
type (- dtype [type or iterable of) – Variable type; default None (i.e. type of initial value).
optional] – Variable type; default None (i.e. type of initial value).
[str – Variable description; default to ‘’.
optional] – Variable description; default to ‘’.
[Tuple[Any (- limits) – 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.
Tuple[Tuple] (Any] or) – 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.
[str – Comment to show in case the value is not valid; default ‘’
optional] – Comment to show in case the value is not valid; default ‘’
[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.
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.
[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) 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: Distribution | None¶
Random distribution of the variable.
- Type:
Optional[Distribution]
- get_validity_comment(status: 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: str¶
Comment explaining the reasons of the validity range
- Type:
str
- is_valid() Validity [source]¶
Get the variable value validity.
- Returns:
Variable value validity
- Return type:
- property limits: Tuple[Any, Any] | None¶
Variable limits and optional comment if unvalid
- Type:
Tuple[Any, Any] or None
- property out_of_limits_comment: str¶
Comment explaining the reasons of the limits
- Type:
str
- property valid_range: Tuple[Any, Any] | None¶
alidity range of the variable and optional comment if unvalid
- Type:
Tuple[Any, Any] or None