epymorph.adrio.validation
ADRIO result validation utilities.
Validator
module-attribute
Validator = Callable[[NDArray], ValidationResult]
The type for a function which validates a numpy result.
ValidationResult
Valid
dataclass
Invalid
dataclass
Invalid(error: str)
Bases: ValidationResult
The result of failing a validation check.
ResultFormat
dataclass
Describes the properties of the expected result of evaluating an ADRIO.
Parameters:
validate_pipe
Creates a validator by chaining multiple other validators. Validators are evaluated
such that they short-circuit on the first invalid result, in which case only that
invalid result is returned. If all validators pass, Valid
is returned.
Parameters:
-
*validators
(Validator
, default:()
) –The validator functions in evaluation order.
Returns:
-
Validator
–A validator function.
validate_numpy
validate_numpy() -> Validator
Creates a validator which checks that the result is a numpy array.
Returns:
-
Validator
–A validator function.
validate_values_in_range
Creates a validator which checks that numeric values fall within the specified range.
Assumes the values are not structured; if you wish to validate structured data
combine this function with a wrapper like on_date_values
or on_structured
.
Parameters:
-
minimum
(int | float | None
) –The minimum valid value, or
None
if there is no minimum. -
maximum
(int | float | None
) –The maximum valid value, or
None
if there is no maximum.
Returns:
-
Validator
–A validator function.
validate_shape
validate_shape_unchecked_arbitrary
Creates a validator which checks the given shape with the special exception that if an axis is specified as -1, any length (one or greater) is permitted. There must still be the same number of dimensions in the result.
Parameters:
Returns:
-
Validator
–A validator function.
validate_dtype
Creates a validator which checks the given dtype.
Assumes the values are not structured; if you wish to validate structured data
combine this function with a wrapper like on_date_values
or on_structured
.
Parameters:
Returns:
-
Validator
–A validator function.
on_date_values
on_structured
Wraps a validator function so that it can check the values of structured arrays. This presumes that the validator can be applied to all elements of the structured array in the same way. That is: it will likely work for homogenous types but not heterogenous types.
Parameters:
-
validator
(Validator
) –The validator function to wrap.
Returns:
-
Validator
–The validator function adapated to work for structured arrays.
validate_result
validate_result(
rformat: ResultFormat, context: Context
) -> Validator
Creates a validator for the given result format declaration. This is a shortcut
for chaining validate_shape
and validate_dtype
.
Assumes the values are not structured; if you wish to validate structured data
combine this function with a wrapper like on_date_values
or on_structured
.
Parameters:
-
rformat
(ResultFormat
) –The expected result format.
-
context
(Context
) –The simulation context.
Returns:
-
Validator
–A validator function.