fastoad.openmdao.validity_checker module¶
For checking validity domain of OpenMDAO variables.
-
class
fastoad.openmdao.validity_checker.
CheckRecord
(variable_name, status, limit_value, limit_units, value, value_units, source_file, logger_name)¶ Bases:
tuple
A namedtuple that contains result of one variable check
-
property
limit_units
¶ Alias for field number 3
-
property
limit_value
¶ Alias for field number 2
-
property
logger_name
¶ Alias for field number 7
-
property
source_file
¶ Alias for field number 6
-
property
status
¶ Alias for field number 1
-
property
value
¶ Alias for field number 4
-
property
value_units
¶ Alias for field number 5
-
property
variable_name
¶ Alias for field number 0
-
property
-
class
fastoad.openmdao.validity_checker.
ValidityDomainChecker
(limits: Dict[str, tuple] = None, logger_name: str = None)[source]¶ Bases:
object
Decorator class that checks variable values against limit bounds
This class aims at producing a status of out of limits variables at the end of an OpenMDAO computation.
The point is to allow to define limit bounds when defining an OpenMDAO system, but to make the check on the OpenMDAO problem after the run.
When defining an OpenMDAO system, use this class as Python decorator to define validity domains:
@ValidityDomainChecker class MyComponent(om.explicitComponent): ...
The above code will check values against lower and upper bounds that have been defined when adding OpenMDAO outputs.
Next code shows how to define lower and upper bounds, for inputs and/or outputs.
@ValidityDomainChecker( { "a:variable:with:two:bounds": (-10.0, 1.0), "a:variable:with:lower:bound:only": (0.0, None), "a:variable:with:upper:bound:only": (None, 4.2), }, ) class MyComponent(om.explicitComponent): ...
The defined domain limits supersedes lower and upper bounds from OpenMDAO output definitions, but only in the frame of ValidityDomainChecker. In any case, OpenMDAO process is not affected by usage of ValidityDomainChecker.
Validity status can be obtained through log messages from Python logging module after problem has been run with:
... problem.run_model() ValidityDomainChecker.check_problem_variables(problem)
Warnings: - Units of limit values defined in ValidityDomainChecker are assumed to be the
same as in add_input() and add_output() statements of decorated class
Validity check currently only applies to scalar values
- Parameters
limits – a dictionary where keys are variable names and values are two-values tuples that give lower and upper bound. One bound can be set to None.
logger_name – The named of the logger that will be used. If not provided, name of current module (i.e. “__name__””) will be used.
-
classmethod
check_problem_variables
(problem: openmdao.core.problem.Problem)[source]¶ Checks variable values in provided problem and logs warnings for each variable that is out of registered limits.
- Parameters
problem –
- Returns
-
classmethod
check_variables
(variables: fastoad.openmdao.variables.VariableList) → List[fastoad.openmdao.validity_checker.CheckRecord][source]¶ Check values of provided variables against registered limits.
- Parameters
variables –
- Returns
a list of CheckRecord instances
-
static
log_records
(records: List[fastoad.openmdao.validity_checker.CheckRecord])[source]¶ Logs warnings through Python logging module for each CheckRecord in provided list if it is not OK.
- Parameters
records –
- Returns