Skip to main content

factory-sim

A fast C simulator of a small slice of Factorio's early game: a character walking, reaching and hand-mining; burner mining drills; stone furnaces; fuel; ground item piles. It exists to train reinforcement-learning policies quickly, with the real game kept as the verifier.

It is checked, decision by decision and tick by tick, against golden traces recorded on Factorio 2.0.60 by FactorioGym. A mechanic is added here only after it has been measured there.

Status

M3, the simulator core, is done:

  • All 12 golden scenarios match the real game at every decision, in both free-running and one-step sync.
  • All 8 tick-level traces match on every tick.
  • A single environment runs 173k decisions/s, and 8 threads run 850k in total (bench/RESULTS.md).

M4, the RL contract, is done too. fsim.rl.RlEnv speaks FactorioRL's parameterized-v1 action space (MultiDiscrete[22, 33, 122, 5, 15, 4]) and its local-v2 tensor observation for construct_smelting_line and build_line:

  • It covers the encoder, argument domains, the action mask, vector decoding, the goal vector, rewards, termination, and the verification window.
  • Driven by each golden trace's recorded action vectors, every decision matches FactorioRL:
    • each encoded tensor hashes identically, bit for bit;
    • the mask, goal, reward, reward components, termination, truncation, success and decode failures all match.
  • The whole RL path runs 60k decisions/s on one environment and 382k on eight threads.

Next is M5: a PPO learner trained here, then evaluated on the real game through FactorioRL.

What it simulates today:

  • Character: 4-way walking, with collision against walls, machines and water. Reach and build distance. Hand-mining ore and picking machines back up.
  • Burner mining drill: fuel and energy buffer, mining progress, drop position per facing, delivery into a furnace or onto the ground, jams.
  • Stone furnace: iron smelting, fuel, the 54-ore source slot, idle and no-fuel states.
  • Transfers: clamped transfers, with the same choice of slot and the same refusals as the game.
  • Bookkeeping:
    • handles, running actions and the event log, as FactorioRL's mod keeps them;
    • production statistics, and the steam-power trigger 24 ticks after the 50th plate.

How parity is judged:

  • Doubles are compared to within 1e-12. The game prints some doubles with an imprecise last digit, and one progress bar is matched to about one part in 10^14.
  • Ore under a drill is compared as a total over the drill's four tiles. The order a drill visits its tiles follows the engine's internal entity order, which could not be reduced to a rule, and the encoder cannot see the difference.
  • Everything else must match exactly.

Install

pip install git+https://github.com/divagr18/factory-sim   # compiles csrc/: needs a C compiler

This installs the simulator (fsim) and the program-search loop (evolve); the benchmark map ships inside the package. Extras: [gym] for the Gymnasium adapter, [puffer] for PufferLib's (see docs/interfaces.md).

Build and test

uv sync                         # installs the checkout editable, compiling csrc/
uv run python build_fsim.py          # rebuilds fsim/_fsim in place after a C change
uv run pytest                   # parity against tests/golden
uv run python bench/bench.py

tools/sync_golden.py --from ../FactorioRL refreshes the golden traces from a FactorioRL checkout, checking every trace's hash.

Citing

If you use factory-sim in academic work, please cite it. GitHub's "Cite this repository" button reads CITATION.cff; in BibTeX:

@software{agrawal2026factorysim,
  author  = {Agrawal, Divyansh},
  title   = {{factory-sim}: a fast, tick-exact simulator of an early-game factory},
  year    = {2026},
  version = {0.1.1},
  url     = {https://github.com/divagr18/factory-sim},
  license = {Apache-2.0}
}

License

Apache-2.0; see LICENSE. See NOTICE for what this project does and does not contain.

Release files for factory-sim 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for factory-sim 0.1.1
File Size Uploaded
factory_sim-0.1.1.tar.gz 234.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for factory-sim 0.1.1
File
factory_sim-0.1.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
factory_sim-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
factory_sim-0.1.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
factory_sim-0.1.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
factory_sim-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
factory_sim-0.1.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
factory_sim-0.1.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
factory_sim-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
factory_sim-0.1.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 2.1 MB

Release files / factory_sim-0.1.1.tar.gz

Download URL factory_sim-0.1.1.tar.gz
Size 234.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ca98676aac8906139c3bac58681593115ad22ff54385b45a77586a3c29bdcb32
BLAKE2b-256 checksum
How to use checksums
e45d62612b07cd47313ce569cdd52a776b4a79517be9c238611b8a4dfd852450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp313-cp313-win_amd64.whl

Download URL factory_sim-0.1.1-cp313-cp313-win_amd64.whl
Size 176.7 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
8b625b82ad4e1525d3749283bff9f350f3499a46cbdfafcdb55d9f77cdeb26bf
BLAKE2b-256 checksum
How to use checksums
a3d521a1d95d483742d5a62c96526c8354f2077cb6f841a0d1dd9803d0067711
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl

Download URL factory_sim-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Size 266.1 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4906bb6635a48c2e019539f810acf83148e1744f38933125539bbc34976aaee5
BLAKE2b-256 checksum
How to use checksums
84a3c9aadf9c5080f852e41b9633386cb0c86c02f0ad6669143b1c0a60a05191
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL factory_sim-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Size 179.4 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4a7f02fd292206e37064f0765d8b73134b399ad9c837afafe58d0b7611812c49
BLAKE2b-256 checksum
How to use checksums
4414c21273f784baa414e18663c71bae2ff66980dedd8008e69a54213d15113d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp312-cp312-win_amd64.whl

Download URL factory_sim-0.1.1-cp312-cp312-win_amd64.whl
Size 176.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
2130f1f04f51b1c09ea977b58592055f271e2b31e8d2563dcb6fdf4a33917720
BLAKE2b-256 checksum
How to use checksums
d0fe811ae87124b2326decb4d087b04f697904de6ecd0f29571a0ae4920082b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl

Download URL factory_sim-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Size 266.2 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
51b23561d8bb242687b918a03ee8be790e8d4053e515dd18246590fa54767869
BLAKE2b-256 checksum
How to use checksums
ff05a36baf4777b35d1fbbd768e2c941ccca18d71bc0f434a18e4da8c3b1a2d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL factory_sim-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Size 179.4 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8707d5a4bc26b241047209a0c9124b9a2b09b78a66b2ea9a8dc4039c1114fab2
BLAKE2b-256 checksum
How to use checksums
284e5d7d3594df65b1d8383ccbf74033850d417f28c0421676e595c301a9d8a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp311-cp311-win_amd64.whl

Download URL factory_sim-0.1.1-cp311-cp311-win_amd64.whl
Size 176.7 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1ca6232339e38bb8371ca0187a4cd1606a1a577b6dc949c8e77271a1b4b1cc01
BLAKE2b-256 checksum
How to use checksums
0132f31b8ea9098e9ed549404796573c39d879c9453d067c2c88da5e2d272ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl

Download URL factory_sim-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Size 265.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
785c2584166d7bb7ad623cf45260048909693467b875b55dc2e6a6ac5495fc6d
BLAKE2b-256 checksum
How to use checksums
e2308795f18c3b8c8e90016275bdd2de11742d6aab9fa8328f39b012e5579c69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / factory_sim-0.1.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL factory_sim-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Size 179.3 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2fbabb7a902a3ddd976d8c34295469f4841c53be722acc8b9d595cab745ad7f3
BLAKE2b-256 checksum
How to use checksums
fcba51a4ec7044e0698adaa2ee29f76be83b7361c728ce47dcd7443ae8a20843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

10 release files

0.1.2

10 release files

This release

0.1.1 This release

10 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page