Application Constants¶
MOSAIC centralises all tuning knobs, default values, and magic numbers into
a single gym_gui/constants/ package. Every subsystem: from the
Slow Lane queue sizes to the
Rendering Strategies FPS caps: imports its defaults
from here rather than scattering literals across the codebase.
Architecture¶
The package follows a domain-based submodule pattern. Each submodule
is a focused Python file exporting frozen dataclasses and/or module-level
constants. The top-level __init__.py re-exports everything
(160 symbols in __all__) so consumers can write:
from gym_gui.constants import (
OPERATOR_DEFAULTS,
UI_DEFAULTS,
TELEMETRY_HUB_BUFFER_SIZE,
INITIAL_CREDITS,
format_episode_id,
)
Constant Domains¶
Module |
Lines |
Key Exports |
|---|---|---|
|
203 |
|
|
220 |
|
|
122 |
|
|
90 |
|
|
47 |
|
|
97 |
|
|
162 |
|
|
204 |
|
|
54 |
|
|
41 |
|
|
126 |
|
|
22 |
|
|
379 |
|
|
n/a |
Welcome widget strings |
|
n/a |
Dynamic constant discovery |
Rendering Defaults¶
constants_ui.py provides the defaults used by the
Overview subsystem:
@dataclass(frozen=True)
class RenderDefaults:
min_delay_ms: int = 10
max_delay_ms: int = 500
tick_interval_ms: int = 50
default_delay_ms: int = 100 # ~10 FPS for slow lane
queue_size: int = 32 # RenderingSpeedRegulator max
bootstrap_timeout_ms: int = 500
@dataclass(frozen=True)
class UIDefaults:
render: RenderDefaults = RenderDefaults()
sliders: SliderDefaults = SliderDefaults()
buffers: BufferDefaults = BufferDefaults()
layout: LayoutDefaults = LayoutDefaults()
These values directly govern the
Slow Lane RenderingSpeedRegulator
drain interval and queue capacity.
Telemetry Constants¶
constants_telemetry.py defines queue sizes, buffer bounds, and batch
parameters for the Slow Lane pipeline:
Constant |
Value |
Used by |
|---|---|---|
|
64 |
|
|
32 |
|
|
32 |
|
|
2 048 |
|
|
512 |
UI subscriber path |
|
1 024 |
DB subscriber path |
|
64 |
|
|
64 |
|
|
32 |
|
|
4 096 |
|
|
100 000 |
Hub in-memory buffer |
|
256 |
|
|
4 096 |
WAL checkpoint trigger |
|
16 384 |
Writer thread queue |
|
200 |
|
|
10 |
Starvation warning |
|
500 |
Auto-start regulator |
Bus & Credit Defaults¶
constants_telemetry_bus.py wraps related defaults into nested dataclasses:
@dataclass(frozen=True)
class CreditDefaults:
initial_credits: int = 200
starvation_threshold: int = 10
@dataclass(frozen=True)
class BusDefaults:
run_bus: RunBusQueueDefaults = ...
run_events: RunEventDefaults = ...
telemetry_streams: TelemetryStreamDefaults = ...
hub: TelemetryHubDefaults = ...
logging: TelemetryLoggingDefaults = ...
credit: CreditDefaults = ...
These are consumed by the Slow Lane
CreditManager and RunBus.
Operator Constants¶
constants_operator.py defines categories used by the
Operators system:
OPERATOR_CATEGORY_HUMAN = "human"
OPERATOR_CATEGORY_LLM = "llm"
OPERATOR_CATEGORY_RL = "rl"
OPERATOR_CATEGORY_HETEROGENEOUS = "heterogeneous"
It also provides BALROG LLM worker defaults:
Constant |
Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Optional Dependency Gates¶
optional_deps.py provides safe import wrappers that raise clear errors
when an optional library is missing. Seven dependency groups are guarded:
Dependency |
Check |
Require |
|---|---|---|
PyTorch |
|
|
PettingZoo |
|
|
CleanRL |
|
|
ViZDoom |
|
|
Stockfish |
|
|
MuJoCo MPC |
|
|
Godot |
|
|
Each guard uses lazy-loaded flags with caching and raises
OptionalDependencyError with an installation hint.
Type Stubs¶
__init__.pyi provides full type annotations for IDE auto-completion,
since the runtime __init__.py uses dynamic imports.
Directory Layout¶
gym_gui/
constants/
__init__.py # Re-exports 160 symbols
__init__.pyi # Type stubs for IDE support
constants_core.py # Episode IDs, counter bounds
constants_ui.py # Window / render / slider defaults
constants_telemetry.py # Queue sizes, buffer configs
constants_telemetry_bus.py # RunBus queue & credit defaults
constants_telemetry_db.py # SQLite / WAL tuning
constants_trainer.py # gRPC & daemon lifecycle
constants_worker.py # Worker discovery & heartbeat
constants_operator.py # Operator categories, BALROG config
constants_tensorboard.py # TensorBoard log paths
constants_wandb.py # W&B URL builder
constants_replay.py # HDF5 replay storage
constants_vector.py # Vector env metadata
constants_game.py # Legacy game config (dynamic import)
optional_deps.py # Safe optional-dependency gates
loader.py # Dynamic constant discovery
mosaic_welcome.py # Welcome widget strings
README.md # Internal architecture guide
See Also¶
Log Constants:
LogConstantcodes reference specific constant values (e.g.,LOG_TELEMETRY_QUEUE_OVERFLOWusesRUNBUS_DEFAULT_QUEUE_SIZE).Validation: Pydantic models validate payloads whose schema constraints come from these constants.
Slow Lane: the telemetry pipeline whose queue sizes, batch sizes, and credit thresholds are all defined here.