synth-ai 0.2.0__py3-none-any.whl ā 0.2.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synth_ai/__init__.py +28 -2
- synth_ai/core/system.py +4 -0
- synth_ai/environments/__init__.py +35 -0
- synth_ai/environments/environment/__init__.py +1 -0
- synth_ai/environments/environment/artifacts/__init__.py +1 -0
- synth_ai/environments/environment/artifacts/base.py +50 -0
- synth_ai/environments/environment/core.py +22 -0
- synth_ai/environments/environment/db/__init__.py +1 -0
- synth_ai/environments/environment/db/sqlite.py +45 -0
- synth_ai/environments/environment/registry.py +24 -0
- synth_ai/environments/environment/resources/sqlite.py +46 -0
- synth_ai/environments/environment/results.py +1 -0
- synth_ai/environments/environment/rewards/__init__.py +1 -0
- synth_ai/environments/environment/rewards/core.py +28 -0
- synth_ai/environments/environment/shared_engine.py +26 -0
- synth_ai/environments/environment/tools/__init__.py +34 -0
- synth_ai/environments/examples/__init__.py +1 -0
- synth_ai/environments/examples/crafter_classic/__init__.py +8 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_comprehensive_evaluation.py +58 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_evaluation_browser.py +152 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_evaluation_framework.py +1194 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_quick_evaluation.py +51 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_react_agent.py +872 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/crafter_trace_evaluation.py +1412 -0
- synth_ai/environments/examples/crafter_classic/agent_demos/test_crafter_react_agent.py +1110 -0
- synth_ai/environments/examples/crafter_classic/config_logging.py +111 -0
- synth_ai/environments/examples/crafter_classic/engine.py +502 -0
- synth_ai/environments/examples/crafter_classic/engine_deterministic_patch.py +63 -0
- synth_ai/environments/examples/crafter_classic/engine_helpers/action_map.py +5 -0
- synth_ai/environments/examples/crafter_classic/engine_helpers/serialization.py +74 -0
- synth_ai/environments/examples/crafter_classic/environment.py +255 -0
- synth_ai/environments/examples/crafter_classic/taskset.py +228 -0
- synth_ai/environments/examples/enron/agent_demos/test_synth_react.py +535 -0
- synth_ai/environments/examples/enron/art_helpers/email_search_tools.py +156 -0
- synth_ai/environments/examples/enron/art_helpers/local_email_db.py +280 -0
- synth_ai/environments/examples/enron/art_helpers/types_enron.py +24 -0
- synth_ai/environments/examples/enron/engine.py +291 -0
- synth_ai/environments/examples/enron/environment.py +165 -0
- synth_ai/environments/examples/enron/taskset.py +112 -0
- synth_ai/environments/examples/enron/units/keyword_stats.py +111 -0
- synth_ai/environments/examples/enron/units/test_email_index.py +8 -0
- synth_ai/environments/examples/minigrid/__init__.py +48 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_evaluation_framework.py +1188 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_quick_evaluation.py +47 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_react_agent.py +562 -0
- synth_ai/environments/examples/minigrid/agent_demos/minigrid_trace_evaluation.py +220 -0
- synth_ai/environments/examples/minigrid/agent_demos/test_minigrid_react_agent.py +393 -0
- synth_ai/environments/examples/minigrid/engine.py +589 -0
- synth_ai/environments/examples/minigrid/environment.py +274 -0
- synth_ai/environments/examples/minigrid/environment_mapping.py +242 -0
- synth_ai/environments/examples/minigrid/puzzle_loader.py +416 -0
- synth_ai/environments/examples/minigrid/taskset.py +583 -0
- synth_ai/environments/examples/minigrid/units/test_action_behavior.py +226 -0
- synth_ai/environments/examples/minigrid/units/test_debug_messages.py +83 -0
- synth_ai/environments/examples/minigrid/units/test_exploration.py +120 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_engine.py +214 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_environment.py +238 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_environment_mapping.py +301 -0
- synth_ai/environments/examples/minigrid/units/test_minigrid_taskset.py +210 -0
- synth_ai/environments/examples/nethack/__init__.py +7 -0
- synth_ai/environments/examples/nethack/achievements.py +337 -0
- synth_ai/environments/examples/nethack/agent_demos/nethack_evaluation_framework.py +981 -0
- synth_ai/environments/examples/nethack/agent_demos/nethack_quick_evaluation.py +74 -0
- synth_ai/environments/examples/nethack/agent_demos/nethack_react_agent.py +832 -0
- synth_ai/environments/examples/nethack/agent_demos/test_nethack_react_agent.py +1112 -0
- synth_ai/environments/examples/nethack/engine.py +738 -0
- synth_ai/environments/examples/nethack/environment.py +255 -0
- synth_ai/environments/examples/nethack/helpers/__init__.py +42 -0
- synth_ai/environments/examples/nethack/helpers/action_mapping.py +301 -0
- synth_ai/environments/examples/nethack/helpers/nle_wrapper.py +401 -0
- synth_ai/environments/examples/nethack/helpers/observation_utils.py +433 -0
- synth_ai/environments/examples/nethack/helpers/recording_wrapper.py +201 -0
- synth_ai/environments/examples/nethack/helpers/trajectory_recorder.py +268 -0
- synth_ai/environments/examples/nethack/helpers/visualization/replay_viewer.py +308 -0
- synth_ai/environments/examples/nethack/helpers/visualization/visualizer.py +430 -0
- synth_ai/environments/examples/nethack/taskset.py +323 -0
- synth_ai/environments/examples/nethack/units/test_nethack_engine.py +277 -0
- synth_ai/environments/examples/nethack/units/test_nethack_environment.py +281 -0
- synth_ai/environments/examples/nethack/units/test_nethack_taskset.py +213 -0
- synth_ai/environments/examples/nethack/units/test_recording.py +307 -0
- synth_ai/environments/examples/red/__init__.py +7 -0
- synth_ai/environments/examples/red/agent_demos/__init__.py +1 -0
- synth_ai/environments/examples/red/agent_demos/test_synth_react.py +1471 -0
- synth_ai/environments/examples/red/config_logging.py +110 -0
- synth_ai/environments/examples/red/engine.py +693 -0
- synth_ai/environments/examples/red/engine_helpers/__init__.py +1 -0
- synth_ai/environments/examples/red/engine_helpers/memory_map.py +28 -0
- synth_ai/environments/examples/red/engine_helpers/reward_components.py +275 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/__init__.py +142 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/adaptive_rewards.py +56 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/battle_rewards.py +283 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/composite_rewards.py +149 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/economy_rewards.py +137 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/efficiency_rewards.py +56 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/exploration_rewards.py +330 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/novelty_rewards.py +120 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/pallet_town_rewards.py +558 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/pokemon_rewards.py +312 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/social_rewards.py +147 -0
- synth_ai/environments/examples/red/engine_helpers/reward_library/story_rewards.py +246 -0
- synth_ai/environments/examples/red/engine_helpers/screen_analysis.py +367 -0
- synth_ai/environments/examples/red/engine_helpers/state_extraction.py +139 -0
- synth_ai/environments/examples/red/environment.py +235 -0
- synth_ai/environments/examples/red/taskset.py +77 -0
- synth_ai/environments/examples/red/test_fixes.py +125 -0
- synth_ai/environments/examples/red/test_fixes_mock.py +148 -0
- synth_ai/environments/examples/red/units/__init__.py +1 -0
- synth_ai/environments/examples/red/units/test_basic_functionality.py +97 -0
- synth_ai/environments/examples/red/units/test_button_press_requirements.py +217 -0
- synth_ai/environments/examples/red/units/test_engine.py +192 -0
- synth_ai/environments/examples/red/units/test_environment.py +455 -0
- synth_ai/environments/examples/red/units/test_exploration_strategy.py +227 -0
- synth_ai/environments/examples/red/units/test_integration.py +217 -0
- synth_ai/environments/examples/red/units/test_memory_extraction.py +111 -0
- synth_ai/environments/examples/red/units/test_menu_bug_reproduction.py +1100 -0
- synth_ai/environments/examples/red/units/test_movement_debug.py +255 -0
- synth_ai/environments/examples/red/units/test_pokemon_mcts_debug.py +163 -0
- synth_ai/environments/examples/red/units/test_pokemon_mcts_verbose.py +117 -0
- synth_ai/environments/examples/red/units/test_red_basic.py +145 -0
- synth_ai/environments/examples/red/units/test_red_comprehensive.py +323 -0
- synth_ai/environments/examples/red/units/test_retry_movement.py +195 -0
- synth_ai/environments/examples/red/units/test_reward_components.py +186 -0
- synth_ai/environments/examples/red/units/test_rom_integration.py +260 -0
- synth_ai/environments/examples/red/units/test_taskset.py +116 -0
- synth_ai/environments/examples/red/units/test_tree.py +448 -0
- synth_ai/environments/examples/sokoban/__init__.py +1 -0
- synth_ai/environments/examples/sokoban/agent_demos/sokoban_full_eval.py +900 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_dspy_react.py +1 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_sokoban_react_agent.py +498 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_synth_lats.py +1 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_synth_react_locally.py +748 -0
- synth_ai/environments/examples/sokoban/agent_demos/test_synth_react_service.py +296 -0
- synth_ai/environments/examples/sokoban/engine.py +675 -0
- synth_ai/environments/examples/sokoban/engine_helpers/__init__.py +1 -0
- synth_ai/environments/examples/sokoban/engine_helpers/room_utils.py +656 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/__init__.py +17 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/__init__.py +3 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/boxoban_env.py +129 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/render_utils.py +370 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/room_utils.py +331 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env.py +305 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_fixed_targets.py +66 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_pull.py +114 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_two_player.py +122 -0
- synth_ai/environments/examples/sokoban/engine_helpers/vendored/envs/sokoban_env_variations.py +394 -0
- synth_ai/environments/examples/sokoban/environment.py +228 -0
- synth_ai/environments/examples/sokoban/generate_verified_puzzles.py +438 -0
- synth_ai/environments/examples/sokoban/puzzle_loader.py +311 -0
- synth_ai/environments/examples/sokoban/taskset.py +425 -0
- synth_ai/environments/examples/sokoban/units/astar_common.py +94 -0
- synth_ai/environments/examples/sokoban/units/test_building_task_set.py +49 -0
- synth_ai/environments/examples/sokoban/units/test_false_positive.py +120 -0
- synth_ai/environments/examples/sokoban/units/test_simple_run_through_environment.py +119 -0
- synth_ai/environments/examples/sokoban/units/test_sokoban_environment.py +98 -0
- synth_ai/environments/examples/sokoban/units/test_tree.py +364 -0
- synth_ai/environments/examples/tictactoe/__init__.py +1 -0
- synth_ai/environments/examples/tictactoe/agent_demos/test_synth_react.py +266 -0
- synth_ai/environments/examples/tictactoe/agent_demos/test_tictactoe_react_agent.py +470 -0
- synth_ai/environments/examples/tictactoe/engine.py +368 -0
- synth_ai/environments/examples/tictactoe/environment.py +239 -0
- synth_ai/environments/examples/tictactoe/taskset.py +214 -0
- synth_ai/environments/examples/tictactoe/units/test_tictactoe_engine.py +393 -0
- synth_ai/environments/examples/tictactoe/units/test_tictactoe_environment.py +493 -0
- synth_ai/environments/examples/tictactoe/units/test_tictactoe_taskset.py +191 -0
- synth_ai/environments/examples/verilog/__init__.py +10 -0
- synth_ai/environments/examples/verilog/agent_demos/test_synth_react.py +520 -0
- synth_ai/environments/examples/verilog/engine.py +328 -0
- synth_ai/environments/examples/verilog/environment.py +349 -0
- synth_ai/environments/examples/verilog/taskset.py +418 -0
- synth_ai/environments/examples/verilog/units/test_verilog_engine.py +466 -0
- synth_ai/environments/examples/verilog/units/test_verilog_environment.py +585 -0
- synth_ai/environments/examples/verilog/units/test_verilog_integration.py +383 -0
- synth_ai/environments/examples/verilog/units/test_verilog_taskset.py +457 -0
- synth_ai/environments/reproducibility/core.py +42 -0
- synth_ai/environments/reproducibility/tree.py +364 -0
- synth_ai/environments/service/app.py +78 -0
- synth_ai/environments/service/core_routes.py +775 -0
- synth_ai/environments/service/external_registry.py +57 -0
- synth_ai/environments/service/registry.py +9 -0
- synth_ai/environments/stateful/__init__.py +1 -0
- synth_ai/environments/stateful/core.py +28 -0
- synth_ai/environments/stateful/engine.py +21 -0
- synth_ai/environments/stateful/state.py +7 -0
- synth_ai/environments/tasks/api.py +19 -0
- synth_ai/environments/tasks/core.py +78 -0
- synth_ai/environments/tasks/filters.py +39 -0
- synth_ai/environments/tasks/utils.py +89 -0
- synth_ai/environments/v0_observability/history.py +3 -0
- synth_ai/environments/v0_observability/log.py +2 -0
- synth_ai/lm/caching/constants.py +1 -0
- synth_ai/{zyk/lms ā lm}/caching/ephemeral.py +4 -8
- synth_ai/{zyk/lms ā lm}/caching/handler.py +15 -15
- synth_ai/{zyk/lms ā lm}/caching/initialize.py +2 -4
- synth_ai/{zyk/lms ā lm}/caching/persistent.py +4 -10
- synth_ai/{zyk/lms ā lm}/config.py +2 -1
- synth_ai/{zyk/lms ā lm}/constants.py +2 -2
- synth_ai/{zyk/lms ā lm}/core/all.py +10 -10
- synth_ai/{zyk/lms ā lm}/core/main.py +57 -33
- synth_ai/{zyk/lms ā lm}/core/vendor_clients.py +12 -10
- synth_ai/lm/cost/monitor.py +1 -0
- synth_ai/lm/cost/statefulness.py +1 -0
- synth_ai/lm/provider_support/__init__.py +8 -0
- synth_ai/lm/provider_support/anthropic.py +945 -0
- synth_ai/lm/provider_support/openai.py +1115 -0
- synth_ai/lm/provider_support/suppress_logging.py +31 -0
- synth_ai/{zyk/lms ā lm}/structured_outputs/handler.py +58 -80
- synth_ai/{zyk/lms ā lm}/structured_outputs/inject.py +6 -20
- synth_ai/{zyk/lms ā lm}/structured_outputs/rehabilitate.py +6 -12
- synth_ai/{zyk/lms ā lm}/vendors/core/anthropic_api.py +21 -30
- synth_ai/{zyk/lms ā lm}/vendors/core/gemini_api.py +35 -32
- synth_ai/{zyk/lms ā lm}/vendors/core/mistral_api.py +19 -28
- synth_ai/{zyk/lms ā lm}/vendors/core/openai_api.py +26 -36
- synth_ai/{zyk/lms ā lm}/vendors/openai_standard.py +29 -33
- synth_ai/{zyk/lms ā lm}/vendors/retries.py +1 -1
- synth_ai/lm/vendors/supported/__init__.py +0 -0
- synth_ai/{zyk/lms ā lm}/vendors/supported/custom_endpoint.py +131 -118
- synth_ai/{zyk/lms ā lm}/vendors/supported/deepseek.py +4 -8
- synth_ai/{zyk/lms ā lm}/vendors/supported/grok.py +6 -8
- synth_ai/{zyk/lms ā lm}/vendors/supported/groq.py +1 -1
- synth_ai/{zyk/lms ā lm}/vendors/supported/ollama.py +2 -2
- synth_ai/{zyk/lms ā lm}/vendors/supported/openrouter.py +18 -16
- synth_ai/{zyk/lms ā lm}/vendors/supported/together.py +1 -1
- synth_ai/tracing/__init__.py +0 -0
- synth_ai/tracing/abstractions.py +224 -0
- synth_ai/tracing/base_client.py +91 -0
- synth_ai/tracing/client_manager.py +131 -0
- synth_ai/tracing/config.py +140 -0
- synth_ai/tracing/context.py +146 -0
- synth_ai/tracing/decorators.py +679 -0
- synth_ai/tracing/events/__init__.py +0 -0
- synth_ai/tracing/events/manage.py +147 -0
- synth_ai/tracing/events/scope.py +86 -0
- synth_ai/tracing/events/store.py +227 -0
- synth_ai/tracing/immediate_client.py +152 -0
- synth_ai/tracing/local.py +18 -0
- synth_ai/tracing/log_client_base.py +74 -0
- synth_ai/tracing/retry_queue.py +187 -0
- synth_ai/tracing/trackers.py +515 -0
- synth_ai/tracing/upload.py +504 -0
- synth_ai/tracing/utils.py +9 -0
- synth_ai/zyk/__init__.py +28 -2
- synth_ai-0.2.1.dev0.dist-info/METADATA +349 -0
- synth_ai-0.2.1.dev0.dist-info/RECORD +261 -0
- {synth_ai-0.2.0.dist-info ā synth_ai-0.2.1.dev0.dist-info}/WHEEL +1 -1
- synth_ai/zyk/lms/caching/constants.py +0 -1
- synth_ai/zyk/lms/cost/monitor.py +0 -1
- synth_ai/zyk/lms/cost/statefulness.py +0 -1
- synth_ai-0.2.0.dist-info/METADATA +0 -36
- synth_ai-0.2.0.dist-info/RECORD +0 -50
- /synth_ai/{zyk/lms/__init__.py ā environments/reproducibility/helpers.py} +0 -0
- /synth_ai/{zyk/lms/caching ā lm}/__init__.py +0 -0
- /synth_ai/{zyk/lms/core ā lm/caching}/__init__.py +0 -0
- /synth_ai/{zyk/lms ā lm}/caching/dbs.py +0 -0
- /synth_ai/{zyk/lms/cost ā lm/core}/__init__.py +0 -0
- /synth_ai/{zyk/lms ā lm}/core/exceptions.py +0 -0
- /synth_ai/{zyk/lms/structured_outputs ā lm/cost}/__init__.py +0 -0
- /synth_ai/{zyk/lms/vendors ā lm/structured_outputs}/__init__.py +0 -0
- /synth_ai/{zyk/lms ā lm}/tools/__init__.py +0 -0
- /synth_ai/{zyk/lms ā lm}/tools/base.py +0 -0
- /synth_ai/{zyk/lms/vendors/core ā lm/vendors}/__init__.py +0 -0
- /synth_ai/{zyk/lms ā lm}/vendors/base.py +0 -0
- /synth_ai/{zyk/lms/vendors/local ā lm/vendors/core}/__init__.py +0 -0
- /synth_ai/{zyk/lms/vendors/supported ā lm/vendors/local}/__init__.py +0 -0
- /synth_ai/{zyk/lms ā lm}/vendors/local/ollama.py +0 -0
- {synth_ai-0.2.0.dist-info ā synth_ai-0.2.1.dev0.dist-info/licenses}/LICENSE +0 -0
- {synth_ai-0.2.0.dist-info ā synth_ai-0.2.1.dev0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,900 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
Comprehensive Sokoban evaluation framework with trace generation.
|
4
|
+
Generates proper trace files for the Streamlit viewer.
|
5
|
+
"""
|
6
|
+
|
7
|
+
import asyncio
|
8
|
+
import json
|
9
|
+
import uuid
|
10
|
+
from pathlib import Path
|
11
|
+
from datetime import datetime
|
12
|
+
from typing import Dict, Any, List, Optional
|
13
|
+
from dataclasses import dataclass, asdict
|
14
|
+
import time
|
15
|
+
import os
|
16
|
+
|
17
|
+
from synth_ai.zyk import LM
|
18
|
+
from synth_sdk.tracing.decorators import trace_event_async
|
19
|
+
from synth_sdk.tracing.abstractions import (
|
20
|
+
RewardSignal,
|
21
|
+
Dataset,
|
22
|
+
TrainingQuestion,
|
23
|
+
EventPartitionElement,
|
24
|
+
SystemTrace,
|
25
|
+
)
|
26
|
+
from synth_sdk.tracing.utils import get_system_id
|
27
|
+
|
28
|
+
from synth_ai.environments.examples.sokoban.environment import SokobanEnvironment
|
29
|
+
from synth_ai.environments.examples.sokoban.taskset import (
|
30
|
+
SokobanTaskInstance,
|
31
|
+
SokobanTaskInstanceMetadata,
|
32
|
+
)
|
33
|
+
from synth_ai.environments.examples.sokoban.engine import _grid_to_text, ACTION_STRING_TO_INT
|
34
|
+
from synth_ai.environments.examples.sokoban.engine_helpers.room_utils import (
|
35
|
+
generate_room,
|
36
|
+
get_shortest_action_path,
|
37
|
+
)
|
38
|
+
from synth_ai.environments.tasks.core import Impetus, Intent
|
39
|
+
from synth_ai.environments.environment.tools import EnvToolCall
|
40
|
+
|
41
|
+
from test_synth_react_locally import (
|
42
|
+
ReActAgent,
|
43
|
+
HistoryObservationCallable,
|
44
|
+
format_obs_for_llm_from_states,
|
45
|
+
SokobanInteractArgs,
|
46
|
+
Move,
|
47
|
+
AgentDecisionRecord,
|
48
|
+
)
|
49
|
+
|
50
|
+
|
51
|
+
@dataclass
|
52
|
+
class SokobanTrajectoryResult:
|
53
|
+
"""Result from a single Sokoban trajectory."""
|
54
|
+
|
55
|
+
trajectory_id: str
|
56
|
+
model_name: str
|
57
|
+
difficulty: str
|
58
|
+
seed: int
|
59
|
+
success: bool
|
60
|
+
final_reward: float
|
61
|
+
num_steps: int
|
62
|
+
boxes_solved: int
|
63
|
+
total_boxes: int
|
64
|
+
trace_file_path: str
|
65
|
+
metadata: Dict[str, Any]
|
66
|
+
|
67
|
+
|
68
|
+
class SokobanEvalFramework:
|
69
|
+
"""Comprehensive evaluation framework for Sokoban with trace generation."""
|
70
|
+
|
71
|
+
def __init__(self):
|
72
|
+
self.trajectory_results: List[SokobanTrajectoryResult] = []
|
73
|
+
|
74
|
+
async def run_single_trajectory_with_trace(
|
75
|
+
self,
|
76
|
+
model_name: str,
|
77
|
+
difficulty: str,
|
78
|
+
seed: int,
|
79
|
+
max_turns: int = 20,
|
80
|
+
collect_detailed_data: bool = True,
|
81
|
+
eval_dir: Path = None,
|
82
|
+
) -> SokobanTrajectoryResult:
|
83
|
+
"""Run a single trajectory with comprehensive trace capture."""
|
84
|
+
|
85
|
+
# Generate Sokoban instance
|
86
|
+
difficulty_configs = {
|
87
|
+
"ultra-easy": {"target_len": 1, "dim": (5, 5), "boxes": 1},
|
88
|
+
"easy": {"target_len": 3, "dim": (5, 5), "boxes": 1},
|
89
|
+
"medium": {"target_len": 5, "dim": (6, 6), "boxes": 1},
|
90
|
+
"hard": {"target_len": 7, "dim": (7, 7), "boxes": 2},
|
91
|
+
}
|
92
|
+
|
93
|
+
config = difficulty_configs.get(difficulty, difficulty_configs["easy"])
|
94
|
+
|
95
|
+
# Generate room
|
96
|
+
room_structure, room_state, _, _ = generate_room(
|
97
|
+
dim=config["dim"],
|
98
|
+
initial_seed=seed,
|
99
|
+
num_boxes=config["boxes"],
|
100
|
+
search_depth=max(10, config["target_len"] + 2),
|
101
|
+
)
|
102
|
+
|
103
|
+
# Convert numpy arrays to lists for JSON serialization
|
104
|
+
room_structure = room_structure.tolist()
|
105
|
+
room_state = room_state.tolist()
|
106
|
+
|
107
|
+
# Create task instance
|
108
|
+
metadata = SokobanTaskInstanceMetadata(
|
109
|
+
difficulty=difficulty,
|
110
|
+
num_boxes=config["boxes"],
|
111
|
+
dim_room=config["dim"],
|
112
|
+
max_steps=max_turns,
|
113
|
+
shortest_path_length=config["target_len"],
|
114
|
+
seed=seed,
|
115
|
+
generation_params=f"dim={config['dim']}, boxes={config['boxes']}, steps={max_turns}",
|
116
|
+
)
|
117
|
+
|
118
|
+
instance = SokobanTaskInstance(
|
119
|
+
id=uuid.uuid4(),
|
120
|
+
impetus=Impetus(
|
121
|
+
instructions="Solve this Sokoban puzzle by pushing all boxes onto targets."
|
122
|
+
),
|
123
|
+
intent=Intent(rubric={}, gold_trajectories=None, gold_state_diff={}),
|
124
|
+
metadata=metadata,
|
125
|
+
is_reproducible=True,
|
126
|
+
initial_engine_snapshot={
|
127
|
+
"dim_room": config["dim"],
|
128
|
+
"room_fixed": room_structure,
|
129
|
+
"room_state": room_state,
|
130
|
+
"boxes_on_target": 0,
|
131
|
+
"max_steps": max_turns,
|
132
|
+
"num_boxes": config["boxes"],
|
133
|
+
},
|
134
|
+
)
|
135
|
+
|
136
|
+
# Setup environment and agent
|
137
|
+
hist_cb = HistoryObservationCallable(max_history=1)
|
138
|
+
env = SokobanEnvironment(instance, custom_step_obs=hist_cb)
|
139
|
+
|
140
|
+
llm = LM(model_name=model_name, formatting_model_name=model_name, temperature=0.0)
|
141
|
+
agent = ReActAgent(llm, max_turns=max_turns)
|
142
|
+
|
143
|
+
# Initialize tracking
|
144
|
+
trajectory_id = str(uuid.uuid4())
|
145
|
+
turn_count = 0
|
146
|
+
actions_per_turn = []
|
147
|
+
turn_by_turn_data = [] if collect_detailed_data else None
|
148
|
+
partition_index = 0
|
149
|
+
|
150
|
+
# Initialize environment
|
151
|
+
obs_payload = await env.initialize()
|
152
|
+
if "error" in obs_payload:
|
153
|
+
raise Exception(f"Environment initialization failed: {obs_payload['error']}")
|
154
|
+
|
155
|
+
# Record initial turn before any agent action
|
156
|
+
initial_pub_state = obs_payload["public"]
|
157
|
+
initial_priv_state = obs_payload["private"]
|
158
|
+
initial_turn_data = {
|
159
|
+
"turn_number": 0,
|
160
|
+
"room_text": _grid_to_text(initial_pub_state.room_state),
|
161
|
+
"player_position": [int(x) for x in initial_pub_state.player_position],
|
162
|
+
"boxes_on_target": int(initial_pub_state.boxes_on_target),
|
163
|
+
"num_steps": int(initial_pub_state.num_steps),
|
164
|
+
"last_action": "Initial",
|
165
|
+
"terminated": bool(initial_priv_state.terminated),
|
166
|
+
"truncated": bool(initial_priv_state.truncated),
|
167
|
+
"reward": float(initial_priv_state.reward_last),
|
168
|
+
"total_reward": float(initial_priv_state.total_reward),
|
169
|
+
"action_taken": -1,
|
170
|
+
"action_name": "initial",
|
171
|
+
}
|
172
|
+
if collect_detailed_data:
|
173
|
+
turn_by_turn_data.append(initial_turn_data)
|
174
|
+
partition_index = 0
|
175
|
+
event_partition_initial = EventPartitionElement(
|
176
|
+
partition_index=partition_index,
|
177
|
+
events=[
|
178
|
+
{
|
179
|
+
"event_type": "sokoban_turn",
|
180
|
+
"event_metadata": {
|
181
|
+
"turn_number": 0,
|
182
|
+
"turn_data": initial_turn_data,
|
183
|
+
},
|
184
|
+
"environment_compute_steps": [
|
185
|
+
{
|
186
|
+
"compute_output": [
|
187
|
+
{
|
188
|
+
"outputs": {
|
189
|
+
"room_text": initial_turn_data["room_text"],
|
190
|
+
"action": -1,
|
191
|
+
"action_name": "initial",
|
192
|
+
"player_position": initial_turn_data["player_position"],
|
193
|
+
"boxes_on_target": initial_turn_data["boxes_on_target"],
|
194
|
+
"num_steps": initial_turn_data["num_steps"],
|
195
|
+
"reward": initial_turn_data["reward"],
|
196
|
+
"terminated": initial_turn_data["terminated"],
|
197
|
+
"truncated": initial_turn_data["truncated"],
|
198
|
+
}
|
199
|
+
}
|
200
|
+
]
|
201
|
+
}
|
202
|
+
],
|
203
|
+
}
|
204
|
+
],
|
205
|
+
)
|
206
|
+
partition_index += 1
|
207
|
+
|
208
|
+
agent.last_obs_dict = {
|
209
|
+
"terminated": obs_payload["private"].terminated,
|
210
|
+
"boxes_on_target": obs_payload["public"].boxes_on_target,
|
211
|
+
}
|
212
|
+
agent.num_total_boxes = obs_payload["public"].num_boxes
|
213
|
+
|
214
|
+
try:
|
215
|
+
while turn_count < max_turns:
|
216
|
+
turn_count += 1
|
217
|
+
|
218
|
+
current_formatted_obs = format_obs_for_llm_from_states(
|
219
|
+
obs_payload["public"], obs_payload["private"]
|
220
|
+
)
|
221
|
+
|
222
|
+
# Get current game state for trace
|
223
|
+
pub_state = obs_payload["public"]
|
224
|
+
priv_state = obs_payload["private"]
|
225
|
+
|
226
|
+
# Create turn data
|
227
|
+
turn_data = {
|
228
|
+
"turn_number": turn_count,
|
229
|
+
"room_text": _grid_to_text(pub_state.room_state),
|
230
|
+
"player_position": [int(x) for x in pub_state.player_position],
|
231
|
+
"boxes_on_target": int(pub_state.boxes_on_target),
|
232
|
+
"num_steps": int(pub_state.num_steps),
|
233
|
+
"last_action": pub_state.last_action_name,
|
234
|
+
"terminated": priv_state.terminated,
|
235
|
+
"truncated": priv_state.truncated,
|
236
|
+
"reward": float(priv_state.reward_last),
|
237
|
+
"total_reward": float(priv_state.total_reward),
|
238
|
+
}
|
239
|
+
|
240
|
+
# Agent decision - get full reasoning record
|
241
|
+
decision_record = await agent.decide(current_formatted_obs)
|
242
|
+
action_int = decision_record.action_int
|
243
|
+
|
244
|
+
if action_int == -1: # Agent terminated
|
245
|
+
break
|
246
|
+
|
247
|
+
# Execute action
|
248
|
+
obs_payload_next = await env.step([Move(action_int)])
|
249
|
+
|
250
|
+
if "error" in obs_payload_next:
|
251
|
+
break
|
252
|
+
|
253
|
+
# Update turn data with action taken
|
254
|
+
turn_data["action_taken"] = action_int
|
255
|
+
turn_data["action_name"] = (
|
256
|
+
list(ACTION_STRING_TO_INT.keys())[
|
257
|
+
list(ACTION_STRING_TO_INT.values()).index(action_int)
|
258
|
+
]
|
259
|
+
if action_int in ACTION_STRING_TO_INT.values()
|
260
|
+
else f"unknown_{action_int}"
|
261
|
+
)
|
262
|
+
|
263
|
+
# Store detailed turn data
|
264
|
+
if collect_detailed_data:
|
265
|
+
turn_by_turn_data.append(turn_data)
|
266
|
+
|
267
|
+
# Create event partition for this turn with BOTH agent and environment compute steps
|
268
|
+
event_partition = EventPartitionElement(
|
269
|
+
partition_index=partition_index,
|
270
|
+
events=[
|
271
|
+
{
|
272
|
+
"event_type": "sokoban_turn",
|
273
|
+
"event_metadata": {
|
274
|
+
"turn_number": turn_count,
|
275
|
+
"boxes_on_target": pub_state.boxes_on_target,
|
276
|
+
"total_boxes": pub_state.num_boxes,
|
277
|
+
"action_taken": turn_data["action_name"],
|
278
|
+
"player_position": turn_data["player_position"],
|
279
|
+
},
|
280
|
+
"agent_compute_step": {
|
281
|
+
"event_order": 1,
|
282
|
+
"compute_began": datetime.now().isoformat(),
|
283
|
+
"compute_ended": datetime.now().isoformat(),
|
284
|
+
"model_name": decision_record.model_name,
|
285
|
+
"model_params": {"temperature": 0.0},
|
286
|
+
"compute_input": [{"messages": decision_record.input_messages}],
|
287
|
+
"compute_output": [{"messages": decision_record.output_messages}],
|
288
|
+
},
|
289
|
+
"environment_compute_steps": [
|
290
|
+
{
|
291
|
+
"event_order": 2,
|
292
|
+
"compute_began": datetime.now().isoformat(),
|
293
|
+
"compute_ended": datetime.now().isoformat(),
|
294
|
+
"compute_input": [
|
295
|
+
{
|
296
|
+
"action": action_int,
|
297
|
+
"action_name": turn_data["action_name"],
|
298
|
+
}
|
299
|
+
],
|
300
|
+
"compute_output": [
|
301
|
+
{
|
302
|
+
"outputs": {
|
303
|
+
"room_text": turn_data["room_text"],
|
304
|
+
"action": action_int,
|
305
|
+
"action_name": turn_data["action_name"],
|
306
|
+
"player_position": turn_data["player_position"],
|
307
|
+
"boxes_on_target": turn_data["boxes_on_target"],
|
308
|
+
"num_steps": turn_data["num_steps"],
|
309
|
+
"reward": turn_data["reward"],
|
310
|
+
"terminated": turn_data["terminated"],
|
311
|
+
"truncated": turn_data["truncated"],
|
312
|
+
}
|
313
|
+
}
|
314
|
+
],
|
315
|
+
}
|
316
|
+
],
|
317
|
+
}
|
318
|
+
],
|
319
|
+
)
|
320
|
+
|
321
|
+
actions_per_turn.append(action_int)
|
322
|
+
partition_index += 1
|
323
|
+
|
324
|
+
# Update for next iteration
|
325
|
+
obs_payload = obs_payload_next
|
326
|
+
agent.last_obs_dict = {
|
327
|
+
"terminated": obs_payload["private"].terminated,
|
328
|
+
"boxes_on_target": obs_payload["public"].boxes_on_target,
|
329
|
+
}
|
330
|
+
|
331
|
+
# Check termination - if terminated, record final state
|
332
|
+
if obs_payload["private"].terminated or obs_payload["private"].truncated:
|
333
|
+
# Record final state after the terminating action
|
334
|
+
final_pub_state = obs_payload["public"]
|
335
|
+
final_priv_state = obs_payload["private"]
|
336
|
+
|
337
|
+
final_turn_data = {
|
338
|
+
"turn_number": turn_count + 1,
|
339
|
+
"room_text": _grid_to_text(final_pub_state.room_state),
|
340
|
+
"player_position": [int(x) for x in final_pub_state.player_position],
|
341
|
+
"boxes_on_target": int(final_pub_state.boxes_on_target),
|
342
|
+
"num_steps": int(final_pub_state.num_steps),
|
343
|
+
"last_action": final_pub_state.last_action_name,
|
344
|
+
"terminated": final_priv_state.terminated,
|
345
|
+
"truncated": final_priv_state.truncated,
|
346
|
+
"reward": float(final_priv_state.reward_last),
|
347
|
+
"total_reward": float(final_priv_state.total_reward),
|
348
|
+
"action_taken": -1, # No action taken in final state
|
349
|
+
"action_name": "final_state",
|
350
|
+
}
|
351
|
+
|
352
|
+
if collect_detailed_data:
|
353
|
+
turn_by_turn_data.append(final_turn_data)
|
354
|
+
|
355
|
+
# Create event partition for final state
|
356
|
+
final_event_partition = EventPartitionElement(
|
357
|
+
partition_index=partition_index,
|
358
|
+
events=[
|
359
|
+
{
|
360
|
+
"event_type": "sokoban_turn",
|
361
|
+
"event_metadata": {
|
362
|
+
"turn_number": turn_count + 1,
|
363
|
+
"turn_data": final_turn_data,
|
364
|
+
},
|
365
|
+
"environment_compute_steps": [
|
366
|
+
{
|
367
|
+
"compute_output": [
|
368
|
+
{
|
369
|
+
"outputs": {
|
370
|
+
"room_text": final_turn_data["room_text"],
|
371
|
+
"action": -1,
|
372
|
+
"action_name": "final_state",
|
373
|
+
"player_position": final_turn_data[
|
374
|
+
"player_position"
|
375
|
+
],
|
376
|
+
"boxes_on_target": final_turn_data[
|
377
|
+
"boxes_on_target"
|
378
|
+
],
|
379
|
+
"num_steps": final_turn_data["num_steps"],
|
380
|
+
"reward": final_turn_data["reward"],
|
381
|
+
"terminated": final_turn_data["terminated"],
|
382
|
+
"truncated": final_turn_data["truncated"],
|
383
|
+
}
|
384
|
+
}
|
385
|
+
]
|
386
|
+
}
|
387
|
+
],
|
388
|
+
}
|
389
|
+
],
|
390
|
+
)
|
391
|
+
partition_index += 1
|
392
|
+
break
|
393
|
+
|
394
|
+
except Exception as e:
|
395
|
+
print(f"Error during trajectory execution: {e}")
|
396
|
+
|
397
|
+
# Final state
|
398
|
+
final_private_state = obs_payload["private"]
|
399
|
+
final_public_state = obs_payload["public"]
|
400
|
+
|
401
|
+
success = bool(final_public_state.boxes_on_target == final_public_state.num_boxes)
|
402
|
+
final_reward = float(final_private_state.total_reward)
|
403
|
+
num_steps = int(final_public_state.num_steps)
|
404
|
+
|
405
|
+
# Create trace data
|
406
|
+
trace_data = {
|
407
|
+
"trace": {
|
408
|
+
"metadata": {
|
409
|
+
"model_name": model_name,
|
410
|
+
"difficulty": difficulty,
|
411
|
+
"seed": seed,
|
412
|
+
"trajectory_id": trajectory_id,
|
413
|
+
"success": success,
|
414
|
+
"final_reward": final_reward,
|
415
|
+
"num_steps": num_steps,
|
416
|
+
"boxes_solved": int(final_public_state.boxes_on_target),
|
417
|
+
"total_boxes": int(final_public_state.num_boxes),
|
418
|
+
"max_turns": max_turns,
|
419
|
+
},
|
420
|
+
"partition": [
|
421
|
+
{
|
422
|
+
"partition_index": i,
|
423
|
+
"events": [
|
424
|
+
{
|
425
|
+
"event_type": "sokoban_turn",
|
426
|
+
"event_metadata": {
|
427
|
+
"turn_number": i + 1,
|
428
|
+
"turn_data": turn_data,
|
429
|
+
},
|
430
|
+
"agent_compute_step": {
|
431
|
+
"event_order": 1,
|
432
|
+
"compute_began": datetime.now().isoformat(),
|
433
|
+
"compute_ended": datetime.now().isoformat(),
|
434
|
+
"model_name": model_name,
|
435
|
+
"model_params": {"temperature": 0.0},
|
436
|
+
"compute_input": [
|
437
|
+
{
|
438
|
+
"messages": [
|
439
|
+
{
|
440
|
+
"role": "system",
|
441
|
+
"content": "You are playing Sokoban. Push all boxes onto targets.",
|
442
|
+
},
|
443
|
+
{
|
444
|
+
"role": "user",
|
445
|
+
"content": f"Turn {i + 1}: {turn_data['room_text']}",
|
446
|
+
},
|
447
|
+
]
|
448
|
+
}
|
449
|
+
],
|
450
|
+
"compute_output": [
|
451
|
+
{
|
452
|
+
"messages": [
|
453
|
+
{
|
454
|
+
"role": "assistant",
|
455
|
+
"content": f"Taking action: {turn_data.get('action_name', 'initial')}",
|
456
|
+
"tool_calls": [
|
457
|
+
{
|
458
|
+
"id": f"turn_{i + 1}",
|
459
|
+
"type": "function",
|
460
|
+
"function": {
|
461
|
+
"name": "sokoban_interact",
|
462
|
+
"arguments": json.dumps(
|
463
|
+
{
|
464
|
+
"actions_list": [
|
465
|
+
turn_data.get(
|
466
|
+
"action_name",
|
467
|
+
"initial",
|
468
|
+
)
|
469
|
+
],
|
470
|
+
"reasoning": f"Turn {i + 1} action",
|
471
|
+
}
|
472
|
+
),
|
473
|
+
},
|
474
|
+
}
|
475
|
+
],
|
476
|
+
},
|
477
|
+
{
|
478
|
+
"role": "tool",
|
479
|
+
"tool_call_id": f"turn_{i + 1}",
|
480
|
+
"content": f"Executed: {turn_data.get('action_name', 'initial')}",
|
481
|
+
},
|
482
|
+
]
|
483
|
+
}
|
484
|
+
],
|
485
|
+
},
|
486
|
+
"environment_compute_steps": [
|
487
|
+
{
|
488
|
+
"event_order": 2,
|
489
|
+
"compute_began": datetime.now().isoformat(),
|
490
|
+
"compute_ended": datetime.now().isoformat(),
|
491
|
+
"compute_input": [
|
492
|
+
{
|
493
|
+
"action": turn_data.get("action_taken", -1),
|
494
|
+
"action_name": turn_data.get(
|
495
|
+
"action_name", "initial"
|
496
|
+
),
|
497
|
+
}
|
498
|
+
],
|
499
|
+
"compute_output": [
|
500
|
+
{
|
501
|
+
"outputs": {
|
502
|
+
"room_text": turn_data["room_text"],
|
503
|
+
"action": turn_data.get("action_taken", -1),
|
504
|
+
"action_name": turn_data.get(
|
505
|
+
"action_name", "initial"
|
506
|
+
),
|
507
|
+
"player_position": turn_data["player_position"],
|
508
|
+
"boxes_on_target": turn_data["boxes_on_target"],
|
509
|
+
"num_steps": turn_data["num_steps"],
|
510
|
+
"reward": turn_data["reward"],
|
511
|
+
"terminated": turn_data["terminated"],
|
512
|
+
"truncated": turn_data["truncated"],
|
513
|
+
}
|
514
|
+
}
|
515
|
+
],
|
516
|
+
}
|
517
|
+
],
|
518
|
+
}
|
519
|
+
],
|
520
|
+
}
|
521
|
+
for i, turn_data in enumerate(turn_by_turn_data or [])
|
522
|
+
],
|
523
|
+
},
|
524
|
+
"dataset": {
|
525
|
+
"questions": [
|
526
|
+
{
|
527
|
+
"id": "sokoban_puzzle",
|
528
|
+
"intent": "solve",
|
529
|
+
"criteria": "push_all_boxes_to_targets",
|
530
|
+
}
|
531
|
+
],
|
532
|
+
"reward_signals": [
|
533
|
+
{
|
534
|
+
"question_id": "sokoban_puzzle",
|
535
|
+
"system_instance_id": agent.system_instance_id,
|
536
|
+
"reward": final_reward,
|
537
|
+
"annotation": json.dumps(
|
538
|
+
{
|
539
|
+
"success": success,
|
540
|
+
"boxes_solved": final_public_state.boxes_on_target,
|
541
|
+
"total_boxes": final_public_state.num_boxes,
|
542
|
+
"num_steps": num_steps,
|
543
|
+
"actions_taken": len(actions_per_turn),
|
544
|
+
}
|
545
|
+
),
|
546
|
+
}
|
547
|
+
],
|
548
|
+
},
|
549
|
+
}
|
550
|
+
|
551
|
+
# Save trace file
|
552
|
+
eval_dir = eval_dir or Path(
|
553
|
+
f"src/evals/sokoban/run_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
554
|
+
)
|
555
|
+
eval_dir.mkdir(parents=True, exist_ok=True)
|
556
|
+
traces_dir = eval_dir / "traces"
|
557
|
+
traces_dir.mkdir(exist_ok=True)
|
558
|
+
|
559
|
+
trace_file_path = traces_dir / f"{trajectory_id}.json"
|
560
|
+
with open(trace_file_path, "w") as f:
|
561
|
+
json.dump(trace_data, f, indent=2)
|
562
|
+
|
563
|
+
# Create trajectory result
|
564
|
+
result = SokobanTrajectoryResult(
|
565
|
+
trajectory_id=trajectory_id,
|
566
|
+
model_name=model_name,
|
567
|
+
difficulty=difficulty,
|
568
|
+
seed=seed,
|
569
|
+
success=success,
|
570
|
+
final_reward=final_reward,
|
571
|
+
num_steps=num_steps,
|
572
|
+
boxes_solved=int(final_public_state.boxes_on_target),
|
573
|
+
total_boxes=int(final_public_state.num_boxes),
|
574
|
+
trace_file_path=str(trace_file_path),
|
575
|
+
metadata={
|
576
|
+
"max_turns": max_turns,
|
577
|
+
"actions_taken": len(actions_per_turn),
|
578
|
+
"evaluation_timestamp": datetime.now().isoformat(),
|
579
|
+
},
|
580
|
+
)
|
581
|
+
|
582
|
+
self.trajectory_results.append(result)
|
583
|
+
return result
|
584
|
+
|
585
|
+
async def run_evaluation(
|
586
|
+
self,
|
587
|
+
model_names: List[str],
|
588
|
+
difficulties: List[str] = ["ultra-easy", "easy", "medium"],
|
589
|
+
num_trajectories_per_condition: int = 3,
|
590
|
+
max_turns: int = 20,
|
591
|
+
) -> Dict[str, Any]:
|
592
|
+
"""Run comprehensive evaluation across models and difficulties."""
|
593
|
+
|
594
|
+
print(f"šÆ Starting Sokoban evaluation")
|
595
|
+
print(f" Models: {model_names}")
|
596
|
+
print(f" Difficulties: {difficulties}")
|
597
|
+
print(f" Trajectories per condition: {num_trajectories_per_condition}")
|
598
|
+
print(f" Max turns per trajectory: {max_turns}")
|
599
|
+
|
600
|
+
eval_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
601
|
+
eval_dir = Path(f"src/evals/sokoban/run_{eval_timestamp}")
|
602
|
+
eval_dir.mkdir(parents=True, exist_ok=True)
|
603
|
+
|
604
|
+
all_results = []
|
605
|
+
|
606
|
+
for model_name in model_names:
|
607
|
+
for difficulty in difficulties:
|
608
|
+
print(f"\nš¤ Running {model_name} on {difficulty} difficulty...")
|
609
|
+
|
610
|
+
# Run trajectories for this condition
|
611
|
+
condition_results = []
|
612
|
+
for traj_idx in range(num_trajectories_per_condition):
|
613
|
+
seed = hash(f"{model_name}_{difficulty}_{traj_idx}") % 10000
|
614
|
+
|
615
|
+
print(
|
616
|
+
f" Trajectory {traj_idx + 1}/{num_trajectories_per_condition} (seed={seed})"
|
617
|
+
)
|
618
|
+
|
619
|
+
result = await self.run_single_trajectory_with_trace(
|
620
|
+
model_name=model_name,
|
621
|
+
difficulty=difficulty,
|
622
|
+
seed=seed,
|
623
|
+
max_turns=max_turns,
|
624
|
+
eval_dir=eval_dir,
|
625
|
+
)
|
626
|
+
|
627
|
+
condition_results.append(result)
|
628
|
+
all_results.append(result)
|
629
|
+
|
630
|
+
# Print condition summary
|
631
|
+
successful = sum(1 for r in condition_results if r.success)
|
632
|
+
avg_steps = sum(r.num_steps for r in condition_results) / len(condition_results)
|
633
|
+
avg_boxes = sum(r.boxes_solved for r in condition_results) / len(condition_results)
|
634
|
+
|
635
|
+
print(f" ā
{successful}/{len(condition_results)} successful")
|
636
|
+
print(f" š Avg steps: {avg_steps:.1f}, Avg boxes solved: {avg_boxes:.1f}")
|
637
|
+
|
638
|
+
# Generate evaluation summary
|
639
|
+
summary = {
|
640
|
+
"evaluation_timestamp": eval_timestamp,
|
641
|
+
"models_evaluated": model_names,
|
642
|
+
"difficulties_evaluated": difficulties,
|
643
|
+
"evaluation_metadata": {
|
644
|
+
"num_trajectories": len(all_results),
|
645
|
+
"max_turns": max_turns,
|
646
|
+
"trajectories_per_condition": num_trajectories_per_condition,
|
647
|
+
},
|
648
|
+
"aggregate_results": [],
|
649
|
+
}
|
650
|
+
|
651
|
+
# Aggregate results by model and difficulty
|
652
|
+
for model_name in model_names:
|
653
|
+
for difficulty in difficulties:
|
654
|
+
condition_results = [
|
655
|
+
r
|
656
|
+
for r in all_results
|
657
|
+
if r.model_name == model_name and r.difficulty == difficulty
|
658
|
+
]
|
659
|
+
|
660
|
+
if condition_results:
|
661
|
+
success_rate = sum(1 for r in condition_results if r.success) / len(
|
662
|
+
condition_results
|
663
|
+
)
|
664
|
+
avg_reward = sum(r.final_reward for r in condition_results) / len(
|
665
|
+
condition_results
|
666
|
+
)
|
667
|
+
avg_steps = sum(r.num_steps for r in condition_results) / len(condition_results)
|
668
|
+
avg_boxes = sum(r.boxes_solved for r in condition_results) / len(
|
669
|
+
condition_results
|
670
|
+
)
|
671
|
+
|
672
|
+
summary["aggregate_results"].append(
|
673
|
+
{
|
674
|
+
"model_name": model_name,
|
675
|
+
"difficulty": difficulty,
|
676
|
+
"num_trajectories": len(condition_results),
|
677
|
+
"success_rate": success_rate,
|
678
|
+
"avg_reward": avg_reward,
|
679
|
+
"avg_steps": avg_steps,
|
680
|
+
"avg_boxes_solved": avg_boxes,
|
681
|
+
}
|
682
|
+
)
|
683
|
+
|
684
|
+
# Save evaluation summary
|
685
|
+
summary_file = eval_dir / "evaluation_summary.json"
|
686
|
+
with open(summary_file, "w") as f:
|
687
|
+
json.dump(summary, f, indent=2)
|
688
|
+
|
689
|
+
# Print detailed aggregated results
|
690
|
+
print("\n" + "=" * 80)
|
691
|
+
print("š FINAL SOKOBAN EVALUATION RESULTS")
|
692
|
+
print("=" * 80)
|
693
|
+
|
694
|
+
# Overall metrics
|
695
|
+
all_successes = [r.success for r in all_results]
|
696
|
+
all_rewards = [r.final_reward for r in all_results]
|
697
|
+
all_steps = [r.num_steps for r in all_results]
|
698
|
+
all_boxes_solved = [r.boxes_solved for r in all_results]
|
699
|
+
|
700
|
+
print(f"š EVAL METRICS:")
|
701
|
+
print(f" Episodes: {len(all_results)}")
|
702
|
+
print(f" Individual Success: {[str(x) for x in all_successes]}")
|
703
|
+
print(f" Success Rate: {sum(all_successes) / len(all_successes):.3f}")
|
704
|
+
|
705
|
+
print(f"\nš REWARD METRICS:")
|
706
|
+
print(f" Individual Rewards: {[f'{x:.2f}' for x in all_rewards]}")
|
707
|
+
print(f" Mean Reward: {sum(all_rewards) / len(all_rewards):.2f}")
|
708
|
+
|
709
|
+
print(f"\nš EFFICIENCY METRICS:")
|
710
|
+
print(f" Individual Steps: {[str(x) for x in all_steps]}")
|
711
|
+
print(f" Mean Steps: {sum(all_steps) / len(all_steps):.1f}")
|
712
|
+
|
713
|
+
print(f"\nš¦ BOX SOLVING METRICS:")
|
714
|
+
print(f" Individual Boxes Solved: {[str(x) for x in all_boxes_solved]}")
|
715
|
+
print(f" Mean Boxes Solved: {sum(all_boxes_solved) / len(all_boxes_solved):.1f}")
|
716
|
+
|
717
|
+
# Results by difficulty
|
718
|
+
print(f"\nšÆ RESULTS BY DIFFICULTY:")
|
719
|
+
for model_name in model_names:
|
720
|
+
print(f" Model: {model_name}")
|
721
|
+
for difficulty in difficulties:
|
722
|
+
condition_results = [
|
723
|
+
r
|
724
|
+
for r in all_results
|
725
|
+
if r.model_name == model_name and r.difficulty == difficulty
|
726
|
+
]
|
727
|
+
if condition_results:
|
728
|
+
success_rate = sum(1 for r in condition_results if r.success) / len(
|
729
|
+
condition_results
|
730
|
+
)
|
731
|
+
avg_reward = sum(r.final_reward for r in condition_results) / len(
|
732
|
+
condition_results
|
733
|
+
)
|
734
|
+
avg_steps = sum(r.num_steps for r in condition_results) / len(condition_results)
|
735
|
+
avg_boxes = sum(r.boxes_solved for r in condition_results) / len(
|
736
|
+
condition_results
|
737
|
+
)
|
738
|
+
print(
|
739
|
+
f" {difficulty}: {success_rate:.1%} success, {avg_reward:.1f} reward, {avg_steps:.1f} steps, {avg_boxes:.1f} boxes"
|
740
|
+
)
|
741
|
+
|
742
|
+
# Overall assessment
|
743
|
+
overall_success_rate = sum(all_successes) / len(all_successes)
|
744
|
+
overall_reward = sum(all_rewards) / len(all_rewards)
|
745
|
+
|
746
|
+
print(f"\nš ASSESSMENT:")
|
747
|
+
if overall_success_rate >= 0.8:
|
748
|
+
print("š Excellent performance - mastering puzzle solving!")
|
749
|
+
elif overall_success_rate >= 0.6:
|
750
|
+
print("ā
Good performance - solving most puzzles!")
|
751
|
+
elif overall_success_rate >= 0.4:
|
752
|
+
print("ā ļø Moderate performance - learning puzzle mechanics")
|
753
|
+
elif overall_success_rate >= 0.2:
|
754
|
+
print("š Early progress - understanding basic moves")
|
755
|
+
else:
|
756
|
+
print("š§© Learning phase - focus on understanding Sokoban rules")
|
757
|
+
|
758
|
+
# Output markdown table row for README collation
|
759
|
+
print(f"\nš MARKDOWN TABLE ROW:")
|
760
|
+
print(
|
761
|
+
"| Model | Episodes | Success Rate | Mean Reward | Mean Steps | Mean Boxes | Assessment |"
|
762
|
+
)
|
763
|
+
print(
|
764
|
+
"|------------------|----------|--------------|-------------|------------|------------|------------|"
|
765
|
+
)
|
766
|
+
|
767
|
+
if overall_success_rate >= 0.6:
|
768
|
+
assessment = "Excellent"
|
769
|
+
elif overall_success_rate >= 0.4:
|
770
|
+
assessment = "Good"
|
771
|
+
elif overall_success_rate >= 0.2:
|
772
|
+
assessment = "Moderate"
|
773
|
+
else:
|
774
|
+
assessment = "Learning"
|
775
|
+
|
776
|
+
main_model = model_names[0] if model_names else "Unknown"
|
777
|
+
mean_steps = sum(all_steps) / len(all_steps)
|
778
|
+
mean_boxes = sum(all_boxes_solved) / len(all_boxes_solved)
|
779
|
+
|
780
|
+
print(
|
781
|
+
f"| {main_model:<16} | {len(all_results):>8} | {overall_success_rate:>12.3f} | {overall_reward:>11.2f} | {mean_steps:>10.1f} | {mean_boxes:>10.1f} | {assessment:<10} |"
|
782
|
+
)
|
783
|
+
|
784
|
+
print(f"\nš Evaluation saved to: {eval_dir}")
|
785
|
+
print(f"š Summary: {summary_file}")
|
786
|
+
print(f"š Traces: {eval_dir / 'traces'}")
|
787
|
+
|
788
|
+
return summary
|
789
|
+
|
790
|
+
|
791
|
+
# Convenience function for quick evaluations
|
792
|
+
async def run_sokoban_eval(
|
793
|
+
model_names: List[str],
|
794
|
+
difficulties: List[str] = ["ultra-easy", "easy", "medium"],
|
795
|
+
num_trajectories: int = 3,
|
796
|
+
max_turns: int = 20,
|
797
|
+
) -> Dict[str, Any]:
|
798
|
+
"""Quick evaluation runner with automatic report generation."""
|
799
|
+
|
800
|
+
framework = SokobanEvalFramework()
|
801
|
+
report = await framework.run_evaluation(
|
802
|
+
model_names=model_names,
|
803
|
+
difficulties=difficulties,
|
804
|
+
num_trajectories_per_condition=num_trajectories,
|
805
|
+
max_turns=max_turns,
|
806
|
+
)
|
807
|
+
|
808
|
+
return report
|
809
|
+
|
810
|
+
|
811
|
+
# --- Configuration Class ---
|
812
|
+
class SokobanConfig:
|
813
|
+
"""Configuration for Sokoban evaluation."""
|
814
|
+
|
815
|
+
def __init__(self, config_path: Optional[str] = None):
|
816
|
+
# Defaults
|
817
|
+
self.model_name = "gpt-4.1-mini"
|
818
|
+
self.num_instances = 3
|
819
|
+
self.max_turns = 20
|
820
|
+
self.difficulty_levels = ["ultra-easy", "easy", "medium"]
|
821
|
+
self.service_base_url = "http://localhost:8901"
|
822
|
+
self.service_timeout = 30.0
|
823
|
+
self.seed = 42
|
824
|
+
self.save_traces = True
|
825
|
+
self.save_detailed_results = True
|
826
|
+
|
827
|
+
if config_path and os.path.exists(config_path):
|
828
|
+
try:
|
829
|
+
import toml
|
830
|
+
|
831
|
+
cfg = toml.load(config_path)
|
832
|
+
|
833
|
+
e = cfg.get("eval", {})
|
834
|
+
self.model_name = e.get("model_name", self.model_name)
|
835
|
+
self.num_instances = e.get("episodes", self.num_instances)
|
836
|
+
self.max_turns = e.get("max_steps", self.max_turns)
|
837
|
+
diff = e.get("difficulty", None)
|
838
|
+
if diff:
|
839
|
+
# allow comma-separated list or single value
|
840
|
+
if isinstance(diff, str) and "," in diff:
|
841
|
+
self.difficulty_levels = [d.strip() for d in diff.split(",")]
|
842
|
+
elif isinstance(diff, list):
|
843
|
+
self.difficulty_levels = diff
|
844
|
+
else:
|
845
|
+
self.difficulty_levels = [str(diff)]
|
846
|
+
|
847
|
+
self.seed = e.get("seed", self.seed)
|
848
|
+
|
849
|
+
s = cfg.get("service", {})
|
850
|
+
self.service_base_url = s.get("base_url", self.service_base_url)
|
851
|
+
self.service_timeout = s.get("timeout", self.service_timeout)
|
852
|
+
|
853
|
+
o = cfg.get("output", {})
|
854
|
+
self.save_traces = o.get("save_traces", self.save_traces)
|
855
|
+
self.save_detailed_results = o.get(
|
856
|
+
"save_detailed_results", self.save_detailed_results
|
857
|
+
)
|
858
|
+
except Exception as exc:
|
859
|
+
print(f"[WARNING] Failed to load Sokoban config: {exc}")
|
860
|
+
|
861
|
+
|
862
|
+
# --- Helper to run evaluation with config ---
|
863
|
+
async def _run_with_config(cfg: SokobanConfig):
|
864
|
+
await run_sokoban_eval(
|
865
|
+
model_names=[cfg.model_name],
|
866
|
+
difficulties=cfg.difficulty_levels,
|
867
|
+
num_trajectories=cfg.num_instances,
|
868
|
+
max_turns=cfg.max_turns,
|
869
|
+
)
|
870
|
+
|
871
|
+
|
872
|
+
# --- CLI Entry Point ---
|
873
|
+
if __name__ == "__main__":
|
874
|
+
import argparse, asyncio
|
875
|
+
|
876
|
+
parser = argparse.ArgumentParser(description="Run Sokoban evaluation with optional TOML config")
|
877
|
+
parser.add_argument("--config", "-c", type=str, help="Path to TOML configuration file")
|
878
|
+
parser.add_argument("--model", "-m", type=str, help="Model name override")
|
879
|
+
parser.add_argument("--episodes", "-e", type=int, help="Episodes override")
|
880
|
+
parser.add_argument("--max-turns", "-t", type=int, help="Max turns override")
|
881
|
+
parser.add_argument(
|
882
|
+
"--difficulty", "-d", type=str, help="Difficulty (single or comma-separated list)"
|
883
|
+
)
|
884
|
+
|
885
|
+
args = parser.parse_args()
|
886
|
+
|
887
|
+
cfg = SokobanConfig(args.config)
|
888
|
+
if args.model:
|
889
|
+
cfg.model_name = args.model
|
890
|
+
if args.episodes:
|
891
|
+
cfg.num_instances = args.episodes
|
892
|
+
if args.max_turns:
|
893
|
+
cfg.max_turns = args.max_turns
|
894
|
+
if args.difficulty:
|
895
|
+
if "," in args.difficulty:
|
896
|
+
cfg.difficulty_levels = [d.strip() for d in args.difficulty.split(",")]
|
897
|
+
else:
|
898
|
+
cfg.difficulty_levels = [args.difficulty]
|
899
|
+
|
900
|
+
asyncio.run(_run_with_config(cfg))
|