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:
tupleA namedtuple that contains result of one variable check
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- 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:
IntEnumSimple enumeration for validity status.
- OK = 0
- TOO_LOW = -1
- TOO_HIGH = 1
- as_integer_ratio()
Return integer ratio.
Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- bit_count()
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- bit_length()
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- conjugate()
Returns self, the complex conjugate of any int.
- denominator
the denominator of a rational number in lowest terms
- from_bytes(byteorder='big', *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.
- signed
Indicates whether two’s complement is used to represent the integer.
- imag
the imaginary part of a complex number
- numerator
the numerator of a rational number in lowest terms
- real
the real part of a complex number
- to_bytes(length=1, byteorder='big', *, signed=False)
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- class fastoad.openmdao.validity_checker.ValidityDomainChecker(limits: Dict[str, tuple] = None, logger_name: str = None)[source]
Bases:
objectDecorator 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: