cogames 0.3.49__py3-none-any.whl → 0.3.64__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.
- cogames/cli/client.py +60 -6
- cogames/cli/docsync/__init__.py +0 -0
- cogames/cli/docsync/_nb_md_directive_processing.py +180 -0
- cogames/cli/docsync/_nb_md_sync.py +103 -0
- cogames/cli/docsync/_nb_py_sync.py +122 -0
- cogames/cli/docsync/_three_way_sync.py +115 -0
- cogames/cli/docsync/_utils.py +76 -0
- cogames/cli/docsync/docsync.py +156 -0
- cogames/cli/leaderboard.py +112 -28
- cogames/cli/mission.py +64 -53
- cogames/cli/policy.py +46 -10
- cogames/cli/submit.py +268 -67
- cogames/cogs_vs_clips/cog.py +79 -0
- cogames/cogs_vs_clips/cogs_vs_clips_mapgen.md +19 -16
- cogames/cogs_vs_clips/cogsguard_reward_variants.py +153 -0
- cogames/cogs_vs_clips/cogsguard_tutorial.py +56 -0
- cogames/cogs_vs_clips/evals/README.md +10 -16
- cogames/cogs_vs_clips/evals/cogsguard_evals.py +81 -0
- cogames/cogs_vs_clips/evals/diagnostic_evals.py +49 -444
- cogames/cogs_vs_clips/evals/difficulty_variants.py +13 -326
- cogames/cogs_vs_clips/evals/integrated_evals.py +5 -45
- cogames/cogs_vs_clips/evals/spanning_evals.py +9 -180
- cogames/cogs_vs_clips/mission.py +187 -146
- cogames/cogs_vs_clips/missions.py +46 -137
- cogames/cogs_vs_clips/procedural.py +8 -8
- cogames/cogs_vs_clips/sites.py +107 -3
- cogames/cogs_vs_clips/stations.py +198 -186
- cogames/cogs_vs_clips/tutorial_missions.py +1 -1
- cogames/cogs_vs_clips/variants.py +25 -476
- cogames/device.py +13 -1
- cogames/{policy/scripted_agent/README.md → docs/SCRIPTED_AGENT.md} +82 -58
- cogames/evaluate.py +18 -30
- cogames/main.py +1434 -243
- cogames/maps/canidate1_1000.map +1 -1
- cogames/maps/canidate1_1000_stations.map +2 -2
- cogames/maps/canidate1_500.map +1 -1
- cogames/maps/canidate1_500_stations.map +2 -2
- cogames/maps/canidate2_1000.map +1 -1
- cogames/maps/canidate2_1000_stations.map +2 -2
- cogames/maps/canidate2_500.map +1 -1
- cogames/maps/canidate2_500_stations.map +2 -2
- cogames/maps/canidate3_1000.map +1 -1
- cogames/maps/canidate3_1000_stations.map +2 -2
- cogames/maps/canidate3_500.map +1 -1
- cogames/maps/canidate3_500_stations.map +2 -2
- cogames/maps/canidate4_500.map +1 -1
- cogames/maps/canidate4_500_stations.map +2 -2
- cogames/maps/cave_base_50.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_agile.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_agile_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_charge_up.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_charge_up_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_navigation1.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_navigation1_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_navigation2.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_navigation2_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_navigation3.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_navigation3_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_near.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_search.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_chest_search_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_extract_lab.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_extract_lab_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_memory.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_memory_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_radial.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_radial_hard.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_resource_lab.map +2 -2
- cogames/maps/diagnostic_evals/diagnostic_unclip.map +2 -2
- cogames/maps/evals/eval_balanced_spread.map +9 -5
- cogames/maps/evals/eval_clip_oxygen.map +9 -5
- cogames/maps/evals/eval_collect_resources.map +9 -5
- cogames/maps/evals/eval_collect_resources_hard.map +9 -5
- cogames/maps/evals/eval_collect_resources_medium.map +9 -5
- cogames/maps/evals/eval_divide_and_conquer.map +9 -5
- cogames/maps/evals/eval_energy_starved.map +9 -5
- cogames/maps/evals/eval_multi_coordinated_collect_hard.map +9 -5
- cogames/maps/evals/eval_oxygen_bottleneck.map +9 -5
- cogames/maps/evals/eval_single_use_world.map +9 -5
- cogames/maps/evals/extractor_hub_100x100.map +9 -5
- cogames/maps/evals/extractor_hub_30x30.map +9 -5
- cogames/maps/evals/extractor_hub_50x50.map +9 -5
- cogames/maps/evals/extractor_hub_70x70.map +9 -5
- cogames/maps/evals/extractor_hub_80x80.map +9 -5
- cogames/maps/machina_100_stations.map +2 -2
- cogames/maps/machina_200_stations.map +2 -2
- cogames/maps/machina_200_stations_small.map +2 -2
- cogames/maps/machina_eval_exp01.map +2 -2
- cogames/maps/machina_eval_template_large.map +2 -2
- cogames/maps/machinatrainer4agents.map +2 -2
- cogames/maps/machinatrainer4agentsbase.map +2 -2
- cogames/maps/machinatrainerbig.map +2 -2
- cogames/maps/machinatrainersmall.map +2 -2
- cogames/maps/planky_evals/aligner_avoid_aoe.map +28 -0
- cogames/maps/planky_evals/aligner_full_cycle.map +28 -0
- cogames/maps/planky_evals/aligner_gear.map +24 -0
- cogames/maps/planky_evals/aligner_hearts.map +24 -0
- cogames/maps/planky_evals/aligner_junction.map +26 -0
- cogames/maps/planky_evals/exploration_distant.map +28 -0
- cogames/maps/planky_evals/maze.map +32 -0
- cogames/maps/planky_evals/miner_best_resource.map +26 -0
- cogames/maps/planky_evals/miner_deposit.map +24 -0
- cogames/maps/planky_evals/miner_extract.map +26 -0
- cogames/maps/planky_evals/miner_full_cycle.map +28 -0
- cogames/maps/planky_evals/miner_gear.map +24 -0
- cogames/maps/planky_evals/multi_role.map +28 -0
- cogames/maps/planky_evals/resource_chain.map +30 -0
- cogames/maps/planky_evals/scout_explore.map +32 -0
- cogames/maps/planky_evals/scout_gear.map +24 -0
- cogames/maps/planky_evals/scrambler_full_cycle.map +28 -0
- cogames/maps/planky_evals/scrambler_gear.map +24 -0
- cogames/maps/planky_evals/scrambler_target.map +26 -0
- cogames/maps/planky_evals/stuck_corridor.map +32 -0
- cogames/maps/planky_evals/survive_retreat.map +26 -0
- cogames/maps/training_facility_clipped.map +2 -2
- cogames/maps/training_facility_open_1.map +2 -2
- cogames/maps/training_facility_open_2.map +2 -2
- cogames/maps/training_facility_open_3.map +2 -2
- cogames/maps/training_facility_tight_4.map +2 -2
- cogames/maps/training_facility_tight_5.map +2 -2
- cogames/maps/vanilla_large.map +2 -2
- cogames/maps/vanilla_small.map +2 -2
- cogames/pickup.py +183 -0
- cogames/play.py +166 -33
- cogames/policy/chaos_monkey.py +54 -0
- cogames/policy/nim_agents/__init__.py +27 -10
- cogames/policy/nim_agents/agents.py +121 -60
- cogames/policy/nim_agents/thinky_eval.py +35 -222
- cogames/policy/pufferlib_policy.py +67 -32
- cogames/policy/starter_agent.py +184 -0
- cogames/policy/trainable_policy_template.py +4 -1
- cogames/train.py +51 -13
- cogames/verbose.py +2 -2
- cogames-0.3.64.dist-info/METADATA +1842 -0
- cogames-0.3.64.dist-info/RECORD +159 -0
- cogames-0.3.64.dist-info/licenses/LICENSE +21 -0
- cogames-0.3.64.dist-info/top_level.txt +2 -0
- metta_alo/__init__.py +0 -0
- metta_alo/job_specs.py +17 -0
- metta_alo/policy.py +16 -0
- metta_alo/pure_single_episode_runner.py +75 -0
- metta_alo/py.typed +0 -0
- metta_alo/rollout.py +322 -0
- metta_alo/scoring.py +168 -0
- cogames/maps/diagnostic_evals/diagnostic_assembler_near.map +0 -49
- cogames/maps/diagnostic_evals/diagnostic_assembler_search.map +0 -49
- cogames/maps/diagnostic_evals/diagnostic_assembler_search_hard.map +0 -89
- cogames/policy/nim_agents/common.nim +0 -887
- cogames/policy/nim_agents/install.sh +0 -1
- cogames/policy/nim_agents/ladybug_agent.nim +0 -984
- cogames/policy/nim_agents/nim_agents.nim +0 -55
- cogames/policy/nim_agents/nim_agents.nims +0 -14
- cogames/policy/nim_agents/nimby.lock +0 -3
- cogames/policy/nim_agents/racecar_agents.nim +0 -884
- cogames/policy/nim_agents/random_agents.nim +0 -68
- cogames/policy/nim_agents/test_agents.py +0 -53
- cogames/policy/nim_agents/thinky_agents.nim +0 -717
- cogames/policy/scripted_agent/baseline_agent.py +0 -1049
- cogames/policy/scripted_agent/demo_policy.py +0 -244
- cogames/policy/scripted_agent/pathfinding.py +0 -126
- cogames/policy/scripted_agent/starter_agent.py +0 -136
- cogames/policy/scripted_agent/types.py +0 -235
- cogames/policy/scripted_agent/unclipping_agent.py +0 -476
- cogames/policy/scripted_agent/utils.py +0 -385
- cogames-0.3.49.dist-info/METADATA +0 -406
- cogames-0.3.49.dist-info/RECORD +0 -136
- cogames-0.3.49.dist-info/top_level.txt +0 -1
- {cogames-0.3.49.dist-info → cogames-0.3.64.dist-info}/WHEEL +0 -0
- {cogames-0.3.49.dist-info → cogames-0.3.64.dist-info}/entry_points.txt +0 -0
cogames/train.py
CHANGED
|
@@ -24,7 +24,7 @@ from mettagrid.policy.loader import (
|
|
|
24
24
|
)
|
|
25
25
|
from mettagrid.policy.policy import PolicySpec
|
|
26
26
|
from mettagrid.policy.policy_env_interface import PolicyEnvInterface
|
|
27
|
-
from mettagrid.policy.submission import POLICY_SPEC_FILENAME
|
|
27
|
+
from mettagrid.policy.submission import POLICY_SPEC_FILENAME, SubmissionPolicySpec, write_submission_policy_spec
|
|
28
28
|
from mettagrid.simulator import Simulator
|
|
29
29
|
from mettagrid.util.stats_writer import NoopStatsWriter
|
|
30
30
|
from pufferlib import pufferl
|
|
@@ -76,6 +76,25 @@ def _resolve_vector_counts(
|
|
|
76
76
|
return num_envs, num_workers
|
|
77
77
|
|
|
78
78
|
|
|
79
|
+
def _align_minibatch_size(minibatch_size: int, batch_size: int, bptt_horizon: int) -> int:
|
|
80
|
+
if bptt_horizon <= 1:
|
|
81
|
+
return minibatch_size
|
|
82
|
+
|
|
83
|
+
if minibatch_size < bptt_horizon:
|
|
84
|
+
return bptt_horizon
|
|
85
|
+
|
|
86
|
+
remainder = minibatch_size % bptt_horizon
|
|
87
|
+
if remainder == 0:
|
|
88
|
+
return minibatch_size
|
|
89
|
+
|
|
90
|
+
rounded_up = minibatch_size + (bptt_horizon - remainder)
|
|
91
|
+
if rounded_up <= batch_size:
|
|
92
|
+
return rounded_up
|
|
93
|
+
|
|
94
|
+
rounded_down = minibatch_size - remainder
|
|
95
|
+
return max(bptt_horizon, rounded_down)
|
|
96
|
+
|
|
97
|
+
|
|
79
98
|
def train(
|
|
80
99
|
env_cfg: Optional[MettaGridConfig],
|
|
81
100
|
policy_class_path: str,
|
|
@@ -86,12 +105,14 @@ def train(
|
|
|
86
105
|
seed: int,
|
|
87
106
|
batch_size: int,
|
|
88
107
|
minibatch_size: int,
|
|
108
|
+
map_seed: Optional[int] = None,
|
|
89
109
|
missions_arg: Optional[list[str]] = None,
|
|
90
110
|
vector_num_envs: Optional[int] = None,
|
|
91
111
|
vector_batch_size: Optional[int] = None,
|
|
92
112
|
vector_num_workers: Optional[int] = None,
|
|
93
113
|
env_cfg_supplier: Optional[Callable[[], MettaGridConfig]] = None,
|
|
94
114
|
log_outputs: bool = False,
|
|
115
|
+
checkpoint_interval: int = 200,
|
|
95
116
|
) -> None:
|
|
96
117
|
console = Console()
|
|
97
118
|
|
|
@@ -101,7 +122,6 @@ def train(
|
|
|
101
122
|
backend = pvector.Multiprocessing
|
|
102
123
|
if platform.system() == "Darwin":
|
|
103
124
|
multiprocessing.set_start_method("spawn", force=True)
|
|
104
|
-
backend = pvector.Serial
|
|
105
125
|
|
|
106
126
|
try:
|
|
107
127
|
cpu_cores = psutil.cpu_count(logical=False) or psutil.cpu_count(logical=True)
|
|
@@ -121,7 +141,7 @@ def train(
|
|
|
121
141
|
else:
|
|
122
142
|
num_workers = desired_workers
|
|
123
143
|
|
|
124
|
-
if backend is pvector.Multiprocessing and device.type
|
|
144
|
+
if backend is pvector.Multiprocessing and device.type not in ("cuda", "mps"):
|
|
125
145
|
backend = pvector.Serial
|
|
126
146
|
num_workers = 1
|
|
127
147
|
|
|
@@ -175,7 +195,7 @@ def train(
|
|
|
175
195
|
envs_per_worker,
|
|
176
196
|
)
|
|
177
197
|
|
|
178
|
-
env_creator = _EnvCreator(env_cfg, env_cfg_supplier)
|
|
198
|
+
env_creator = _EnvCreator(env_cfg, env_cfg_supplier, map_seed, seed)
|
|
179
199
|
base_cfg = env_creator.clone_cfg()
|
|
180
200
|
|
|
181
201
|
vecenv = pvector.make(
|
|
@@ -242,6 +262,16 @@ def train(
|
|
|
242
262
|
amended_minibatch_size,
|
|
243
263
|
)
|
|
244
264
|
|
|
265
|
+
aligned_minibatch_size = _align_minibatch_size(amended_minibatch_size, amended_batch_size, bptt_horizon)
|
|
266
|
+
if aligned_minibatch_size != amended_minibatch_size:
|
|
267
|
+
logger.info(
|
|
268
|
+
"Adjusting minibatch_size from %s to %s to align with bptt_horizon=%s",
|
|
269
|
+
amended_minibatch_size,
|
|
270
|
+
aligned_minibatch_size,
|
|
271
|
+
bptt_horizon,
|
|
272
|
+
)
|
|
273
|
+
amended_minibatch_size = aligned_minibatch_size
|
|
274
|
+
|
|
245
275
|
effective_timesteps = max(num_steps, amended_batch_size)
|
|
246
276
|
if effective_timesteps != num_steps:
|
|
247
277
|
logger.info(
|
|
@@ -250,7 +280,6 @@ def train(
|
|
|
250
280
|
effective_timesteps,
|
|
251
281
|
)
|
|
252
282
|
|
|
253
|
-
checkpoint_interval = 200
|
|
254
283
|
train_args = dict(
|
|
255
284
|
env=env_name,
|
|
256
285
|
device=device.type,
|
|
@@ -285,6 +314,7 @@ def train(
|
|
|
285
314
|
vtrace_c_clip=1.0,
|
|
286
315
|
prio_alpha=0.8,
|
|
287
316
|
prio_beta0=0.2,
|
|
317
|
+
min_lr_ratio=0.0,
|
|
288
318
|
)
|
|
289
319
|
|
|
290
320
|
trainer = pufferl.PuffeRL(train_args, vecenv, policy.network())
|
|
@@ -354,13 +384,17 @@ def train(
|
|
|
354
384
|
)
|
|
355
385
|
console.print("=" * 80, style="bold green")
|
|
356
386
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
key=lambda path: path.stat().st_mtime,
|
|
360
|
-
)
|
|
387
|
+
run_dir = checkpoints_path / trainer.logger.run_id
|
|
388
|
+
checkpoints = sorted(run_dir.glob("model_*.pt"), key=lambda path: path.stat().st_mtime)
|
|
361
389
|
|
|
362
390
|
if checkpoints and not training_diverged:
|
|
363
391
|
final_checkpoint = checkpoints[-1]
|
|
392
|
+
spec = SubmissionPolicySpec(
|
|
393
|
+
class_path=policy_class_path,
|
|
394
|
+
data_path=final_checkpoint.name,
|
|
395
|
+
)
|
|
396
|
+
write_submission_policy_spec(run_dir / POLICY_SPEC_FILENAME, spec)
|
|
397
|
+
|
|
364
398
|
console.print()
|
|
365
399
|
console.print(f"Final checkpoint: [cyan]{final_checkpoint}[/cyan]")
|
|
366
400
|
if trainer.epoch < checkpoint_interval:
|
|
@@ -409,9 +443,13 @@ class _EnvCreator:
|
|
|
409
443
|
self,
|
|
410
444
|
env_cfg: Optional[MettaGridConfig],
|
|
411
445
|
env_cfg_supplier: Optional[Callable[[], MettaGridConfig]],
|
|
446
|
+
map_seed: Optional[int],
|
|
447
|
+
fallback_seed: Optional[int],
|
|
412
448
|
) -> None:
|
|
413
449
|
self._env_cfg = env_cfg
|
|
414
450
|
self._env_cfg_supplier = env_cfg_supplier
|
|
451
|
+
self._map_seed = map_seed
|
|
452
|
+
self._fallback_seed = fallback_seed
|
|
415
453
|
|
|
416
454
|
def clone_cfg(self) -> MettaGridConfig:
|
|
417
455
|
if self._env_cfg_supplier is not None:
|
|
@@ -430,11 +468,11 @@ class _EnvCreator:
|
|
|
430
468
|
) -> PufferMettaGridEnv:
|
|
431
469
|
target_cfg = cfg.model_copy(deep=True) if cfg is not None else self.clone_cfg()
|
|
432
470
|
|
|
433
|
-
# If this mission uses MapGen and the builder seed is unset, derive a deterministic
|
|
434
|
-
# MapGen seed from the per-env seed provided by the vectorized runner.
|
|
435
471
|
map_builder = getattr(target_cfg.game, "map_builder", None)
|
|
436
|
-
if isinstance(map_builder, MapGen.Config)
|
|
437
|
-
|
|
472
|
+
if isinstance(map_builder, MapGen.Config):
|
|
473
|
+
base_seed = self._map_seed if self._map_seed is not None else self._fallback_seed
|
|
474
|
+
if base_seed is not None and (self._map_seed is not None or map_builder.seed is None):
|
|
475
|
+
map_builder.seed = base_seed + (seed or 0)
|
|
438
476
|
simulator = Simulator()
|
|
439
477
|
simulator.add_event_handler(StatsTracker(NoopStatsWriter()))
|
|
440
478
|
simulator.add_event_handler(EarlyResetHandler())
|
cogames/verbose.py
CHANGED
|
@@ -4,14 +4,14 @@ import json
|
|
|
4
4
|
|
|
5
5
|
from rich.console import Console
|
|
6
6
|
|
|
7
|
-
from cogames.cogs_vs_clips.mission import
|
|
7
|
+
from cogames.cogs_vs_clips.mission import AnyMission
|
|
8
8
|
from mettagrid.config.mettagrid_config import MettaGridConfig
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def print_configs(
|
|
12
12
|
console: Console,
|
|
13
13
|
env_cfg: MettaGridConfig,
|
|
14
|
-
mission_cfg:
|
|
14
|
+
mission_cfg: AnyMission | None = None,
|
|
15
15
|
print_cvc_config: bool = False,
|
|
16
16
|
print_mg_config: bool = False,
|
|
17
17
|
) -> None:
|