Validation¶
MOSAIC validates data at three layers: Pydantic models for telemetry payloads, a ValidationService for runtime checking with Log Constants structured logging, and UI validators for form fields in the PyQt6 interface.
%%{init: {"flowchart": {"curve": "linear"}} }%%
graph LR
subgraph Pydantic["Pydantic Models"]
TSE["TelemetryEventBase"]
SE["StepEvent"]
EE["EpisodeEvent"]
RSE["RunStartedEvent"]
RCE["RunCompletedEvent"]
TC["TrainingConfig"]
TCU["TrainerControlUpdate"]
SC["SubprocessCommand"]
end
subgraph Service["ValidationService"]
VS["validate_telemetry_event()"]
VTC["validate_training_config()"]
VCU["validate_trainer_control_update()"]
VSD["validate_step_data()"]
end
subgraph UI["UI Validators & Widgets"]
IR["IntRangeValidator"]
FR["FloatRangeValidator"]
NS["NonEmptyStringValidator"]
FP["FilePathValidator"]
VLE["ValidatedLineEdit"]
VSB["ValidatedSpinBox"]
end
Pydantic --> Service
Service -->|"log_constant()"| LOG[":doc:`log_constants`"]
UI --> FORM["PyQt6 Forms"]
style Pydantic fill:#e8f5e9,stroke:#2e8b57,color:#333
style Service fill:#fff3e0,stroke:#e65100,color:#333
style UI fill:#e3f2fd,stroke:#1565c0,color:#333
Pydantic Models¶
Defined in gym_gui/validations/validations_pydantic.py, these models
enforce schema and value constraints on telemetry data flowing through the
Slow Lane:
Model |
Validated fields |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
All models use @field_validator decorators for constraint checking
(non-negative indices, bounded epsilon, enum membership).
ValidationService¶
ValidationService (gym_gui/validations/validations_telemetry.py)
wraps Pydantic validation with Log Constants structured logging:
from gym_gui.validations import ValidationService
validator = ValidationService(strict_mode=False)
event = validator.validate_telemetry_event(raw_data)
# On success → logs LOG_SERVICE_VALIDATION_DEBUG
# On failure → logs LOG_SERVICE_VALIDATION_WARNING (or raises if strict)
Methods:
Method |
Returns |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Modes:
strict_mode=True: raisesValidationErroron any failure. Suitable for CI/test environments.strict_mode=False(default): logs a warning vialog_constant()and returnsNone. Suitable for production where partial data should not crash the pipeline.
The service collects all errors in _validation_errors for later
inspection via get_validation_errors().
UI Validators¶
gym_gui/validations/validations_ui.py provides Qt-friendly validators for
form fields. Each validator returns a ValidationResult(is_valid, message):
Validator |
Rule |
|---|---|
|
Integer within |
|
Float with inclusive bounds. |
|
Non-empty, optional min/max length and regex pattern. |
|
File or directory exists, readable / writable. |
Validated Widgets¶
Custom PyQt6 widgets that integrate validators with real-time feedback:
class ValidatedLineEdit(QtWidgets.QLineEdit):
validation_changed = pyqtSignal(bool)
def is_valid(self) -> bool: ...
def get_error_label(self) -> QtWidgets.QLabel: ...
class ValidatedSpinBox(QtWidgets.QSpinBox):
validation_changed = pyqtSignal(bool)
def is_valid(self) -> bool: ...
def get_error_label(self) -> QtWidgets.QLabel: ...
Both emit validation_changed(bool) on every keystroke/value change
and display inline error labels.
FormValidationState aggregates results across multiple fields, and
ValidationErrorDialog displays collected errors in a PyQt6 dialog.
Helper: create_validated_input_row(label_text, validator, parent, *, placeholder, initial_value)
creates a label + ValidatedLineEdit + error label row.
Worker Form Validators¶
Specialised validators for training configuration forms:
Module |
What it validates |
|---|---|
|
CleanRL Worker dry-run via subprocess execution. |
|
XuanCe Worker worker form fields (backend, algorithm, env). |
|
MARLlib worker form fields. |
Agent Training Form¶
validations_agent_train_form.py validates common training fields via
validate_agent_train_form(inputs: AgentTrainFormInputs) → list[str]:
Field |
Constraint |
|---|---|
|
1 – 1 000 000 |
|
1 – 100 000 |
|
(0, 1] |
|
[0, 1) |
|
(0, 1] |
|
0 – 999 999 |
|
≤ 256 chars |
|
Alphanumeric + underscore + hyphen |
Directory Layout¶
gym_gui/
validations/
__init__.py
validations_pydantic.py # 8 Pydantic models
validations_telemetry.py # ValidationService (strict/lenient)
validations_ui.py # Qt validators, ValidatedLineEdit/SpinBox
validations_agent_train_form.py # Agent training form helpers
validation_cleanrl_worker_form.py # CleanRL-specific validation
validation_xuance_worker_form.py # XuanCe-specific validation
validation_marllib_worker_form.py # MARLlib-specific validation
See Also¶
Log Constants:
LOG_SERVICE_VALIDATION_*codes emitted byValidationService.Application Constants: numeric bounds used by
AgentTrainFormInputs(e.g.,MAX_COUNTER_VALUEfromconstants_core.py).Slow Lane: the telemetry pipeline that passes through
ValidationServicebefore reaching the UI.