cuju-render 0.1.0__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 (382) hide show
  1. cuju/render/__init__.py +759 -0
  2. cuju/render/__main__.py +1065 -0
  3. cuju/render/_export/__init__.py +3 -0
  4. cuju/render/_export/feed.py +542 -0
  5. cuju/render/_export/sizes.py +157 -0
  6. cuju/render/_export/video.py +1618 -0
  7. cuju/render/_export/video_jobs.py +408 -0
  8. cuju/render/_format/__init__.py +3 -0
  9. cuju/render/_format/annotations.py +235 -0
  10. cuju/render/_format/codec.py +307 -0
  11. cuju/render/_format/keep.py +121 -0
  12. cuju/render/_format/recording.py +860 -0
  13. cuju/render/_format/writer.py +54 -0
  14. cuju/render/_guide/__init__.py +3 -0
  15. cuju/render/_guide/doctor.py +523 -0
  16. cuju/render/_guide/help.py +62 -0
  17. cuju/render/_guide/tutorial.py +254 -0
  18. cuju/render/_http/__init__.py +3 -0
  19. cuju/render/_http/commands.py +57 -0
  20. cuju/render/_http/headers.py +103 -0
  21. cuju/render/_http/launch.py +500 -0
  22. cuju/render/_http/launchers.py +408 -0
  23. cuju/render/_http/pwa.py +128 -0
  24. cuju/render/_http/server.py +2105 -0
  25. cuju/render/_http/window.py +360 -0
  26. cuju/render/_moments/__init__.py +3 -0
  27. cuju/render/_moments/captions.py +284 -0
  28. cuju/render/_moments/events.py +1123 -0
  29. cuju/render/_moments/search.py +694 -0
  30. cuju/render/_packages/__init__.py +3 -0
  31. cuju/render/_packages/glsl.py +746 -0
  32. cuju/render/_packages/loudness.py +334 -0
  33. cuju/render/_packages/pack.py +1959 -0
  34. cuju/render/_packages/presentation.py +1376 -0
  35. cuju/render/_packages/vocabulary.py +609 -0
  36. cuju/render/_playing/__init__.py +3 -0
  37. cuju/render/_playing/achievements.py +463 -0
  38. cuju/render/_playing/bench.py +609 -0
  39. cuju/render/_playing/challenges.py +1813 -0
  40. cuju/render/_playing/demo.py +323 -0
  41. cuju/render/_playing/draw.py +211 -0
  42. cuju/render/_playing/errors.py +20 -0
  43. cuju/render/_playing/game.py +645 -0
  44. cuju/render/_playing/limits.py +339 -0
  45. cuju/render/_playing/play.py +926 -0
  46. cuju/render/_playing/policy_worker.py +250 -0
  47. cuju/render/_playing/strict.py +810 -0
  48. cuju/render/_registry/__init__.py +3 -0
  49. cuju/render/_registry/clips.py +394 -0
  50. cuju/render/_registry/joints.py +108 -0
  51. cuju/render/_registry/teams.py +2058 -0
  52. cuju/render/_store/__init__.py +3 -0
  53. cuju/render/_store/home.py +70 -0
  54. cuju/render/_store/library.py +604 -0
  55. cuju/render/_store/samples.py +163 -0
  56. cuju/render/_text/__init__.py +3 -0
  57. cuju/render/_text/languages.py +637 -0
  58. cuju/render/_text/messages.py +1396 -0
  59. cuju/render/_tournaments/__init__.py +3 -0
  60. cuju/render/_tournaments/results.py +547 -0
  61. cuju/render/_tournaments/tournament.py +2742 -0
  62. cuju/render/_tournaments/tournament_cli.py +587 -0
  63. cuju/render/_tournaments/tournament_runner.py +1975 -0
  64. cuju/render/_version.py +6 -0
  65. cuju/render/_watch/__init__.py +3 -0
  66. cuju/render/_watch/grid.py +265 -0
  67. cuju/render/_watch/live.py +664 -0
  68. cuju/render/_watch/notebook.py +79 -0
  69. cuju/render/_watch/show.py +171 -0
  70. cuju/render/samples/sample-11v11.cjr +0 -0
  71. cuju/render/samples/sample-5v5.cjr +0 -0
  72. cuju/render/samples/teams/starter/main.py +33 -0
  73. cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
  74. cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
  75. cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
  76. cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
  77. cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
  78. cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
  79. cuju/render/web/assets/adboard_polygon.webp +0 -0
  80. cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
  81. cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
  82. cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
  83. cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
  84. cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
  85. cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
  86. cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
  87. cuju/render/web/assets/ball.glb +0 -0
  88. cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
  89. cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
  90. cuju/render/web/assets/challenges/corner.mp4 +0 -0
  91. cuju/render/web/assets/challenges/corner.webp +0 -0
  92. cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
  93. cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
  94. cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
  95. cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
  96. cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
  97. cuju/render/web/assets/challenges/empty_goal.webp +0 -0
  98. cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
  99. cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
  100. cuju/render/web/assets/challenges/manifest.json +375 -0
  101. cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
  102. cuju/render/web/assets/challenges/one_on_one.webp +0 -0
  103. cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
  104. cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
  105. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
  106. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
  107. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
  108. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
  109. cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
  110. cuju/render/web/assets/challenges/run_to_score.webp +0 -0
  111. cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
  112. cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
  113. cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
  114. cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
  115. cuju/render/web/assets/crowd.webp +0 -0
  116. cuju/render/web/assets/crowd_normal.webp +0 -0
  117. cuju/render/web/assets/cuju-logo-384.png +0 -0
  118. cuju/render/web/assets/cuju-logo.png +0 -0
  119. cuju/render/web/assets/cuju-logo.svg +46 -0
  120. cuju/render/web/assets/cuju-mark-light.svg +33 -0
  121. cuju/render/web/assets/cuju-mark.svg +33 -0
  122. cuju/render/web/assets/goal.glb +0 -0
  123. cuju/render/web/assets/grass.webp +0 -0
  124. cuju/render/web/assets/hair_black.png +0 -0
  125. cuju/render/web/assets/hair_blonde.png +0 -0
  126. cuju/render/web/assets/hair_brown.png +0 -0
  127. cuju/render/web/assets/hair_darkblonde.png +0 -0
  128. cuju/render/web/assets/hair_long01.glb +0 -0
  129. cuju/render/web/assets/hair_long02.glb +0 -0
  130. cuju/render/web/assets/hair_medium01.glb +0 -0
  131. cuju/render/web/assets/hair_red.png +0 -0
  132. cuju/render/web/assets/hair_short01.glb +0 -0
  133. cuju/render/web/assets/hair_short02.glb +0 -0
  134. cuju/render/web/assets/icons/cuju-192.png +0 -0
  135. cuju/render/web/assets/icons/cuju-512.png +0 -0
  136. cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
  137. cuju/render/web/assets/kit_goalkeeper.webp +0 -0
  138. cuju/render/web/assets/kit_mask.png +0 -0
  139. cuju/render/web/assets/kit_normal.webp +0 -0
  140. cuju/render/web/assets/manifest.json +601 -0
  141. cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
  142. cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
  143. cuju/render/web/assets/models/kaykit-knight.glb +0 -0
  144. cuju/render/web/assets/models/kaykit-knight.json +23 -0
  145. cuju/render/web/assets/models/kaykit-mage.glb +0 -0
  146. cuju/render/web/assets/models/kaykit-mage.json +23 -0
  147. cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
  148. cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
  149. cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
  150. cuju/render/web/assets/models/kaykit-ranger.json +23 -0
  151. cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
  152. cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
  153. cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
  154. cuju/render/web/assets/models/kaykit-rogue.json +23 -0
  155. cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
  156. cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
  157. cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
  158. cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
  159. cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
  160. cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
  161. cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
  162. cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
  163. cuju/render/web/assets/pitch.webp +0 -0
  164. cuju/render/web/assets/pitch_normal.webp +0 -0
  165. cuju/render/web/assets/player.glb +0 -0
  166. cuju/render/web/assets/shoe.webp +0 -0
  167. cuju/render/web/assets/shoe_sole.png +0 -0
  168. cuju/render/web/assets/skin_01.png +0 -0
  169. cuju/render/web/assets/skin_02.png +0 -0
  170. cuju/render/web/assets/skin_03.png +0 -0
  171. cuju/render/web/assets/skin_04.png +0 -0
  172. cuju/render/web/assets/sounds/applause.ogg +0 -0
  173. cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
  174. cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
  175. cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
  176. cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
  177. cuju/render/web/assets/sounds/city-horn.ogg +0 -0
  178. cuju/render/web/assets/sounds/city-loop.ogg +0 -0
  179. cuju/render/web/assets/sounds/city-siren.ogg +0 -0
  180. cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
  181. cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
  182. cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
  183. cuju/render/web/assets/sounds/gulls.ogg +0 -0
  184. cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
  185. cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
  186. cuju/render/web/assets/sounds/sounds.json +46 -0
  187. cuju/render/web/assets/sounds/space-beep.ogg +0 -0
  188. cuju/render/web/assets/sounds/space-hum.ogg +0 -0
  189. cuju/render/web/assets/sounds/space-radio.ogg +0 -0
  190. cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
  191. cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
  192. cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
  193. cuju/render/web/easy.css +357 -0
  194. cuju/render/web/export.html +23 -0
  195. cuju/render/web/feed.css +262 -0
  196. cuju/render/web/feed.html +28 -0
  197. cuju/render/web/flat.css +120 -0
  198. cuju/render/web/home.css +837 -0
  199. cuju/render/web/index.html +373 -0
  200. cuju/render/web/js/boot.js +50 -0
  201. cuju/render/web/js/broadcast/audio.js +2141 -0
  202. cuju/render/web/js/broadcast/celebrate.js +1238 -0
  203. cuju/render/web/js/broadcast/decisions.js +609 -0
  204. cuju/render/web/js/broadcast/hud.js +352 -0
  205. cuju/render/web/js/broadcast/show.js +3614 -0
  206. cuju/render/web/js/broadcast/transition.js +2231 -0
  207. cuju/render/web/js/broadcast/voices.js +153 -0
  208. cuju/render/web/js/capture.js +101 -0
  209. cuju/render/web/js/core/accessibility.js +90 -0
  210. cuju/render/web/js/core/api.js +429 -0
  211. cuju/render/web/js/core/comfort.js +135 -0
  212. cuju/render/web/js/core/i18n.js +705 -0
  213. cuju/render/web/js/core/icons.js +167 -0
  214. cuju/render/web/js/core/input-settings.js +156 -0
  215. cuju/render/web/js/core/keys.js +277 -0
  216. cuju/render/web/js/core/language-ui.js +125 -0
  217. cuju/render/web/js/core/menu.js +853 -0
  218. cuju/render/web/js/core/names.js +113 -0
  219. cuju/render/web/js/core/page-structure.js +110 -0
  220. cuju/render/web/js/core/scenarios.js +109 -0
  221. cuju/render/web/js/core/spoilers.js +236 -0
  222. cuju/render/web/js/core/typeahead.js +38 -0
  223. cuju/render/web/js/export/dom-picture.js +330 -0
  224. cuju/render/web/js/export/export-host.js +97 -0
  225. cuju/render/web/js/export/feed-dialog.js +191 -0
  226. cuju/render/web/js/export/feed-params.js +266 -0
  227. cuju/render/web/js/export/feed.js +363 -0
  228. cuju/render/web/js/export/mp4-mux.js +295 -0
  229. cuju/render/web/js/export/photo-core.js +313 -0
  230. cuju/render/web/js/export/photo.js +1314 -0
  231. cuju/render/web/js/export/safe-frame.js +59 -0
  232. cuju/render/web/js/export/size-fields.js +103 -0
  233. cuju/render/web/js/export/sizes.js +178 -0
  234. cuju/render/web/js/export/video-boot.js +55 -0
  235. cuju/render/web/js/export/video-browser.js +325 -0
  236. cuju/render/web/js/export/video-export.js +417 -0
  237. cuju/render/web/js/export/video-plan.js +207 -0
  238. cuju/render/web/js/export/video-range.js +185 -0
  239. cuju/render/web/js/export/webm-mux.js +198 -0
  240. cuju/render/web/js/feed-boot.js +151 -0
  241. cuju/render/web/js/feed-frame.js +101 -0
  242. cuju/render/web/js/help/doctor.js +488 -0
  243. cuju/render/web/js/help/firstrun.js +379 -0
  244. cuju/render/web/js/help/help-center.js +438 -0
  245. cuju/render/web/js/help/install-offer.js +164 -0
  246. cuju/render/web/js/help/install-state.js +104 -0
  247. cuju/render/web/js/help/lessons-core.js +207 -0
  248. cuju/render/web/js/help/lessons.js +463 -0
  249. cuju/render/web/js/help/palette.js +584 -0
  250. cuju/render/web/js/help/pwa.js +257 -0
  251. cuju/render/web/js/help/tour-core.js +241 -0
  252. cuju/render/web/js/help/tour.js +461 -0
  253. cuju/render/web/js/main.js +2513 -0
  254. cuju/render/web/js/pages/draw.js +188 -0
  255. cuju/render/web/js/pages/fieldpage.js +530 -0
  256. cuju/render/web/js/pages/home.js +521 -0
  257. cuju/render/web/js/pages/matches.js +779 -0
  258. cuju/render/web/js/pages/moments-ui.js +359 -0
  259. cuju/render/web/js/pages/queue-filters.js +63 -0
  260. cuju/render/web/js/pages/recording-groups.js +80 -0
  261. cuju/render/web/js/pages/recordings.js +1069 -0
  262. cuju/render/web/js/play/bench.js +347 -0
  263. cuju/render/web/js/play/challenges.js +1302 -0
  264. cuju/render/web/js/play/medals.js +127 -0
  265. cuju/render/web/js/play/play.js +1953 -0
  266. cuju/render/web/js/play/teasers.js +196 -0
  267. cuju/render/web/js/play/touch.js +350 -0
  268. cuju/render/web/js/play/tournament-layout.js +487 -0
  269. cuju/render/web/js/play/tournament-results.js +441 -0
  270. cuju/render/web/js/play/tournament-strict.js +560 -0
  271. cuju/render/web/js/play/tournament.js +2585 -0
  272. cuju/render/web/js/players/animate.js +972 -0
  273. cuju/render/web/js/players/clips.js +224 -0
  274. cuju/render/web/js/players/kaykit.js +162 -0
  275. cuju/render/web/js/players/kits.js +676 -0
  276. cuju/render/web/js/players/number-patch.js +82 -0
  277. cuju/render/web/js/players/players.js +2694 -0
  278. cuju/render/web/js/players/recolor.js +893 -0
  279. cuju/render/web/js/players/retarget.js +325 -0
  280. cuju/render/web/js/players/rig-numbers.js +174 -0
  281. cuju/render/web/js/presentation/animator.js +231 -0
  282. cuju/render/web/js/presentation/assign.js +85 -0
  283. cuju/render/web/js/presentation/behaviors.js +440 -0
  284. cuju/render/web/js/presentation/budget.js +209 -0
  285. cuju/render/web/js/presentation/catalog.js +1674 -0
  286. cuju/render/web/js/presentation/clocks.js +72 -0
  287. cuju/render/web/js/presentation/commands.js +301 -0
  288. cuju/render/web/js/presentation/contract.js +240 -0
  289. cuju/render/web/js/presentation/effects.js +904 -0
  290. cuju/render/web/js/presentation/flash.js +605 -0
  291. cuju/render/web/js/presentation/freeze-worklet.js +22 -0
  292. cuju/render/web/js/presentation/glsl.js +464 -0
  293. cuju/render/web/js/presentation/host.js +323 -0
  294. cuju/render/web/js/presentation/index.js +2066 -0
  295. cuju/render/web/js/presentation/loudness-worklet.js +235 -0
  296. cuju/render/web/js/presentation/loudness.js +740 -0
  297. cuju/render/web/js/presentation/moments.js +536 -0
  298. cuju/render/web/js/presentation/post.js +327 -0
  299. cuju/render/web/js/presentation/preview.js +180 -0
  300. cuju/render/web/js/presentation/protocol.js +174 -0
  301. cuju/render/web/js/presentation/reach.js +158 -0
  302. cuju/render/web/js/presentation/rigging.js +130 -0
  303. cuju/render/web/js/presentation/sandbox.js +157 -0
  304. cuju/render/web/js/presentation/shaders.js +235 -0
  305. cuju/render/web/js/presentation/stage.js +402 -0
  306. cuju/render/web/js/presentation/teamaudio.js +722 -0
  307. cuju/render/web/js/presentation/tracks.js +197 -0
  308. cuju/render/web/js/presentation/values.js +81 -0
  309. cuju/render/web/js/recording/annotation-data.js +203 -0
  310. cuju/render/web/js/recording/captions.js +491 -0
  311. cuju/render/web/js/recording/codec.js +185 -0
  312. cuju/render/web/js/recording/decode-worker.js +70 -0
  313. cuju/render/web/js/recording/decode.js +94 -0
  314. cuju/render/web/js/recording/episodes.js +46 -0
  315. cuju/render/web/js/recording/format.js +461 -0
  316. cuju/render/web/js/recording/live.js +348 -0
  317. cuju/render/web/js/recording/moments-query.js +59 -0
  318. cuju/render/web/js/recording/moments.js +149 -0
  319. cuju/render/web/js/recording/pose.js +86 -0
  320. cuju/render/web/js/recording/timeline.js +275 -0
  321. cuju/render/web/js/teams/art.js +50 -0
  322. cuju/render/web/js/teams/clip-editor.js +293 -0
  323. cuju/render/web/js/teams/editor.js +1979 -0
  324. cuju/render/web/js/teams/library.js +344 -0
  325. cuju/render/web/js/teams/painter.js +633 -0
  326. cuju/render/web/js/teams/surprise-ui.js +195 -0
  327. cuju/render/web/js/teams/surprise.js +497 -0
  328. cuju/render/web/js/teams/team-check.js +127 -0
  329. cuju/render/web/js/watch/annotations.js +270 -0
  330. cuju/render/web/js/watch/flat.js +366 -0
  331. cuju/render/web/js/watch/grid.js +436 -0
  332. cuju/render/web/js/watch/pitch2d.js +289 -0
  333. cuju/render/web/js/watch/player-tools.js +192 -0
  334. cuju/render/web/js/watch/presets.js +201 -0
  335. cuju/render/web/js/world/arenas.js +997 -0
  336. cuju/render/web/js/world/ball.js +204 -0
  337. cuju/render/web/js/world/cameras.js +982 -0
  338. cuju/render/web/js/world/crowd.js +376 -0
  339. cuju/render/web/js/world/field.js +227 -0
  340. cuju/render/web/js/world/framing.js +145 -0
  341. cuju/render/web/js/world/occlusion.js +48 -0
  342. cuju/render/web/js/world/pitch.js +703 -0
  343. cuju/render/web/js/world/scene.js +395 -0
  344. cuju/render/web/js/world/sky.js +325 -0
  345. cuju/render/web/js/world/stadium.js +1262 -0
  346. cuju/render/web/js/world/vendor-sky.js +367 -0
  347. cuju/render/web/js/world/weather.js +264 -0
  348. cuju/render/web/languages/en.json +4750 -0
  349. cuju/render/web/lessons.json +137 -0
  350. cuju/render/web/manifest.webmanifest +23 -0
  351. cuju/render/web/style.css +8399 -0
  352. cuju/render/web/sw.js +235 -0
  353. cuju/render/web/vendor/fabric/LICENSE +16 -0
  354. cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
  355. cuju/render/web/vendor/lucide/LICENSE +43 -0
  356. cuju/render/web/vendor/lucide/icons.js +141 -0
  357. cuju/render/web/vendor/three/LICENSE +21 -0
  358. cuju/render/web/vendor/three/build/three.core.js +60586 -0
  359. cuju/render/web/vendor/three/build/three.module.js +19719 -0
  360. cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
  361. cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
  362. cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  363. cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
  364. cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  365. cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
  366. cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  367. cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
  368. cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  369. cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  370. cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  371. cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
  372. cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
  373. cuju_render-0.1.0.dist-info/METADATA +116 -0
  374. cuju_render-0.1.0.dist-info/RECORD +382 -0
  375. cuju_render-0.1.0.dist-info/WHEEL +4 -0
  376. cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
  377. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
  378. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
  379. cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
  380. cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
  381. cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
  382. cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
