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
- limit_units
Alias for field number 3
- limit_value
Alias for field number 2
- logger_name
Alias for field number 7
- source_file
Alias for field number 6
- status
Alias for field number 1
- value
Alias for field number 4
- value_units
Alias for field number 5
- variable_name
Alias for field number 0
- class fastoad.openmdao.validity_checker.ValidityStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
Simple enumeration for validity status.
- OK = 0
- TOO_LOW = -1
- TOO_HIGH = 1
- 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: Problem) List[CheckRecord] [source]
Checks variable values in provided problem.
Logs warnings for each variable that is out of registered limits.
problem.setup() must have been run.
- Parameters:
problem –
- Returns:
the list of checks
- classmethod check_variables(variables: VariableList, activated_only: bool = True) List[CheckRecord] [source]
Check values of provided variables against registered limits.
- Parameters:
variables –
activated_only – if True, only activated checkers are considered.
- Returns:
the list of checks
- static log_records(records: List[CheckRecord])[source]
Logs warnings through Python logging module for each CheckRecord in provided list if it is not OK.
- Parameters:
records –
- Returns: