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: BasePort, value: Any, unit='', dtype: Types | None = None, desc='', scope=Scope.PRIVATE)[source]¶
Bases:
ABCBase 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: BasePort, name: str | None = None) BaseVariable[source]¶
- property description: str¶
Variable description
- Type:
str
- property dtype: type | tuple[type, ...] | 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¶
Full variable name, including port contextual name
- Type:
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¶
Variable value
- Type:
Any
- class cosapp.ports.variable.Variable(name: str, port: BasePort, value: Any, unit='', dtype: Types | None = None, valid_range: RangeValue | None = None, invalid_comment='', limits: RangeValue | None = None, out_of_limits_comment='', desc='', distribution: Distribution | None = None, scope=Scope.PRIVATE)[source]¶
Bases:
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:
[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¶
validity range of the variable and optional comment if unvalid
- Type:
tuple[Any, Any] or None