Skip to content

Commit 0fb6b36

Browse files
authored
Merge pull request #2 from lguibr/trieye
Trieye
2 parents 5d728e9 + c77fc22 commit 0fb6b36

45 files changed

Lines changed: 9651 additions & 4064 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,6 @@ files/ # Ignore specific directory if generated
156156

157157
# OS generated files
158158
.DS_Store
159-
Thumbs.db
159+
Thumbs.db
160+
.trieye_data
161+
.trieye_data/

.resumed.txt

Lines changed: 8640 additions & 0 deletions
Large diffs are not rendered by default.

MANIFEST.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
# File: MANIFEST.in
32
# File: MANIFEST.in
43
include README.md
54
include LICENSE
@@ -15,12 +14,20 @@ prune alphatriangle/visualization
1514
prune alphatriangle/interaction
1615
# REMOVE MCTS pruning
1716
# prune alphatriangle/mcts
17+
# Remove Trieye-replaced directories
18+
prune alphatriangle/stats
19+
prune alphatriangle/data
1820
# Remove pruned files
1921
global-exclude alphatriangle/app.py
2022
# Remove pruned test directories
2123
prune tests/visualization
2224
prune tests/interaction
2325
# REMOVE MCTS test pruning
2426
# prune tests/mcts
27+
# Remove Trieye-replaced test directories
28+
prune tests/stats
29+
prune tests/data
2530
# Remove pruned core files
26-
global-exclude alphatriangle/rl/core/visual_state_actor.py
31+
global-exclude alphatriangle/rl/core/visual_state_actor.py
32+
# REMOVE test_save_resume.py
33+
global-exclude tests/training/test_save_resume.py

README.md

Lines changed: 64 additions & 58 deletions
Large diffs are not rendered by default.

alphatriangle/cli.py

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# File: alphatriangle/cli.py
12
import logging
23
import shutil
34
import subprocess
@@ -8,9 +9,12 @@
89
from rich.console import Console
910
from rich.panel import Panel
1011

12+
# Import Trieye config
13+
from trieye import PersistenceConfig, TrieyeConfig
14+
1115
# Import alphatriangle specific configs and runner
1216
from alphatriangle.config import (
13-
PersistenceConfig,
17+
APP_NAME, # Use APP_NAME from config
1418
TrainConfig,
1519
)
1620
from alphatriangle.logging_config import setup_logging # Import centralized setup
@@ -61,6 +65,15 @@
6165
),
6266
]
6367

