_validator
Input Validator
This module defines the input validator for the AlphaCube application. It includes a Pydantic Input
class that validates input data for the application's tasks. The input data must adhere to specific format and validation rules.
Validation Rules:
format
attribute must be either 'moves' or 'stickers'.- For 'moves' format, the
scramble
attribute must consist of valid moves. - For 'stickers' format (not implemented), additional validation may be performed.
beam_width
attribute must be a positive integer.extra_depths
attribute must be a non-negative integer.
The ergonomic bias information is optional and not strictly validated.
input_data = {
'format': 'moves',
'scramble': "R U R' U'",
'beam_width': 256,
'extra_depths': 2,
'ergonomic_bias': None
}
validated_input = Input(**input_data)
Input
class Input(BaseModel)
Input validator (& preprocessor) for AlphaCube.
format
The format of the input data. Must be either 'moves' or 'stickers'.
scramble
The scramble data in the specified format.
beam_width
The beam width for the task. Must be a positive integer.
extra_depths
The number of extra depths for the task. Must be a non-negative integer.
ergonomic_bias
Optional ergonomic bias information (not strictly validated).
validate_format
@validator("format")
@classmethod
def validate_format(cls, value: str) -> str
Validate the input format.
Arguments:
value
str - The format value to be validated.
Returns:
str
- The validated format value.
Raises:
ValueError
- If the format is not 'moves' or 'stickers'.
validate_beam_width
@validator("beam_width")
@classmethod
def validate_beam_width(cls, value)
Validate the beam width.
Arguments:
value
- The beam width value to be validated.
Returns:
int
- The validated beam width value.
Raises:
ValueError
- If the beam width is not a positive integer.
validate_extra_depths
@validator("extra_depths")
@classmethod
def validate_extra_depths(cls, value)
Validate the extra depths.
Arguments:
value
- The extra depths value to be validated.
Returns:
int
- The validated extra depths value.
Raises:
ValueError
- If the extra depths value is negative.
validate_scramble
@model_validator(mode="before")
@classmethod
def validate_scramble(cls, values)
Validate & preprocess the scramble data based on the chosen format.
Arguments:
values
dict - The input values.
Returns:
dict
- The input values with validated scramble data.
Raises:
ValueError
- If there are invalid moves in 'scramble' for 'moves' format.ValueError
- If unexpected center-piece configuration in 'scramble' for 'stickers' format (not implemented).