@@ -0,0 +1,810 @@
1
+ # Copyright 2026 The cuju Authors
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ """Plays the submissions of a match under strict rules, and checks one team before a tournament.
5
+
6
+ Under strict rules each registered team's policy runs in a process of its own, the script
7
+ `policy_worker.py`, with its own import path and a limit of threads, so two teams never share a
8
+ module and each computes on the same terms. The match times every call of each policy, and a side
9
+ that fails to load or to reset in time, fails in a call, answers late, answers an action outside its
10
+ set or computes for longer on average than the rules allow, breaks a rule, which ends the match at
11
+ once as that side's forfeit. This is isolation for fairness, not a sandbox for code that one cannot
12
+ trust, as the renderer's other ways of playing a submission are.
13
+
14
+ The check of a team, its pre-flight, loads the team and plays a few steps against the built-in AI
15
+ under the same rules, once on the left and once on the right, so the turned view of the right side
16
+ is checked too, and reports a pass or the rule it broke, with its timings and warnings. The
17
+ command line runs it in a process of its own, as `python -m cuju.render._playing.strict`, which
18
+ reports one line of JSON.
19
+
20
+ Every match plays exactly from its seed and the actions of each step, so the actions that a match
21
+ under strict rules stepped with, kept beside its seed, replay it, which `replay` does.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import argparse
27
+ import contextlib
28
+ import hashlib
29
+ import json
30
+ import os
31
+ import queue
32
+ import shutil
33
+ import stat
34
+ import subprocess
35
+ import sys
36
+ import tempfile
37
+ import threading
38
+ import time
39
+ from pathlib import Path
40
+ from typing import Any
41
+
42
+ from cuju.kaggle import action_index, action_indices
43
+
44
+ from .._registry import teams as _teams
45
+ from .._store import home as _home
46
+ from .._text import messages as _messages
47
+ from . import play as _play
48
+ from .limits import Guard
49
+ from .policy_worker import THREAD_VARIABLES
50
+
51
+ # The script of a team's process, which runs from its file with nothing of the renderer.
52
+ WORKER = Path(__file__).with_name('policy_worker.py')
53
+ # The steps that the check of a team plays.
54
+ PREFLIGHT_STEPS = 10
55
+ # The seconds that a process has to end once the match asks it to.
56
+ _END_SECONDS = 2.0
57
+ # The variables that hide the GPUs of CUDA and ROCm from a team's process, unless the rules
58
+ # allow a GPU.
59
+ GPU_VARIABLES = ('CUDA_VISIBLE_DEVICES', 'HIP_VISIBLE_DEVICES', 'ROCR_VISIBLE_DEVICES')
60
+ # A team's log starts again once it grows past this many bytes.
61
+ _LOG_BYTES = 1024 * 1024
62
+ # The share of all its actions above which one action draws a warning in the check of a team.
63
+ _ONE_ACTION = 0.9
64
+ # The settings that a team's own file of the registry may hold, beside those it names itself.
65
+ _TEAM_SETTINGS = {
66
+ 'id',
67
+ 'name',
68
+ 'name_id',
69
+ 'name_values',
70
+ 'kind',
71
+ 'created',
72
+ 'format',
73
+ 'style',
74
+ 'model',
75
+ 'control',
76
+ 'color',
77
+ 'secondary',
78
+ 'images',
79
+ 'sounds',
80
+ 'sounds_version',
81
+ 'clips',
82
+ 'joints',
83
+ 'presentation',
84
+ 'source',
85
+ 'filename',
86
+ 'imported',
87
+ }
88
+
89
+
90
+ def _label(name: str, /, **values: Any) -> dict[str, Any]:
91
+ """Returns the label of a broken rule, `server.strict.<name>`, which the page translates."""
92
+ return _messages.label(f'server.strict.{name}', **values)
93
+
94
+
95
+ def _seconds(value: float) -> str:
96
+ return f'{value:g}'
97
+
98
+
99
+ def _kept(relative: Path) -> bool:
100
+ """Returns whether a file of a team's folder counts in its digest and its copy."""
101
+ return not (
102
+ relative.parts[0] == _teams.TEAM_FOLDER
103
+ or '__pycache__' in relative.parts
104
+ or relative.suffix == '.pyc'
105
+ )
106
+
107
+
108
+ def folder_digest(team: str) -> str | None:
109
+ """Returns the SHA-256 of a team's folder, of every file's path and bytes, or `None`.
110
+
111
+ The files count in the order of their paths, each its path, its size and its bytes, so the
112
+ digest changes with any file that is added, removed, renamed or changed. The renderer's
113
+ folder of the team's kit and presentation and the caches of Python stay out of it, since the
114
+ Teams page and Python change those while the policy stays the same.
115
+ """
116
+ folder = _home.folder('teams') / team
117
+ if not (folder / 'main.py').is_file():
118
+ return None
119
+ digest = hashlib.sha256()
120
+ for path in sorted(folder.rglob('*'), key=lambda item: item.relative_to(folder).as_posix()):
121
+ relative = path.relative_to(folder)
122
+ if path.is_symlink() or not path.is_file() or not _kept(relative):
123
+ continue
124
+ data = path.read_bytes()
125
+ digest.update(relative.as_posix().encode() + b'\0' + str(len(data)).encode() + b'\0')
126
+ digest.update(data)
127
+ return digest.hexdigest()
128
+
129
+
130
+ def frozen_copy(team: str, target: Path) -> Path:
131
+ """Copies a team's folder into `target` with every file read only, and returns the copy.
132
+
133
+ A match plays the team from the copy, inside its private working folder, so whatever the team
134
+ writes stays in that folder and goes with it at the end of the match.
135
+ """
136
+ source = _home.folder('teams') / team
137
+ shutil.copytree(
138
+ source,
139
+ target,
140
+ symlinks=False,
141
+ ignore=lambda folder, names: [
142
+ name
143
+ for name in names
144
+ if name == '__pycache__'
145
+ or name.endswith('.pyc')
146
+ or (name == _teams.TEAM_FOLDER and Path(folder) == source)
147
+ ],
148
+ )
149
+ for path in target.rglob('*'):
150
+ if path.is_file():
151
+ path.chmod(stat.S_IREAD)
152
+ return target
153
+
154
+
155
+ def _writable(function: Any, path: str, info: Any) -> None:
156
+ """Makes a read only file writable and removes it, as removing a frozen copy needs."""
157
+ del info
158
+ with contextlib.suppress(OSError):
159
+ os.chmod(path, stat.S_IWRITE | stat.S_IREAD)
160
+ function(path)
161
+
162
+
163
+ def log_path(team: str) -> Path:
164
+ """Returns the log of a team's processes under strict rules, what its policy printed."""
165
+ folder = _home.folder('logs') / 'policies'
166
+ folder.mkdir(parents=True, exist_ok=True)
167
+ return folder / f'{team}.log'
168
+
169
+
170
+ def _log(team: str) -> Any:
171
+ """Opens the log of a team to add to, started again once it grows too long."""
172
+ path = log_path(team)
173
+ with contextlib.suppress(OSError):
174
+ if path.stat().st_size > _LOG_BYTES:
175
+ path.unlink()
176
+ stream = path.open('a', encoding='utf-8', errors='replace')
177
+ stream.write(f'--- a process of the team started at {time.strftime("%Y-%m-%d %H:%M:%S")}\n')
178
+ stream.flush()
179
+ return stream
180
+
181
+
182
+ class Worker:
183
+ """One team's process, the requests it is sent and the lines it answers with.
184
+
185
+ Attributes:
186
+ process: The process.
187
+ started: When the process started, on the clock of `time.perf_counter`.
188
+ calls: The calls that the policy has answered.
189
+ translate: Whether the policy answers the default set in a batch of the v2 set.
190
+ """
191
+
192
+ def __init__(self, team: dict[str, Any], limits: dict[str, Any], translate: bool) -> None:
193
+ threads = int(limits['threads'])
194
+ # The variables of Python that a renderer's process may carry, such as PYTHONPATH, stay
195
+ # out, as `-I` leaves them out too, and the threads of each library follow the rules.
196
+ environment = {
197
+ key: value
198
+ for key, value in _home.process_environment().items()
199
+ if not key.upper().startswith('PYTHON')
200
+ }
201
+ environment.update({name: str(threads) for name in THREAD_VARIABLES})
202
+ if not limits.get('gpu', False):
203
+ environment.update({name: '' for name in GPU_VARIABLES})
204
+ self.started = time.perf_counter()
205
+ self.calls = 0
206
+ self.total = 0.0
207
+ self.translate = translate
208
+ self._lines: queue.Queue[str | None] = queue.Queue()
209
+ # A private working folder, which the match removes once the process ends, with a copy
210
+ # of the team's folder whose files read only, so nothing the team writes outlasts it.
211
+ self.folder = tempfile.mkdtemp(prefix='cuju-policy-')
212
+ folder = _home.folder('teams') / team['id']
213
+ if limits.get('frozen', True):
214
+ folder = frozen_copy(team['id'], Path(self.folder) / 'team')
215
+ self._log = _log(team['id'])
216
+ self.guard = Guard(float(limits.get('memory_mb', 2048)), threads)
217
+ # The team's prints go to its log, and its answers come on a pipe of their own, which no
218
+ # other team reaches.
219
+ self.process = subprocess.Popen(
220
+ [sys.executable, '-I', '-X', 'utf8', str(WORKER), str(folder), str(threads)],
221
+ stdin=subprocess.PIPE,
222
+ stdout=subprocess.PIPE,
223
+ stderr=self._log,
224
+ text=True,
225
+ encoding='utf-8',
226
+ errors='replace',
227
+ cwd=self.folder,
228
+ env=environment,
229
+ preexec_fn=self.guard.preexec(),
230
+ )
231
+ self.guard.attach(self.process)
232
+ threading.Thread(target=self._read, daemon=True, name='cuju-strict-worker').start()
233
+ # The team's code runs only once the process stands under its limits.
234
+ self.send({'start': True})
235
+
236
+ def _read(self) -> None:
237
+ try:
238
+ for line in self.process.stdout:
239
+ self._lines.put(line)
240
+ except (OSError, ValueError):
241
+ pass
242
+ self._lines.put(None)
243
+
244
+ def send(self, request: dict[str, Any]) -> None:
245
+ """Sends one request, and leaves a process that has ended to answer that it has."""
246
+ with contextlib.suppress(OSError, ValueError):
247
+ self.process.stdin.write(json.dumps(request) + '\n')
248
+ self.process.stdin.flush()
249
+
250
+ def receive(self, timeout: float) -> dict[str, Any] | None:
251
+ """Returns the next answer within `timeout` seconds, `{'closed': True}` once the process
252
+ has ended, or `None` when no answer came in time."""
253
+ deadline = time.perf_counter() + max(0.0, timeout)
254
+ while True:
255
+ try:
256
+ line = self._lines.get(timeout=max(0.0, deadline - time.perf_counter()))
257
+ except queue.Empty:
258
+ return None
259
+ if line is None:
260
+ # The process ended, so its last lines have all been read.
261
+ self._lines.put(None)
262
+ return {'closed': True}
263
+ try:
264
+ found = json.loads(line)
265
+ except ValueError:
266
+ continue
267
+ if isinstance(found, dict):
268
+ return found
269
+
270
+ def exit_text(self) -> str:
271
+ """Returns how the process ended, with its exit code once it has one."""
272
+ with contextlib.suppress(subprocess.TimeoutExpired):
273
+ code = self.process.wait(1.0)
274
+ return f'its process ended with exit code {code}'
275
+ return 'its process stopped answering'
276
+
277
+ def close(self) -> None:
278
+ """Asks the process to end and ends it when it does not in time."""
279
+ self.send({'end': True})
280
+ with contextlib.suppress(OSError, ValueError):
281
+ self.process.stdin.close()
282
+ try:
283
+ self.process.wait(_END_SECONDS)
284
+ except subprocess.TimeoutExpired:
285
+ with contextlib.suppress(OSError):
286
+ self.process.kill()
287
+ with contextlib.suppress(subprocess.TimeoutExpired):
288
+ self.process.wait(_END_SECONDS)
289
+ self.guard.close()
290
+ with contextlib.suppress(OSError):
291
+ self._log.close()
292
+ shutil.rmtree(self.folder, onerror=_writable)
293
+ shutil.rmtree(self.folder, ignore_errors=True)
294
+
295
+ def failure(self, found: dict[str, Any], kind: str, name: Any, label: dict[str, Any]) -> Any:
296
+ """Returns the rule that a failed request broke, the guard's limit where it saw one.
297
+
298
+ Args:
299
+ found: What the process answered, its error or that it ended.
300
+ kind: The kind of rule that a plain failure breaks, such as `crash` or `load`.
301
+ name: The name of the side.
302
+ label: The reason of a plain failure.
303
+
304
+ Returns:
305
+ The kind, the reason and the detail of the break.
306
+ """
307
+ broken = self.guard.broken
308
+ if broken is not None:
309
+ limit, values = broken
310
+ return limit, _label(limit, player=name, **values), None
311
+ stage = found.get('stage')
312
+ memory = self.guard.memory_mb
313
+ if stage == 'memory' or (
314
+ stage is None and self.guard.peak() >= 0.9 * memory and found.get('closed')
315
+ ):
316
+ return 'memory', _label('memory_out', player=name, limit=_seconds(memory)), None
317
+ if stage == 'process':
318
+ return 'process', _label('process', player=name), None
319
+ return kind, label, None
320
+
321
+
322
+ class StrictPolicies(_play.Policies):
323
+ """The policies of a match under strict rules, each submission in a process of its own.
324
+
325
+ The processes start together and load at once, so the limit of loading counts from each
326
+ process's start. The random entrant plays in the match's own process, as it is no team.
327
+
328
+ The mean compute time of a call, which the rules limit over the whole match, leaves out the
329
+ first call, which may well load a model or compile, and the first call has a limit of its own.
330
+
331
+ Args:
332
+ limits: The limits, as `tournament.check_strict` gives them.
333
+ mean_after_first: Whether the mean of a call leaves out the first, true unless a test asks
334
+ for the plain mean.
335
+ """
336
+
337
+ def __init__(
338
+ self,
339
+ *arguments: Any,
340
+ seed: int = 0,
341
+ limits: dict[str, Any],
342
+ mean_after_first: bool = True,
343
+ ) -> None:
344
+ self.limits = limits
345
+ self.mean_after_first = mean_after_first
346
+ self.workers: list[Worker] = []
347
+ try:
348
+ super().__init__(*arguments, seed=seed)
349
+ self._start()
350
+ except _play.RuleError as broken:
351
+ broken.stats = self._safe_stats()
352
+ self.close()
353
+ raise
354
+ except BaseException:
355
+ self.close()
356
+ raise
357
+
358
+ def _safe_stats(self) -> list[Any]:
359
+ try:
360
+ return self.stats()
361
+ except AttributeError:
362
+ return [None, None]
363
+
364
+ def _runner(
365
+ self,
366
+ team: dict[str, Any],
367
+ side: int,
368
+ extended: bool,
369
+ control: dict[str, Any],
370
+ seed: int,
371
+ name: Any,
372
+ ) -> Any:
373
+ if team['kind'] == 'random':
374
+ return super()._runner(team, side, extended, control, seed, name)
375
+ worker = Worker(team, self.limits, extended and control['action_set'] == 'default')
376
+ self.workers.append(worker)
377
+ return worker
378
+
379
+ def _players(self) -> list[tuple[dict[str, Any], Worker]]:
380
+ return [
381
+ (player, player['runner'])
382
+ for player in self.players
383
+ if isinstance(player['runner'], Worker)
384
+ ]
385
+
386
+ def _start(self) -> None:
387
+ """Waits for every process to load and then to reset, each within its limit.
388
+
389
+ Raises:
390
+ RuleError: If a side fails or runs out of time in either.
391
+ """
392
+ breaks: list[tuple[int, str, dict[str, Any]]] = []
393
+ load = self.limits['load_seconds']
394
+ for player, worker in self._players():
395
+ found = worker.receive(worker.started + load - time.perf_counter())
396
+ name = player['name']
397
+ if found is None:
398
+ breaks.append(
399
+ (player['side'], 'load', _label('load_time', player=name, count=_seconds(load)))
400
+ )
401
+ elif found.get('closed') or 'error' in found:
402
+ reason = str(found.get('error') or worker.exit_text())
403
+ label = _label('load', player=name, reason=reason)
404
+ breaks.append((player['side'], *worker.failure(found, 'load', name, label)))
405
+ else:
406
+ player['stats'].load = time.perf_counter() - worker.started
407
+ worker.guard.loading = False
408
+ if breaks:
409
+ raise _play.RuleError(breaks)
410
+ reset = self.limits['reset_seconds']
411
+ asked = {}
412
+ for _, worker in self._players():
413
+ worker.send({'reset': True})
414
+ asked[id(worker)] = time.perf_counter()
415
+ for player, worker in self._players():
416
+ found = worker.receive(asked[id(worker)] + reset - time.perf_counter())
417
+ name = player['name']
418
+ if found is None:
419
+ breaks.append(
420
+ (
421
+ player['side'],
422
+ 'reset',
423
+ _label('reset_time', player=name, count=_seconds(reset)),
424
+ )
425
+ )
426
+ elif found.get('closed') or 'error' in found:
427
+ reason = str(found.get('error') or worker.exit_text())
428
+ label = _label('reset', player=name, reason=reason)
429
+ breaks.append((player['side'], *worker.failure(found, 'reset', name, label)))
430
+ else:
431
+ player['stats'].reset = time.perf_counter() - asked[id(worker)]
432
+ if breaks:
433
+ raise _play.RuleError(breaks)
434
+
435
+ def _actions(self, worker: Worker, answer: Any, players: int) -> list[int]:
436
+ """Returns the actions of an answer, checked as Kaggle checks them, or raises."""
437
+ count = _play.DEFAULT_ACTIONS if worker.translate else self.batch.action_count
438
+ values = (
439
+ [action_index(answer, count)]
440
+ if players == 1
441
+ else action_indices(answer, count, players)
442
+ )
443
+ return [value % _play.DEFAULT_ACTIONS for value in values] if worker.translate else values
444
+
445
+ def decide(self, parts: list[Any]) -> list[Any]:
446
+ """Sends each process its observation at once, and takes each answer within its limit.
447
+
448
+ Raises:
449
+ RuleError: If a side fails in its call, answers late or answers an invalid action.
450
+ """
451
+ sent: dict[int, float] = {}
452
+ for index, (player, part) in enumerate(zip(self.players, parts, strict=True)):
453
+ if part is not None and isinstance(player['runner'], Worker):
454
+ player['runner'].send({'obs': part[2]})
455
+ sent[index] = time.perf_counter()
456
+ answers: list[Any] = []
457
+ breaks: list[tuple[int, str, dict[str, Any]]] = []
458
+ for index, (player, part) in enumerate(zip(self.players, parts, strict=True)):
459
+ if part is None:
460
+ answers.append(None)
461
+ continue
462
+ runner, name, side = player['runner'], player['name'], player['side']
463
+ if not isinstance(runner, Worker):
464
+ started = time.perf_counter()
465
+ answer = runner.act(part[2], self.batch.action_count)
466
+ player['stats'].add(time.perf_counter() - started, answer)
467
+ answers.append(answer)
468
+ continue
469
+ first = runner.calls == 0
470
+ limit = self.limits['first_call_seconds' if first else 'call_seconds']
471
+ found = runner.receive(sent[index] + limit - time.perf_counter())
472
+ wall = time.perf_counter() - sent[index]
473
+ answers.append(None)
474
+ if found is None:
475
+ reason = (
476
+ _label('first_time', player=name, count=_seconds(limit))
477
+ if first
478
+ else _label(
479
+ 'call_time', player=name, call=runner.calls + 1, count=_seconds(limit)
480
+ )
481
+ )
482
+ breaks.append((side, 'timeout', reason))
483
+ continue
484
+ if found.get('closed') or 'error' in found:
485
+ reason = str(found.get('error') or runner.exit_text())
486
+ if found.get('stage') == 'answer':
487
+ breaks.append(
488
+ (
489
+ side,
490
+ 'invalid',
491
+ _label('invalid_type', player=name, reason=reason),
492
+ 'type',
493
+ )
494
+ )
495
+ else:
496
+ label = _label('crash', player=name, reason=reason)
497
+ breaks.append((side, *runner.failure(found, 'crash', name, label)))
498
+ continue
499
+ try:
500
+ actions = self._actions(runner, found.get('answer'), len(part[2]['players_raw']))
501
+ except (TypeError, ValueError, IndexError) as error:
502
+ # A wrong count of actions, an action of another type or one outside the set.
503
+ detail = {TypeError: 'type', ValueError: 'count', IndexError: 'range'}[type(error)]
504
+ reason = _label(f'invalid_{detail}', player=name, reason=_play._reason(error))
505
+ breaks.append((side, 'invalid', reason, detail))
506
+ continue
507
+ compute = found.get('compute')
508
+ valid = isinstance(compute, (int, float)) and not isinstance(compute, bool)
509
+ # The time that the process reports for its call counts, within the time it took.
510
+ compute = min(float(compute), wall) if valid and compute >= 0 else wall
511
+ runner.calls += 1
512
+ runner.total += compute
513
+ player['stats'].add(compute, actions)
514
+ answers[-1] = actions
515
+ most = self.limits.get('match_seconds')
516
+ if most is not None and runner.total > most:
517
+ # The time of all the team's calls of the match together has its own limit.
518
+ reason = _label(
519
+ 'total_time', player=name, total=f'{runner.total:.2f}', limit=_seconds(most)
520
+ )
521
+ breaks.append((side, 'total_time', reason))
522
+ if breaks:
523
+ raise _play.RuleError(breaks)
524
+ return answers
525
+
526
+ def finish(self) -> None:
527
+ """Checks the mean compute time of a call of each side against its limit.
528
+
529
+ Raises:
530
+ RuleError: If a side computed for longer on average than the rules allow.
531
+ """
532
+ limit = self.limits['mean_call_ms']
533
+ breaks = []
534
+ for player, _ in self._players():
535
+ mean = player['stats'].mean(self.mean_after_first) * 1000
536
+ if player['stats'].calls and mean > limit:
537
+ reason = _label(
538
+ 'mean', player=player['name'], mean=f'{mean:.1f}', limit=_seconds(limit)
539
+ )
540
+ breaks.append((player['side'], 'mean', reason))
541
+ if breaks:
542
+ raise _play.RuleError(breaks)
543
+
544
+ def close(self) -> None:
545
+ """Ends every team's process, and keeps the most memory that each used."""
546
+ for worker in self.workers:
547
+ worker.close()
548
+ for player, worker in self._players():
549
+ player['stats'].memory = worker.guard.peak()
550
+
551
+
552
+ # A check of a team without strict rules only asks that it loads and plays.
553
+ LENIENT = {
554
+ 'threads': 64,
555
+ 'load_seconds': 600.0,
556
+ 'first_call_seconds': 600.0,
557
+ 'call_seconds': 600.0,
558
+ 'reset_seconds': 600.0,
559
+ 'mean_call_ms': 10000.0,
560
+ 'folder_mb': 10000.0,
561
+ 'memory_mb': 65536.0,
562
+ 'match_seconds': None,
563
+ 'frozen': True,
564
+ 'gpu': True,
565
+ 'deterministic': False,
566
+ }
567
+
568
+
569
+ def _folder_bytes(folder: Path) -> int:
570
+ """Returns the bytes of every file of a folder and its subfolders, links left out."""
571
+ total = 0
572
+ for path in folder.rglob('*'):
573
+ with contextlib.suppress(OSError):
574
+ if path.is_file() and not path.is_symlink():
575
+ total += path.stat().st_size
576
+ return total
577
+
578
+
579
+ def _rule(kind: str, reason: dict[str, Any], detail: str | None = None) -> dict[str, Any]:
580
+ return {
581
+ 'side': 'home',
582
+ 'kind': kind,
583
+ 'reason': reason['text'],
584
+ 'reason_id': reason.get('id'),
585
+ 'reason_values': reason.get('values'),
586
+ 'detail': detail,
587
+ 'step': 0,
588
+ 'at': [0, 0],
589
+ }
590
+
591
+
592
+ def _setting_warnings(team: str) -> list[dict[str, Any]]:
593
+ """Returns a warning for each setting of a team's file that the renderer does not know."""
594
+ path = _home.folder('teams') / team / _teams.TEAM_FOLDER / 'team.json'
595
+ try:
596
+ saved = json.loads(path.read_text(encoding='utf-8'))
597
+ except (OSError, ValueError):
598
+ return []
599
+ if not isinstance(saved, dict):
600
+ return []
601
+ unknown = sorted(str(key) for key in saved if key not in _TEAM_SETTINGS)
602
+ return [_label('warning_setting', setting=key, file='team.json') for key in unknown]
603
+
604
+
605
+ def _side_check(
606
+ team: str,
607
+ scenario: str,
608
+ limits: dict[str, Any],
609
+ left: bool,
610
+ replay: dict[str, Any] | None = None,
611
+ ) -> tuple[dict[str, Any] | None, dict[str, Any]]:
612
+ """Plays a few steps with the team on one side and returns the rule it broke and its stats.
613
+
614
+ `replay`, when given, takes the actions of every step, which the check of determinism
615
+ compares.
616
+ """
617
+ stats: dict[str, Any] = {}
618
+ sides = (team, _teams.BUILTIN) if left else (_teams.BUILTIN, team)
619
+ try:
620
+ _play.play(
621
+ *sides,
622
+ scenario,
623
+ seed=0,
624
+ strict=limits,
625
+ stats=stats,
626
+ steps=PREFLIGHT_STEPS,
627
+ save=False,
628
+ replay=replay,
629
+ )
630
+ except _play.ForfeitError as forfeit:
631
+ rule = dict(forfeit.rule)
632
+ rule['side'] = 'home'
633
+ return rule, forfeit.stats
634
+ except Exception as error:
635
+ ids = _messages.id_fields(error)
636
+ found = {'text': str(error), 'id': ids.get('error_id'), 'values': ids.get('error_values')}
637
+ return _rule('load', found), stats
638
+ return None, stats
639
+
640
+
641
+ def _timings(side: dict[str, Any]) -> dict[str, Any]:
642
+ return {
643
+ 'load_seconds': side.get('load_seconds'),
644
+ 'reset_seconds': side.get('reset_seconds'),
645
+ 'calls': side.get('calls', 0),
646
+ 'first_ms': side.get('first_ms'),
647
+ 'mean_ms': side.get('mean_ms'),
648
+ 'max_ms': side.get('max_ms'),
649
+ 'mean_after_first_ms': side.get('mean_after_first_ms'),
650
+ }
651
+
652
+
653
+ def preflight(
654
+ team: str, scenario: str | None = None, limits: dict[str, Any] | None = None
655
+ ) -> dict[str, Any]:
656
+ """Loads a team and plays a few steps against the built-in AI on each side, under strict rules.
657
+
658
+ The team plays once on the left and once on the right, where it sees the match turned, so a
659
+ policy that reads the turned view wrong fails before its tournament. Its folder may hold at
660
+ most the size of the limit `folder_mb`. Warnings, which never fail the check, name the
661
+ settings of the team's file that the renderer does not know, and an action that makes up more
662
+ than nine in ten of all the actions the team answered.
663
+
664
+ Args:
665
+ team: The team of the registry.
666
+ scenario: The scenario, by default five against five for a team of five a side and the
667
+ Kaggle match for one of eleven.
668
+ limits: The limits of strict rules, or `None` for limits so wide that only a team that
669
+ fails to load or to play breaks them.
670
+
671
+ Returns:
672
+ Whether the team passed, the rule it broke otherwise with its reason, its timings on the
673
+ left, the seconds to load and to reset, its calls and the first, mean and largest compute
674
+ time of a call in milliseconds with the mean after the first call, the same for each
675
+ side under `sides`, its actions and its warnings.
676
+ """
677
+ entry = _teams.entry(team)
678
+ if scenario is None:
679
+ scenario = '5_vs_5' if entry.get('format') == '5v5' else '11_vs_11_kaggle'
680
+ limits = limits or LENIENT
681
+ name = _teams.shown_name(entry)
682
+ rule = None
683
+ sides: dict[str, Any] = {}
684
+ actions: dict[str, int] = {}
685
+ notes: list[dict[str, Any]] = []
686
+ folder = _home.folder('teams') / team
687
+ size = _folder_bytes(folder) / 1e6 if entry.get('kind') != 'builtin' else 0.0
688
+ most = limits.get('folder_mb', LENIENT['folder_mb'])
689
+ if size > most:
690
+ reason = _label('folder_size', player=name, size=f'{size:.1f}', limit=_seconds(most))
691
+ rule = _rule('load', reason, 'size')
692
+ else:
693
+ first: dict[str, Any] = {}
694
+ for left in (True, False):
695
+ broken, stats = _side_check(team, scenario, limits, left, first if left else None)
696
+ side = (stats.get('sides') or [None, None])[0 if left else 1] or {}
697
+ sides['left' if left else 'right'] = {
698
+ 'ok': broken is None,
699
+ 'rule': broken,
700
+ 'timings': _timings(side),
701
+ }
702
+ for action, count in (side.get('actions') or {}).items():
703
+ actions[action] = actions.get(action, 0) + count
704
+ if broken is not None:
705
+ rule = broken
706
+ break
707
+ if rule is None:
708
+ # The same steps from the same seed again, whose answers a deterministic team repeats.
709
+ again: dict[str, Any] = {}
710
+ broken, _ = _side_check(team, scenario, limits, True, again)
711
+ if broken is not None:
712
+ rule = broken
713
+ elif again.get('actions') != first.get('actions'):
714
+ reason = _label('deterministic', player=name)
715
+ if limits.get('deterministic'):
716
+ rule = _rule('deterministic', reason)
717
+ else:
718
+ notes.append(_label('warning_deterministic', player=name))
719
+ warnings = [*notes, *_setting_warnings(team)]
720
+ total = sum(actions.values())
721
+ if total:
722
+ action, count = max(actions.items(), key=lambda item: item[1])
723
+ if count > _ONE_ACTION * total:
724
+ share = f'{100 * count / total:.0f}'
725
+ warnings.append(_label('warning_action', player=name, action=action, share=share))
726
+ return {
727
+ 'team': team,
728
+ **_messages.named('name', name),
729
+ 'scenario': scenario,
730
+ 'ok': rule is None,
731
+ 'rule': rule,
732
+ 'timings': (sides.get('left') or {}).get('timings') or _timings({}),
733
+ 'sides': sides,
734
+ 'actions': dict(sorted(actions.items(), key=lambda item: int(item[0]))),
735
+ 'folder_mb': round(size, 3),
736
+ 'digest': folder_digest(team) if entry.get('kind') != 'builtin' else None,
737
+ 'warnings': warnings,
738
+ 'limits': dict(limits),
739
+ 'strict': limits is not LENIENT,
740
+ }
741
+
742
+
743
+ def replay(found: dict[str, Any], device: str = 'cpu') -> dict[str, Any]:
744
+ """Plays a match again from its seed and the actions of each step, as a match kept them.
745
+
746
+ Args:
747
+ found: What `play` filled under `replay`, the seed, the scenario file, the agents, the
748
+ action set, the ability of each side and the actions of every step.
749
+ device: `cpu` or `cuda`.
750
+
751
+ Returns:
752
+ The steps played and the score of the left and the right side at the end.
753
+ """
754
+ import torch
755
+
756
+ from cuju import BatchEnvironment
757
+
758
+ from .._format import recording as _recording
759
+
760
+ ability = tuple(found.get('ability') or (None, None))
761
+ batch = BatchEnvironment(
762
+ found['asset'],
763
+ agent_counts=[tuple(found['agents'])],
764
+ environment_count=1,
765
+ representation='raw',
766
+ seed=int(found['seed']),
767
+ auto_reset=False,
768
+ device=device,
769
+ difficulty=None if ability == (None, None) else [ability],
770
+ action_set=found['action_set'],
771
+ )
772
+ try:
773
+ reader = _recording.StateReader(int(batch.left_players[0] + batch.right_players[0]))
774
+ batch.reset()
775
+ steps = 0
776
+ for row in found['actions']:
777
+ batch.step(torch.tensor([row], dtype=torch.int32))
778
+ steps += 1
779
+ score = _play.frame_score(reader.frame(batch.get_state(0)))
780
+ finally:
781
+ batch.close()
782
+ return {'steps': steps, 'score': score}
783
+
784
+
785
+ def main(arguments: list[str] | None = None) -> None:
786
+ """Checks the team that the command line names and reports one line of JSON."""
787
+ parser = argparse.ArgumentParser(prog='python -m cuju.render._playing.strict')
788
+ parser.add_argument('--team', required=True)
789
+ parser.add_argument('--scenario', default=None)
790
+ parser.add_argument('--limits', type=json.loads, default=None)
791
+ options = parser.parse_args(arguments)
792
+ # The report keeps a copy of standard output, and everything else written there goes to
793
+ # standard error, as a match's reports do.
794
+ sys.stdout.flush()
795
+ reports = os.fdopen(os.dup(1), 'w', encoding='utf-8')
796
+ os.dup2(2, 1)
797
+ sys.stdout = sys.stderr
798
+ try:
799
+ report = preflight(options.team, options.scenario, options.limits)
800
+ except Exception as error:
801
+ report = {'error': _messages.described(error), **_messages.id_fields(error)}
802
+ reports.write(json.dumps(report) + '\n')
803
+ reports.flush()
804
+
805
+
806
+ if __name__ == '__main__':
807
+ # The check runs from the module as the package imports it, as a match does.
808
+ from cuju.render._playing import strict as _module
809
+
810
+ _module.main()