68+
RunNameOption = Annotated[
69+
str | None,
70+
typer.Option(
71+
"--run-name",
72+
help="Specify a custom name for the run (overrides default timestamp).",
73+
),
74+
]
75+
76+
6477
HostOption = Annotated[
6578
str, typer.Option(help="The network address to listen on (default: 127.0.0.1).")
6679
]
@@ -106,7 +119,8 @@ def _run_external_ui(
106119
console.print(
107120
f"[bold red]Error:[/bold red] {ui_name} command failed with exit code {process.returncode}"
108121
)
109-
raise typer.Exit(code=process.returncode)
122+
# Don't exit immediately, let the calling function handle it if needed
123+
# raise typer.Exit(code=process.returncode)
110124
except FileNotFoundError as e:
111125
console.print(
112126
f"[bold red]Error:[/bold red] '{executable}' command not found. Is {ui_name} installed and in your PATH?"
@@ -129,54 +143,64 @@ def train(
129143
log_level: LogLevelOption = "INFO",
130144
seed: SeedOption = 42,
131145
profile: ProfileOption = False,
146+
run_name: RunNameOption = None, # Add run_name option
132147
):
133148
"""
134149
🚀 Run the AlphaTriangle training pipeline (headless).
135150
136-
Initiates the self-play and learning process. Logs will be saved to the run directory.
151+
Initiates the self-play and learning process. Uses Trieye for stats/persistence.
152+
Logs will be saved to the run directory within `.trieye_data/alphatriangle/runs/`.
153+
This command also initializes Ray and starts the Ray Dashboard. Check the logs for the dashboard URL.
137154
"""
138-
# Setup logging using the centralized function (file logging handled by runner)
155+
# Setup logging using the centralized function (file logging handled by Trieye)
139156
setup_logging(log_level)
140157
logging.getLogger(__name__) # Get logger after setup
141158

142-
# Use alphatriangle configs here
159+
# Use alphatriangle TrainConfig
143160
train_config_override = TrainConfig()
144-
persist_config_override = PersistenceConfig()
145161
train_config_override.RANDOM_SEED = seed
146162
train_config_override.PROFILE_WORKERS = profile # Set profile config
147-
# Ensure run name is set for persistence config
148-
persist_config_override.RUN_NAME = train_config_override.RUN_NAME
163+
164+
# Create TrieyeConfig, overriding run_name if provided
165+
trieye_config_override = TrieyeConfig(app_name=APP_NAME)
166+
if run_name:
167+
trieye_config_override.run_name = run_name
168+
# Sync run_name to persistence config within TrieyeConfig
169+
trieye_config_override.persistence.RUN_NAME = run_name
170+
else:
171+
# Use the default factory-generated run_name from TrieyeConfig
172+
run_name = trieye_config_override.run_name
149173

150174
console.print(
151175
Panel(
152-
f"Starting Training Run: '[bold cyan]{train_config_override.RUN_NAME}[/]'\n"
176+
f"Starting Training Run: '[bold cyan]{run_name}[/]'\n"
153177
f"Seed: {seed}, Log Level: {log_level.upper()}, Profiling: {'✅ Enabled' if profile else '❌ Disabled'}",
154178
title="[bold green]Training Setup[/]",
155179
border_style="green",
156180
expand=False,
157181
)
158182
)
159183

160-
# Call the single runner function directly, passing the profile flag
184+
# Call the single runner function directly, passing configs
161185
exit_code = run_training(
162186
log_level_str=log_level,
163187
train_config_override=train_config_override,
164-
persist_config_override=persist_config_override,
188+
trieye_config_override=trieye_config_override,
165189
profile=profile,
166190
)
167191

168192
if exit_code == 0:
169193
console.print(
170194
Panel(
171-
f"✅ Training run '[bold cyan]{train_config_override.RUN_NAME}[/]' completed successfully.",
195+
f"✅ Training run '[bold cyan]{run_name}[/]' completed successfully.",
172196
title="[bold green]Training Finished[/]",
173197
border_style="green",
174198
)
175199
)
176200
else:
177201
console.print(
178202
Panel(
179-
f"❌ Training run '[bold cyan]{train_config_override.RUN_NAME}[/]' failed with exit code {exit_code}.",
203+
f"❌ Training run '[bold cyan]{run_name}[/]' failed with exit code {exit_code}.",
180204
title="[bold red]Training Failed[/]",
181205
border_style="red",
182206
)
@@ -192,11 +216,11 @@ def ml(
192216
"""
193217
📊 Launch the MLflow UI for experiment tracking.
194218
195-
Requires MLflow to be installed. Points to the `.alphatriangle_data/mlruns` directory.
219+
Requires MLflow to be installed. Points to the `.trieye_data/<app_name>/mlruns` directory.
196220
"""
197221
setup_logging("INFO") # Basic logging for this command
198-
persist_config = PersistenceConfig()
199-
# Use the computed property which resolves the path and creates the dir
222+
# Use Trieye's PersistenceConfig to find the path
223+
persist_config = PersistenceConfig(APP_NAME=APP_NAME)
200224
mlflow_uri = persist_config.MLFLOW_TRACKING_URI
201225
mlflow_path = persist_config.get_mlflow_abs_path()
202226

@@ -217,7 +241,15 @@ def ml(
217241
"--port",
218242
str(port),
219243
]
220-
_run_external_ui("mlflow", command_args, "MLflow UI", f"http://{host}:{port}")
244+
try:
245+
_run_external_ui("mlflow", command_args, "MLflow UI", f"http://{host}:{port}")
246+
except typer.Exit as e:
247+
if e.exit_code != 0:
248+
console.print(
249+
f"[yellow]MLflow UI failed to start (Exit Code: {e.exit_code}). "
250+
f"Is port {port} already in use? Try specifying a different port with --port.[/]"
251+
)
252+
sys.exit(e.exit_code)
221253

222254

223255
@app.command()
@@ -228,11 +260,11 @@ def tb(
228260
"""
229261
📈 Launch TensorBoard UI pointing to the runs directory.
230262
231-
Requires TensorBoard to be installed. Points to the `.alphatriangle_data/runs` directory.
263+
Requires TensorBoard to be installed. Points to the `.trieye_data/<app_name>/runs` directory.
232264
"""
233265
setup_logging("INFO") # Basic logging for this command
234-
persist_config = PersistenceConfig()
235-
# Point to the parent directory containing all individual run folders
266+
# Use Trieye's PersistenceConfig to find the path
267+
persist_config = PersistenceConfig(APP_NAME=APP_NAME)
236268
runs_root_dir = persist_config.get_runs_root_dir()
237269

238270
if not runs_root_dir.exists() or not any(runs_root_dir.iterdir()):
@@ -253,38 +285,46 @@ def tb(
253285
"--port",
254286
str(port),
255287
]
256-
_run_external_ui(
257-
"tensorboard", command_args, "TensorBoard UI", f"http://{host}:{port}"
258-
)
288+
try:
289+
_run_external_ui(
290+
"tensorboard", command_args, "TensorBoard UI", f"http://{host}:{port}"
291+
)
292+
except typer.Exit as e:
293+
if e.exit_code != 0:
294+
console.print(
295+
f"[yellow]TensorBoard UI failed to start (Exit Code: {e.exit_code}). "
296+
f"Is port {port} already in use? Try specifying a different port with --port.[/]"
297+
)
298+
sys.exit(e.exit_code)
259299

260300

261301
@app.command()
262302
def ray(
263-
host: HostOption = "127.0.0.1",
303+
host: HostOption = "127.0.0.1", # Keep host/port options for reference
264304
port: PortOption = 8265,
265305
):
266306
"""
267-
☀️ Launch the Ray Dashboard web UI.
307+
☀️ Provides instructions to view the Ray Dashboard.
268308
269-
Requires Ray to be installed and potentially running (e.g., started by `alphatriangle train`).
309+
The dashboard is automatically started when you run `alphatriangle train`.
310+
Check the output logs of the `train` command for the correct URL.
270311
"""
271312
setup_logging("INFO") # Basic logging for this command
272313
console.print(
273-
"[yellow]Note:[/yellow] This command attempts to open the Ray Dashboard for an existing Ray cluster."
274-
)
275-
console.print(
276-
"If Ray is not running, this command might fail. Start Ray first (e.g., via `alphatriangle train`)."
314+
Panel(
315+
f"💡 To view the Ray Dashboard:\n\n"
316+
f"1. The Ray Dashboard is started automatically when you run the `[bold]alphatriangle train[/]` command.\n"
317+
f"2. Check the console output or the log file for the `train` command (located in `.trieye_data/{APP_NAME}/runs/<run_name>/logs/`).\n"
318+
f"3. Look for a line similar to: '[bold cyan]Ray Dashboard running at: http://<address>:<port>[/]' \n"
319+
f"4. Open that specific URL in your web browser.\n\n"
320+
f"[dim]Note: The default URL is often http://{host}:{port}, but it might differ. "
321+
f"If you cannot access the URL, check firewall settings or if the port is blocked.[/]",
322+
title="[bold yellow]Ray Dashboard Instructions[/]",
323+
border_style="yellow",
324+
expand=False,
325+
)
277326
)
278327

279-
command_args = [
280-
"dashboard",
281-
"--host",
282-
host,
283-
"--port",
284-
str(port),
285-
]
286-
_run_external_ui("ray", command_args, "Ray Dashboard", f"http://{host}:{port}")
287-
288328

289329
if __name__ == "__main__":
290330
app()

alphatriangle/config/README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
1-
21
# Configuration Module (`alphatriangle.config`)
32

43
## Purpose and Architecture
54

6-
This module centralizes all configuration parameters for the AlphaTriangle project *except* for the core environment settings. It uses separate **Pydantic models** for different aspects of the application (model, training, persistence, MCTS, **statistics**) to promote modularity, clarity, and automatic validation.
5+
This module centralizes configuration parameters for the AlphaTriangle agent itself, *excluding* statistics logging and data persistence which are now handled by the `trieye` library. It uses separate **Pydantic models** for different aspects of the agent (model, training loop, MCTS) to promote modularity, clarity, and automatic validation.
76

8-
**Core environment configuration (`EnvConfig`) is now defined and imported directly from the `trianglengin` library.**
7+
**Core environment configuration (`EnvConfig`) is imported directly from the `trianglengin` library.**
8+
**Statistics and Persistence configuration (`StatsConfig`, `PersistenceConfig`) are defined and managed within the `trieye` library via `TrieyeConfig`.**
99

1010
- **Modularity:** Separating configurations makes it easier to manage parameters for different components.
1111
- **Type Safety & Validation:** Using Pydantic models (`BaseModel`) provides strong type hinting, automatic parsing, and validation of configuration values based on defined types and constraints (e.g., `Field(gt=0)`).
12-
- **Validation Script:** The [`validation.py`](validation.py) script instantiates all configuration models (including importing and validating `trianglengin.EnvConfig`), triggering Pydantic's validation, and prints a summary.
13-
- **Dynamic Defaults:** Some configurations, like `RUN_NAME` in `TrainConfig`, use `default_factory` for dynamic defaults (e.g., timestamp).
14-
- **Computed Fields:** Properties like `MLFLOW_TRACKING_URI` in `PersistenceConfig` are defined using `@computed_field` for clarity.
15-
- **Tuned Defaults:** The default values in `TrainConfig` and `ModelConfig` are tuned for substantial learning runs. `AlphaTriangleMCTSConfig` defaults to 128 simulations. `StatsConfig` defines a default set of metrics to track.
16-
- **Data Paths:** `PersistenceConfig` defines the structure within the `.alphatriangle_data` directory where all local artifacts (runs, checkpoints, logs, TensorBoard data) and MLflow data (`mlruns`) are stored.
12+
- **Validation Script:** The [`validation.py`](validation.py) script instantiates the AlphaTriangle-specific configuration models (including importing and validating `trianglengin.EnvConfig`), triggering Pydantic's validation, and prints a summary. **Note:** It does *not* validate `TrieyeConfig` directly; `trieye` handles its own validation upon actor initialization.
13+
- **Dynamic Defaults:** Some configurations, like `RUN_NAME` in `TrainConfig`, use `default_factory` for dynamic defaults (e.g., timestamp). This default is often overridden by the `TrieyeConfig` setting.
14+
- **Tuned Defaults:** The default values in `TrainConfig` and `ModelConfig` are tuned for substantial learning runs. `AlphaTriangleMCTSConfig` defaults to 128 simulations.
1715

1816
## Exposed Interfaces
1917

2018
- **Pydantic Models:**
2119
- `EnvConfig` (Imported from `trianglengin`): Environment parameters (grid size, shapes, rewards).
2220
- [`ModelConfig`](model_config.py): Neural network architecture parameters.
2321
- [`TrainConfig`](train_config.py): Training loop hyperparameters (batch size, learning rate, workers, PER settings, etc.).
24-
- [`PersistenceConfig`](persistence_config.py): Data saving/loading parameters (directories within `.alphatriangle_data`, filenames).
2522
- [`AlphaTriangleMCTSConfig`](mcts_config.py): MCTS parameters (simulations, exploration constants, temperature).
26-
- [`StatsConfig`](stats_config.py): Statistics collection and logging parameters (metrics, aggregation, frequency).
2723
- **Constants:**
28-
- [`APP_NAME`](app_config.py): The name of the application.
24+
- [`APP_NAME`](app_config.py): The name of the application (used by `trieye` for namespacing).
2925
- **Functions:**
30-
- `print_config_info_and_validate(mcts_config_instance: AlphaTriangleMCTSConfig | None)`: Validates and prints a summary of all configurations.
26+
- `print_config_info_and_validate(mcts_config_instance: AlphaTriangleMCTSConfig | None)`: Validates and prints a summary of AlphaTriangle-specific configurations.
3127

3228
## Dependencies
3329

@@ -40,4 +36,4 @@ This module primarily defines configurations and relies heavily on **Pydantic**.
4036

4137
---
4238

43-
**Note:** Please keep this README updated when adding, removing, or significantly modifying configuration parameters or the structure of the Pydantic models. Accurate documentation is crucial for maintainability.
39+
**Note:** Please keep this README updated when adding, removing, or significantly modifying configuration parameters or the structure of the Pydantic models within this module.

alphatriangle/config/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
from .app_config import APP_NAME
55
from .mcts_config import AlphaTriangleMCTSConfig
66
from .model_config import ModelConfig
7-
from .persistence_config import PersistenceConfig
8-
from .stats_config import StatsConfig # ADDED
97
from .train_config import TrainConfig
108
from .validation import print_config_info_and_validate
119

1210
__all__ = [
1311
"APP_NAME",
1412
"EnvConfig",
1513
"ModelConfig",
16-
"PersistenceConfig",
1714
"TrainConfig",
1815
"AlphaTriangleMCTSConfig",
19-
"StatsConfig", # ADDED
2016
"print_config_info_and_validate",
2117
]

alphatriangle/config/mcts_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from trimcts import SearchConfiguration # Import base config for reference
99

1010
# Restore default simulations to a lower value for faster testing/profiling
11-
DEFAULT_MAX_SIMULATIONS = 128
12-
DEFAULT_MAX_DEPTH = 16
11+
DEFAULT_MAX_SIMULATIONS = 64
12+
DEFAULT_MAX_DEPTH = 8
1313
DEFAULT_CPUCT = 1.5
1414
DEFAULT_MCTS_BATCH_SIZE = 32 # Default batch size for network evals within MCTS
1515

0 commit comments

Comments
 (0)