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.
Files changed (169) hide show
  1. cogames/cli/client.py +60 -6
  2. cogames/cli/docsync/__init__.py +0 -0
  3. cogames/cli/docsync/_nb_md_directive_processing.py +180 -0
  4. cogames/cli/docsync/_nb_md_sync.py +103 -0
  5. cogames/cli/docsync/_nb_py_sync.py +122 -0
  6. cogames/cli/docsync/_three_way_sync.py +115 -0
  7. cogames/cli/docsync/_utils.py +76 -0
  8. cogames/cli/docsync/docsync.py +156 -0
  9. cogames/cli/leaderboard.py +112 -28
  10. cogames/cli/mission.py +64 -53
  11. cogames/cli/policy.py +46 -10
  12. cogames/cli/submit.py +268 -67
  13. cogames/cogs_vs_clips/cog.py +79 -0
  14. cogames/cogs_vs_clips/cogs_vs_clips_mapgen.md +19 -16
  15. cogames/cogs_vs_clips/cogsguard_reward_variants.py +153 -0
  16. cogames/cogs_vs_clips/cogsguard_tutorial.py +56 -0
  17. cogames/cogs_vs_clips/evals/README.md +10 -16
  18. cogames/cogs_vs_clips/evals/cogsguard_evals.py +81 -0
  19. cogames/cogs_vs_clips/evals/diagnostic_evals.py +49 -444
  20. cogames/cogs_vs_clips/evals/difficulty_variants.py +13 -326
  21. cogames/cogs_vs_clips/evals/integrated_evals.py +5 -45
  22. cogames/cogs_vs_clips/evals/spanning_evals.py +9 -180
  23. cogames/cogs_vs_clips/mission.py +187 -146
  24. cogames/cogs_vs_clips/missions.py +46 -137
  25. cogames/cogs_vs_clips/procedural.py +8 -8
  26. cogames/cogs_vs_clips/sites.py +107 -3
  27. cogames/cogs_vs_clips/stations.py +198 -186
  28. cogames/cogs_vs_clips/tutorial_missions.py +1 -1
  29. cogames/cogs_vs_clips/variants.py +25 -476
  30. cogames/device.py +13 -1
  31. cogames/{policy/scripted_agent/README.md → docs/SCRIPTED_AGENT.md} +82 -58
  32. cogames/evaluate.py +18 -30
  33. cogames/main.py +1434 -243
  34. cogames/maps/canidate1_1000.map +1 -1
  35. cogames/maps/canidate1_1000_stations.map +2 -2
  36. cogames/maps/canidate1_500.map +1 -1
  37. cogames/maps/canidate1_500_stations.map +2 -2
  38. cogames/maps/canidate2_1000.map +1 -1
  39. cogames/maps/canidate2_1000_stations.map +2 -2
  40. cogames/maps/canidate2_500.map +1 -1
  41. cogames/maps/canidate2_500_stations.map +2 -2
  42. cogames/maps/canidate3_1000.map +1 -1
  43. cogames/maps/canidate3_1000_stations.map +2 -2
  44. cogames/maps/canidate3_500.map +1 -1
  45. cogames/maps/canidate3_500_stations.map +2 -2
  46. cogames/maps/canidate4_500.map +1 -1
  47. cogames/maps/canidate4_500_stations.map +2 -2
  48. cogames/maps/cave_base_50.map +2 -2
  49. cogames/maps/diagnostic_evals/diagnostic_agile.map +2 -2
  50. cogames/maps/diagnostic_evals/diagnostic_agile_hard.map +2 -2
  51. cogames/maps/diagnostic_evals/diagnostic_charge_up.map +2 -2
  52. cogames/maps/diagnostic_evals/diagnostic_charge_up_hard.map +2 -2
  53. cogames/maps/diagnostic_evals/diagnostic_chest_navigation1.map +2 -2
  54. cogames/maps/diagnostic_evals/diagnostic_chest_navigation1_hard.map +2 -2
  55. cogames/maps/diagnostic_evals/diagnostic_chest_navigation2.map +2 -2
  56. cogames/maps/diagnostic_evals/diagnostic_chest_navigation2_hard.map +2 -2
  57. cogames/maps/diagnostic_evals/diagnostic_chest_navigation3.map +2 -2
  58. cogames/maps/diagnostic_evals/diagnostic_chest_navigation3_hard.map +2 -2
  59. cogames/maps/diagnostic_evals/diagnostic_chest_near.map +2 -2
  60. cogames/maps/diagnostic_evals/diagnostic_chest_search.map +2 -2
  61. cogames/maps/diagnostic_evals/diagnostic_chest_search_hard.map +2 -2
  62. cogames/maps/diagnostic_evals/diagnostic_extract_lab.map +2 -2
  63. cogames/maps/diagnostic_evals/diagnostic_extract_lab_hard.map +2 -2
  64. cogames/maps/diagnostic_evals/diagnostic_memory.map +2 -2
  65. cogames/maps/diagnostic_evals/diagnostic_memory_hard.map +2 -2
  66. cogames/maps/diagnostic_evals/diagnostic_radial.map +2 -2
  67. cogames/maps/diagnostic_evals/diagnostic_radial_hard.map +2 -2
  68. cogames/maps/diagnostic_evals/diagnostic_resource_lab.map +2 -2
  69. cogames/maps/diagnostic_evals/diagnostic_unclip.map +2 -2
  70. cogames/maps/evals/eval_balanced_spread.map +9 -5
  71. cogames/maps/evals/eval_clip_oxygen.map +9 -5
  72. cogames/maps/evals/eval_collect_resources.map +9 -5
  73. cogames/maps/evals/eval_collect_resources_hard.map +9 -5
  74. cogames/maps/evals/eval_collect_resources_medium.map +9 -5
  75. cogames/maps/evals/eval_divide_and_conquer.map +9 -5
  76. cogames/maps/evals/eval_energy_starved.map +9 -5
  77. cogames/maps/evals/eval_multi_coordinated_collect_hard.map +9 -5
  78. cogames/maps/evals/eval_oxygen_bottleneck.map +9 -5
  79. cogames/maps/evals/eval_single_use_world.map +9 -5
  80. cogames/maps/evals/extractor_hub_100x100.map +9 -5
  81. cogames/maps/evals/extractor_hub_30x30.map +9 -5
  82. cogames/maps/evals/extractor_hub_50x50.map +9 -5
  83. cogames/maps/evals/extractor_hub_70x70.map +9 -5
  84. cogames/maps/evals/extractor_hub_80x80.map +9 -5
  85. cogames/maps/machina_100_stations.map +2 -2
  86. cogames/maps/machina_200_stations.map +2 -2
  87. cogames/maps/machina_200_stations_small.map +2 -2
  88. cogames/maps/machina_eval_exp01.map +2 -2
  89. cogames/maps/machina_eval_template_large.map +2 -2
  90. cogames/maps/machinatrainer4agents.map +2 -2
  91. cogames/maps/machinatrainer4agentsbase.map +2 -2
  92. cogames/maps/machinatrainerbig.map +2 -2
  93. cogames/maps/machinatrainersmall.map +2 -2
  94. cogames/maps/planky_evals/aligner_avoid_aoe.map +28 -0
  95. cogames/maps/planky_evals/aligner_full_cycle.map +28 -0
  96. cogames/maps/planky_evals/aligner_gear.map +24 -0
  97. cogames/maps/planky_evals/aligner_hearts.map +24 -0
  98. cogames/maps/planky_evals/aligner_junction.map +26 -0
  99. cogames/maps/planky_evals/exploration_distant.map +28 -0
  100. cogames/maps/planky_evals/maze.map +32 -0
  101. cogames/maps/planky_evals/miner_best_resource.map +26 -0
  102. cogames/maps/planky_evals/miner_deposit.map +24 -0
  103. cogames/maps/planky_evals/miner_extract.map +26 -0
  104. cogames/maps/planky_evals/miner_full_cycle.map +28 -0
  105. cogames/maps/planky_evals/miner_gear.map +24 -0
  106. cogames/maps/planky_evals/multi_role.map +28 -0
  107. cogames/maps/planky_evals/resource_chain.map +30 -0
  108. cogames/maps/planky_evals/scout_explore.map +32 -0
  109. cogames/maps/planky_evals/scout_gear.map +24 -0
  110. cogames/maps/planky_evals/scrambler_full_cycle.map +28 -0
  111. cogames/maps/planky_evals/scrambler_gear.map +24 -0
  112. cogames/maps/planky_evals/scrambler_target.map +26 -0
  113. cogames/maps/planky_evals/stuck_corridor.map +32 -0
  114. cogames/maps/planky_evals/survive_retreat.map +26 -0
  115. cogames/maps/training_facility_clipped.map +2 -2
  116. cogames/maps/training_facility_open_1.map +2 -2
  117. cogames/maps/training_facility_open_2.map +2 -2
  118. cogames/maps/training_facility_open_3.map +2 -2
  119. cogames/maps/training_facility_tight_4.map +2 -2
  120. cogames/maps/training_facility_tight_5.map +2 -2
  121. cogames/maps/vanilla_large.map +2 -2
  122. cogames/maps/vanilla_small.map +2 -2
  123. cogames/pickup.py +183 -0
  124. cogames/play.py +166 -33
  125. cogames/policy/chaos_monkey.py +54 -0
  126. cogames/policy/nim_agents/__init__.py +27 -10
  127. cogames/policy/nim_agents/agents.py +121 -60
  128. cogames/policy/nim_agents/thinky_eval.py +35 -222
  129. cogames/policy/pufferlib_policy.py +67 -32
  130. cogames/policy/starter_agent.py +184 -0
  131. cogames/policy/trainable_policy_template.py +4 -1
  132. cogames/train.py +51 -13
  133. cogames/verbose.py +2 -2
  134. cogames-0.3.64.dist-info/METADATA +1842 -0
  135. cogames-0.3.64.dist-info/RECORD +159 -0
  136. cogames-0.3.64.dist-info/licenses/LICENSE +21 -0
  137. cogames-0.3.64.dist-info/top_level.txt +2 -0
  138. metta_alo/__init__.py +0 -0
  139. metta_alo/job_specs.py +17 -0
  140. metta_alo/policy.py +16 -0
  141. metta_alo/pure_single_episode_runner.py +75 -0
  142. metta_alo/py.typed +0 -0
  143. metta_alo/rollout.py +322 -0
  144. metta_alo/scoring.py +168 -0
  145. cogames/maps/diagnostic_evals/diagnostic_assembler_near.map +0 -49
  146. cogames/maps/diagnostic_evals/diagnostic_assembler_search.map +0 -49
  147. cogames/maps/diagnostic_evals/diagnostic_assembler_search_hard.map +0 -89
  148. cogames/policy/nim_agents/common.nim +0 -887
  149. cogames/policy/nim_agents/install.sh +0 -1
  150. cogames/policy/nim_agents/ladybug_agent.nim +0 -984
  151. cogames/policy/nim_agents/nim_agents.nim +0 -55
  152. cogames/policy/nim_agents/nim_agents.nims +0 -14
  153. cogames/policy/nim_agents/nimby.lock +0 -3
  154. cogames/policy/nim_agents/racecar_agents.nim +0 -884
  155. cogames/policy/nim_agents/random_agents.nim +0 -68
  156. cogames/policy/nim_agents/test_agents.py +0 -53
  157. cogames/policy/nim_agents/thinky_agents.nim +0 -717
  158. cogames/policy/scripted_agent/baseline_agent.py +0 -1049
  159. cogames/policy/scripted_agent/demo_policy.py +0 -244
  160. cogames/policy/scripted_agent/pathfinding.py +0 -126
  161. cogames/policy/scripted_agent/starter_agent.py +0 -136
  162. cogames/policy/scripted_agent/types.py +0 -235
  163. cogames/policy/scripted_agent/unclipping_agent.py +0 -476
  164. cogames/policy/scripted_agent/utils.py +0 -385
  165. cogames-0.3.49.dist-info/METADATA +0 -406
  166. cogames-0.3.49.dist-info/RECORD +0 -136
  167. cogames-0.3.49.dist-info/top_level.txt +0 -1
  168. {cogames-0.3.49.dist-info → cogames-0.3.64.dist-info}/WHEEL +0 -0
  169. {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 != "cuda":
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
- checkpoints = sorted(
358
- {path.parent for path in checkpoints_path.rglob(POLICY_SPEC_FILENAME)},
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) and seed is not None and map_builder.seed is None:
437
- map_builder.seed = seed
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 Mission
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: Mission | None = None,
14
+ mission_cfg: AnyMission | None = None,
15
15
  print_cvc_config: bool = False,
16
16
  print_mg_config: bool = False,
17
17
  ) -> None: