Conversation
Game-agnostic neural seats for any Polyworld game: a strict package loader, the GOTANET1 model format with its FP32 MinGRU actor, and a host layer that a game drives through one NeuralContract. - neural_package.nim: ZIP of exactly manifest.json + policy.bas + model.bin; sha256 file pins; per-entry size caps checked before decompressing and a bounded inflate (boundedinflate.nim, adapted from zippy); strict keys and JSON kinds; game-supplied extra manifest/decoder keys and an options parser. Read-only results. - neural_actor.nim: GOTANET1 loader and inference, dims from the header, read-only Actor; loadActor(bytes, contract) checks the budget, contract hashes, inputs and heads. - neural_host.nim: NeuralContract (one constructor that hashes the contract texts and checks the logit count), NeuralBrain with the frame and recurrent-state lifecycle, the per-seat op budget, the telemetry line, argmax/sampling/masked decoders, and the BASIC functions run_neural_net / neuralObservation / neuralLogits / neuralState / neuralModel. - coworld.nim: PK-prefixed staged players are read up to 16 MiB; failPlayer ends an episode with a real reason. - coworld/runtime/neural_package.py: the Python staging validator, parameterized by contract. - tests: a toy contract proves the tier is game-agnostic; one corruption suite runs through both validators in CI. - docs/neural-policies.md: how to add neural seats to a game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
daveey
force-pushed
the
polyworld-neural-tier
branch
from
September 25, 2026 22:20
2acbd74 to
576f1af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a game-agnostic tier for neural policies. A player can submit a small network next to a BASIC program, and it runs natively inside a Polyworld game under a fixed operation budget. There is no game code in the tier: a game plugs in with one
NeuralContract. The how-to isdocs/neural-policies.md.What's in it
src/polyworld/neural_package.nim: the package loader. A package is a ZIP with exactlymanifest.json,policy.basandmodel.bin.boundedinflate.nim, zippy's inflate with an output limit), so a zip bomb never expands in memory. A package over 16 MiB is rejected as "package exceeds 16 MiB".3.0andtrueare not integers,temperature: trueis not a number, and a non-finite number (NaN,Infinity,1e999) is rejected. A malformed manifest can't raise a defect and take the server down; every failure is aValueErrorwith the reason.parsePackage(bytes, contract)returns a read-onlyNeuralPackage(getters). The raw model bytes are not kept, only the loaded actor.argmax, orsamplewith its temperature.src/polyworld/neural_actor.nim: GOTANET1, the Polyworld neural model format (GotA introduced it; the byte layout and magic are unchanged). The actor is an FP32 MinGRU with its dimensions in the model header.Actoris read-only.src/polyworld/neural_host.nim: the host side.NeuralContracthas one constructor,initNeuralContract. It computes the observation and action hashes from the contract texts and asserts that the game's logit count equals the sum of the head sizes.buildObservation,decodeAction,head,tick, plus the optionallog,actionMaskandtelemetryExtra.loadActor(bytes, contract)checks the op budget, both contract hashes, the input size and the head sizes.NeuralBrainis the per-seat state: the decision frame and the recurrent-state lifecycle (zero on the first frame and on the first frame after a death;resetBraingives a fresh seat).run_neural_net,neuralObservation,neuralLogits,neuralState,neuralModel.coworld.nim:PK\x03\x04is read up to 16 MiB. A bigger file is read one byte past the cap, so it is reported as too large rather than as a broken ZIP.failPlayer(slot, detail, message)ends an episode before play with a real reason.compilePlayernow uses it; its seat log line, status andfailure.jsonare the same as before.coworld/runtime/neural_package.py: the Python staging validator, parameterized by aContract. Rawzipfile/zlib/ JSON errors come out asPackageError.build.yml):tests/test_neural_tier.nim(intests.nim) runs the whole tier on a toy contract (3 inputs, heads [2, 3]): load, strict keys and JSON kinds, in-memory ZIP and model corruption, budget rejection, the recurrent-state lifecycle and reset, the telemetry line format, decoders and the BASIC functions.tests/neural_cases.py+tests/test_neural_cases.nim: one corruption suite that the Python and Nim validators must agree on.Evidence
At this PR's head.
tests/test_neural_tier.nim(toy contract)3.0/2.0/trueas integers,temperature: true,NaNand1e999in the manifest, and a 30,000-deep nested arraybuild.ymltest listbuild.ymlon this branch (ubuntu, macOS, Windows; dispatched, since the workflow only runs on PRs intomain)Notes
failPlayeris new public API incoworld.nim. The only visible change incompilePlayeris the text of theCoworldErrorraised after collection, which now carries the failure reason instead of "Player compilation failed".🤖 Generated with Claude Code