gras-engine 0.1.0__tar.gz → 0.4.0__tar.gz
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.
- {gras_engine-0.1.0 → gras_engine-0.4.0}/Cargo.lock +13 -2
- {gras_engine-0.1.0 → gras_engine-0.4.0}/Cargo.toml +3 -3
- {gras_engine-0.1.0 → gras_engine-0.4.0}/PKG-INFO +48 -18
- {gras_engine-0.1.0 → gras_engine-0.4.0}/README.md +20 -7
- {gras_engine-0.1.0 → gras_engine-0.4.0}/examples/cartpole.rs +204 -70
- {gras_engine-0.1.0 → gras_engine-0.4.0}/examples/mnist.rs +151 -43
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/Cargo.toml +2 -2
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/config.rs +3 -2
- {gras_engine-0.1.0 → gras_engine-0.4.0}/pyproject.toml +2 -2
- {gras_engine-0.1.0 → gras_engine-0.4.0}/python/README.md +45 -15
- {gras_engine-0.1.0 → gras_engine-0.4.0}/python/gras/__init__.py +6 -3
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/breed/child.rs +19 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/clock/lottery.rs +9 -5
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/clock/stop.rs +11 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder/topology.rs +1 -1
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/mod.rs +179 -3
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/tests.rs +149 -5
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/diversity/mod.rs +29 -3
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/founding/seed.rs +1 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/reporting/mod.rs +63 -24
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/reporting/reports.rs +48 -3
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/graph/network.rs +226 -6
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/graph/node.rs +1 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/graph/topology.rs +17 -1
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/state/persistence.rs +1 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/ascii.rs +28 -2
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/graph_utils.rs +20 -1
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/markdown.rs +262 -8
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/mermaid.rs +43 -11
- {gras_engine-0.1.0 → gras_engine-0.4.0}/LICENSE +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/benches/flamegraph.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/benches/memgraph.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/benches/ref_trainer.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/benches/stream.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/benches/support/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/examples/cartpole/tests.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/examples/python/load_gras_net.py +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/examples/python/test_load_gras_net.py +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/arrays.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/defaults.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/engine.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/gym.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/lib.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/logging.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/menu.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/gras-py/src/topology.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/breed/cull.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/breed/evolve.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/breed/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/clock/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/clock/smoothing.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/clock/step.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder/evolution.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder/lottery.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder/population.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder/ranking.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder/run.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config/builder.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/config.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/durability.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/evolution.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/exam.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/ranking.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/resume.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/core/roles.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/diversity/novelty.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/founding/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/founding/pool.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/founding/population.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/reporting/format.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/reporting/lineage.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/reporting/logging.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/start/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/start/rl_engine.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/start/run_spec.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/engine/start/tabular_engine.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/evolution/crossover.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/evolution/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/evolution/mutation.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/evolution/pools.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/evolution/selection.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/graph/inventory.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/graph/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/lib.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/spec/blueprint.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/spec/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/spec/network_facts.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/state/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/challenge.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/core.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/decision_lag.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/env.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/menu.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/optimizer.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/reinforce.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/schedule.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/stream.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/trainer/supervised.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/cfy.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/display.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/error.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/fitness.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/mod.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/race_steps.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/safetensors.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/score.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/seed.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/tabular_data.rs +0 -0
- {gras_engine-0.1.0 → gras_engine-0.4.0}/src/utils/training.rs +0 -0
|
@@ -202,6 +202,7 @@ dependencies = [
|
|
|
202
202
|
"anstyle",
|
|
203
203
|
"clap_lex",
|
|
204
204
|
"strsim",
|
|
205
|
+
"terminal_size",
|
|
205
206
|
]
|
|
206
207
|
|
|
207
208
|
[[package]]
|
|
@@ -407,7 +408,7 @@ checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
|
|
|
407
408
|
|
|
408
409
|
[[package]]
|
|
409
410
|
name = "gras"
|
|
410
|
-
version = "2.
|
|
411
|
+
version = "2.3.0"
|
|
411
412
|
dependencies = [
|
|
412
413
|
"clap",
|
|
413
414
|
"comfy-table",
|
|
@@ -426,7 +427,7 @@ dependencies = [
|
|
|
426
427
|
|
|
427
428
|
[[package]]
|
|
428
429
|
name = "gras-py"
|
|
429
|
-
version = "0.
|
|
430
|
+
version = "0.4.0"
|
|
430
431
|
dependencies = [
|
|
431
432
|
"gras",
|
|
432
433
|
"pyo3",
|
|
@@ -1042,6 +1043,16 @@ dependencies = [
|
|
|
1042
1043
|
"windows-sys",
|
|
1043
1044
|
]
|
|
1044
1045
|
|
|
1046
|
+
[[package]]
|
|
1047
|
+
name = "terminal_size"
|
|
1048
|
+
version = "0.4.4"
|
|
1049
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1050
|
+
checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874"
|
|
1051
|
+
dependencies = [
|
|
1052
|
+
"rustix",
|
|
1053
|
+
"windows-sys",
|
|
1054
|
+
]
|
|
1055
|
+
|
|
1045
1056
|
[[package]]
|
|
1046
1057
|
name = "thousands"
|
|
1047
1058
|
version = "0.2.0"
|
|
@@ -6,13 +6,13 @@ resolver = "2"
|
|
|
6
6
|
|
|
7
7
|
[package]
|
|
8
8
|
name = "gras"
|
|
9
|
-
version = "2.
|
|
9
|
+
version = "2.3.0"
|
|
10
10
|
edition = "2024"
|
|
11
11
|
description = "Neuroevolutionary architecture search: evolve the graph while its weights train, in Rust"
|
|
12
12
|
license = "MIT"
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
rust-version = "1.91"
|
|
15
|
-
keywords = ["neural-network", "
|
|
15
|
+
keywords = ["neural-network", "neuroevolution", "neural-search", "machine-learning", "evolutionary"]
|
|
16
16
|
categories = ["algorithms", "artificial-intelligence", "mathematics"]
|
|
17
17
|
homepage = "https://github.com/maulberto3/gras"
|
|
18
18
|
repository = "https://github.com/maulberto3/gras"
|
|
@@ -50,7 +50,7 @@ comfy-table = { version = "7.2", default-features = false }
|
|
|
50
50
|
[dev-dependencies]
|
|
51
51
|
proptest = "1.11.0"
|
|
52
52
|
dhat = "0.3"
|
|
53
|
-
clap = { version = "4.6.7", features = ["derive"] }
|
|
53
|
+
clap = { version = "4.6.7", features = ["derive", "wrap_help"] }
|
|
54
54
|
|
|
55
55
|
[profile.dev]
|
|
56
56
|
opt-level = 0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gras-engine
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: Intended Audience :: Science/Research
|
|
@@ -14,8 +14,8 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
|
14
14
|
Requires-Dist: pandas>=2.0 ; extra == 'test'
|
|
15
15
|
Provides-Extra: test
|
|
16
16
|
License-File: LICENSE
|
|
17
|
-
Summary:
|
|
18
|
-
Keywords: neural-architecture-search,evolution,
|
|
17
|
+
Summary: Evolutionary neural architecture search: a step-race that evolves, trains and ranks flodl networks
|
|
18
|
+
Keywords: neural-architecture-search,evolution,neuroevolution,automl,deep-learning,libtorch
|
|
19
19
|
Author-email: Mauricio Maroto <maulberto3@hotmail.com>
|
|
20
20
|
License: MIT
|
|
21
21
|
Requires-Python: >=3.12
|
|
@@ -42,6 +42,29 @@ Python binding.
|
|
|
42
42
|
pip install gras-engine
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
### CPU or CUDA — chosen at build time
|
|
46
|
+
|
|
47
|
+
PyPI publishes only the sdist (the wheel is a plain `linux` tag, not
|
|
48
|
+
manylinux, and carries no libtorch), so `pip install` compiles the extension on
|
|
49
|
+
your machine and the backend is baked into that binary. There is no runtime
|
|
50
|
+
switch: the default is CPU, and CUDA is one extra build argument.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# CUDA build — needs the CUDA libtorch at build AND import time
|
|
54
|
+
export LIBTORCH_PATH=~/.flodl/libtorch/precompiled/cu128
|
|
55
|
+
pip install gras-engine --config-settings="build-args=--features cuda"
|
|
56
|
+
# or, on older tooling: MATURIN_PEP517_ARGS="--features cuda" pip install gras-engine
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Environment variables never select the backend — `LIBTORCH_PATH` only says
|
|
60
|
+
*where* libtorch is, while the feature says *which device the compiled code
|
|
61
|
+
uses*. `gras.built_with_cuda` reports which one you got, so a notebook or a test
|
|
62
|
+
can refuse to assume a GPU it was not built for. A CPU build still works against
|
|
63
|
+
a CUDA libtorch — it simply stays on CPU. The reverse (a CUDA build with a
|
|
64
|
+
CPU-only libtorch) imports fine, because `libtorch_cuda.so` is loaded at run
|
|
65
|
+
time rather than linked, and fails on the first clock when the engine creates
|
|
66
|
+
its CUDA device.
|
|
67
|
+
|
|
45
68
|
```python
|
|
46
69
|
import gras
|
|
47
70
|
|
|
@@ -53,11 +76,15 @@ print(engine.run_dir) # results/<timestamp>/ — history.csv, nets/, champ
|
|
|
53
76
|
|
|
54
77
|
## Requirements
|
|
55
78
|
|
|
56
|
-
- **CPython ≥ 3.12.** 0.
|
|
57
|
-
|
|
58
|
-
- **
|
|
59
|
-
|
|
60
|
-
and
|
|
79
|
+
- **CPython ≥ 3.12.** 0.2 builds one `abi3` extension (`cp312-abi3`), so the
|
|
80
|
+
same compiled module works on 3.12, 3.13 and 3.14.
|
|
81
|
+
- **A build toolchain, because PyPI has only the sdist.** `pip install` runs
|
|
82
|
+
cargo on your machine, so the Rust toolchain is needed to build the binding
|
|
83
|
+
and a C++ toolchain (linker + libstdc++, e.g. `build-essential`) to link
|
|
84
|
+
libtorch. Rust and C++ are install-time requirements only — a wheel built
|
|
85
|
+
elsewhere needs neither at run time.
|
|
86
|
+
- **Linux x86_64.** The wheel the CI builds carries a plain `linux` tag, which
|
|
87
|
+
PyPI refuses, so nothing prebuilt is ever installed.
|
|
61
88
|
- **libtorch, which is not bundled.** The extension links `libtorch_cpu.so` and
|
|
62
89
|
`libc10.so` at run time, so the machine needs a libtorch distribution whose
|
|
63
90
|
ABI matches the build (libtorch 2.x).
|
|
@@ -68,8 +95,16 @@ Point the package at libtorch with one environment variable:
|
|
|
68
95
|
export LIBTORCH_PATH=/path/to/libtorch # the directory that contains lib/
|
|
69
96
|
```
|
|
70
97
|
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
**Where to put it:** `fdl libtorch download` writes `./libtorch` in the project
|
|
99
|
+
it runs from — the import (below) finds it there, and `fdl setup` points the
|
|
100
|
+
build at it. Otherwise any directory containing `lib/` works with
|
|
101
|
+
`LIBTORCH_PATH` pointing at it while the extension is built; the shared
|
|
102
|
+
convention is `~/.flodl/libtorch/precompiled/{cpu,cu128}` side by side, so one
|
|
103
|
+
machine holds both backends.
|
|
104
|
+
|
|
105
|
+
On import, `gras` looks for `libtorch_cpu.so` in `LIBTORCH_PATH`, then
|
|
106
|
+
`./libtorch`, then `$FLODL_VARIANT` and `{cpu, cuda, cu128}` under
|
|
107
|
+
`~/.flodl/libtorch/precompiled`, and
|
|
73
108
|
loads it with `ctypes` before the extension imports — so `LD_LIBRARY_PATH` is
|
|
74
109
|
not required. If nothing is found you get an ImportError naming libtorch, not
|
|
75
110
|
the loader's message. A CUDA build also loads `libtorch_cuda.so` from the same
|
|
@@ -158,19 +193,14 @@ language, and the parity guard says so.
|
|
|
158
193
|
- A Python loss or fitness closure is not accepted: the loss *is* the autograd
|
|
159
194
|
graph, and rankings must be re-derivable. The compiled name menus are the
|
|
160
195
|
contract; Rust is the door for anything custom.
|
|
161
|
-
- The
|
|
196
|
+
- The wheel is Linux x86_64. It is `linux_x86_64`, not `manylinux`: the
|
|
162
197
|
wheel needs the system's libtorch, so it cannot claim to be self-contained.
|
|
163
198
|
|
|
164
|
-
## Versions
|
|
165
|
-
|
|
166
|
-
`gras.__version__` is the **binding's** version (0.1.x) and moves independently
|
|
167
|
-
of the Rust crate (`gras` on crates.io, 1.2.0 pending publication). A binding release that
|
|
168
|
-
needs a newer crate says so in its release notes.
|
|
169
199
|
|
|
170
200
|
## More
|
|
171
201
|
|
|
172
|
-
- Tour notebook: `python/notebooks/python_bindings_tour.ipynb` —
|
|
173
|
-
|
|
202
|
+
- Tour notebook: `python/notebooks/python_bindings_tour.ipynb` — self-contained
|
|
203
|
+
cells, from a directory run to gym, arrays and the CPU/CUDA check.
|
|
174
204
|
- Rust crate: https://crates.io/crates/gras · docs: https://docs.rs/gras
|
|
175
205
|
- Source, issues and the publishing notes:
|
|
176
206
|
https://github.com/maulberto3/gras
|
|
@@ -93,7 +93,7 @@ A vacated slot does not stay empty. There are two ways in:
|
|
|
93
93
|
- **Crossover** draws two parents and builds a child from them. The default draw
|
|
94
94
|
is fitness-proportionate roulette, so stronger nets are more likely to be
|
|
95
95
|
picked but nothing is locked out. The fitter parent is the base by default,
|
|
96
|
-
and inherited genes can drift slightly (`drift_prob = 0.
|
|
96
|
+
and inherited genes can drift slightly (`drift_prob = 0.05`). If the two parents
|
|
97
97
|
cannot be combined, the roll is a no-op — a failed crossover never inserts a
|
|
98
98
|
random net.
|
|
99
99
|
- **Mutation** inserts a fresh random immigrant, built from the configured
|
|
@@ -205,12 +205,25 @@ cargo add gras
|
|
|
205
205
|
cargo add gras --features cuda
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
`gras` links libtorch dynamically and does not vendor it
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
`gras` links libtorch dynamically and does not vendor it: headers and libraries
|
|
209
|
+
at compile time, shared objects at run time. `flodl-sys` reads `LIBTORCH_PATH`
|
|
210
|
+
(falling back to `/usr/local/libtorch`), so any arrangement that exports that
|
|
211
|
+
variable works, and CUDA builds need a CUDA-enabled libtorch.
|
|
212
|
+
|
|
213
|
+
`fdl setup` — from `cargo install flodl-cli` — detects the hardware, downloads
|
|
214
|
+
the matching libtorch and points the variable at it. This repository's
|
|
215
|
+
`env_setup.sh` does the same for local development, searching in order:
|
|
216
|
+
|
|
217
|
+
1. `./libtorch`, or `./libtorch/{cpu,cuda,cu128}` — where `fdl libtorch download`
|
|
218
|
+
puts a build by default;
|
|
219
|
+
2. `~/.flodl/libtorch/precompiled/{cpu,cu128,cuda}` — fdl's shared copy, so
|
|
220
|
+
every project on a machine reuses one download per backend;
|
|
221
|
+
3. `/usr/local/libtorch`.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
source env_setup.sh # CPU
|
|
225
|
+
source env_setup.sh cuda # CUDA: skips directories without libtorch_cuda.so
|
|
226
|
+
```
|
|
214
227
|
|
|
215
228
|
## Get started
|
|
216
229
|
|
|
@@ -234,49 +234,191 @@ const EVAL_MATCHES_PER_STEP: usize = 5;
|
|
|
234
234
|
#[derive(clap::Parser, Debug)]
|
|
235
235
|
#[command(
|
|
236
236
|
name = "cartpole",
|
|
237
|
-
about = "CartPole RL race: every engine knob is a flag, each one carrying the value the run uses."
|
|
237
|
+
about = "CartPole RL race: every engine knob is a flag, each one carrying the value the run uses.",
|
|
238
|
+
// Help starts on the flag's own row (`next_line_help = false`) and wraps at a MEDIUM
|
|
239
|
+
// width — about the `--drift` row — instead of running to whatever the terminal is.
|
|
240
|
+
term_width = 200,
|
|
241
|
+
next_line_help = false
|
|
238
242
|
)]
|
|
239
243
|
struct Cli {
|
|
240
|
-
/// Every engine knob shared with the other example (`examples/common/mod.rs`).
|
|
241
|
-
#[command(flatten)]
|
|
242
|
-
engine: EngineArgs,
|
|
243
|
-
|
|
244
244
|
/// Pin the run seed (otherwise fresh per launch); it is always recorded in `engine.json`.
|
|
245
|
-
#[arg(long, value_name = "U64")]
|
|
245
|
+
#[arg(long, value_name = "U64", help_heading = "Run")]
|
|
246
246
|
seed: Option<u64>,
|
|
247
247
|
|
|
248
|
-
///
|
|
249
|
-
#[arg(
|
|
248
|
+
/// Name recorded in `engine.json` (informational only).
|
|
249
|
+
#[arg(
|
|
250
|
+
long,
|
|
251
|
+
value_name = "NAME",
|
|
252
|
+
default_value = "cartpole",
|
|
253
|
+
help_heading = "Run"
|
|
254
|
+
)]
|
|
255
|
+
run_name: String,
|
|
256
|
+
|
|
257
|
+
/// Survival bar (window centre): ENDS the race the clock the field reaches it. Read in the
|
|
258
|
+
/// run's own direction, so it also works on a minimize metric; a bar nothing reaches never fires.
|
|
259
|
+
#[arg(
|
|
260
|
+
long,
|
|
261
|
+
value_name = "F32",
|
|
262
|
+
default_value_t = 400.0,
|
|
263
|
+
help_heading = "Stop"
|
|
264
|
+
)]
|
|
250
265
|
stop_score: f32,
|
|
251
266
|
|
|
252
|
-
/// Clocks the best score may sit still
|
|
253
|
-
|
|
267
|
+
/// Clocks the best score may sit still (no gain over 0.01) before the race stops — no bar of
|
|
268
|
+
/// its own, so it also fires below the bar above; `0` = no-change stop off.
|
|
269
|
+
#[arg(long, value_name = "N", default_value_t = 40, help_heading = "Stop")]
|
|
254
270
|
stop_patience: usize,
|
|
255
271
|
|
|
272
|
+
/// Peak probability that a step fires the anti-plateau challenge; `0` disables it.
|
|
273
|
+
#[arg(
|
|
274
|
+
long,
|
|
275
|
+
value_name = "P",
|
|
276
|
+
default_value_t = DEFAULT_CHALLENGE_PROB,
|
|
277
|
+
help_heading = "Challenge"
|
|
278
|
+
)]
|
|
279
|
+
challenge_prob: f32,
|
|
280
|
+
|
|
281
|
+
// Flattened HERE, not first: clap orders help sections by first appearance, so the
|
|
282
|
+
// example's own "Run" / "Stop" / "Challenge" flags have to come before the shared
|
|
283
|
+
// block, while the shared sections (Tickets → Elites) keep their own order.
|
|
284
|
+
/// Every engine knob shared with the other example (`examples/common/mod.rs`).
|
|
285
|
+
#[command(flatten)]
|
|
286
|
+
engine: EngineArgs,
|
|
287
|
+
|
|
256
288
|
/// Candidates one mutation may spend clearing the floor; the most novel refusal is taken anyway.
|
|
257
|
-
#[arg(
|
|
289
|
+
#[arg(
|
|
290
|
+
long,
|
|
291
|
+
value_name = "N",
|
|
292
|
+
default_value_t = 10,
|
|
293
|
+
help_heading = "Mutation"
|
|
294
|
+
)]
|
|
258
295
|
mutation_novelty_draws: usize,
|
|
259
296
|
|
|
297
|
+
// The node-count bounds live here, MIN then MAX, because their upper bound is this
|
|
298
|
+
// example's own number (20) — split across `EngineArgs` the pair printed far apart.
|
|
299
|
+
/// Hidden nodes per net: the lower sampling bound.
|
|
300
|
+
#[arg(
|
|
301
|
+
long,
|
|
302
|
+
value_name = "N",
|
|
303
|
+
default_value_t = 2,
|
|
304
|
+
help_heading = "Search space"
|
|
305
|
+
)]
|
|
306
|
+
hidden_min: usize,
|
|
307
|
+
|
|
308
|
+
/// Hidden nodes per net: the upper sampling bound.
|
|
309
|
+
#[arg(
|
|
310
|
+
long,
|
|
311
|
+
value_name = "N",
|
|
312
|
+
default_value_t = 20,
|
|
313
|
+
help_heading = "Search space"
|
|
314
|
+
)]
|
|
315
|
+
hidden_max: usize,
|
|
316
|
+
|
|
317
|
+
/// Inputs per node: the lower sampling bound.
|
|
318
|
+
#[arg(
|
|
319
|
+
long,
|
|
320
|
+
value_name = "N",
|
|
321
|
+
default_value_t = 2,
|
|
322
|
+
help_heading = "Search space"
|
|
323
|
+
)]
|
|
324
|
+
inputs_min: usize,
|
|
325
|
+
|
|
326
|
+
/// Inputs per node: the upper sampling bound.
|
|
327
|
+
#[arg(
|
|
328
|
+
long,
|
|
329
|
+
value_name = "N",
|
|
330
|
+
default_value_t = 20,
|
|
331
|
+
help_heading = "Search space"
|
|
332
|
+
)]
|
|
333
|
+
inputs_max: usize,
|
|
334
|
+
|
|
335
|
+
/// Outputs per node: the lower sampling bound.
|
|
336
|
+
#[arg(
|
|
337
|
+
long,
|
|
338
|
+
value_name = "N",
|
|
339
|
+
default_value_t = 2,
|
|
340
|
+
help_heading = "Search space"
|
|
341
|
+
)]
|
|
342
|
+
outputs_min: usize,
|
|
343
|
+
|
|
344
|
+
/// Outputs per node: the upper sampling bound.
|
|
345
|
+
#[arg(
|
|
346
|
+
long,
|
|
347
|
+
value_name = "N",
|
|
348
|
+
default_value_t = 20,
|
|
349
|
+
help_heading = "Search space"
|
|
350
|
+
)]
|
|
351
|
+
outputs_max: usize,
|
|
352
|
+
|
|
353
|
+
/// Counter stride of the hidden-width range (`2` = 16, 18, 20, …).
|
|
354
|
+
#[arg(
|
|
355
|
+
long,
|
|
356
|
+
value_name = "N",
|
|
357
|
+
default_value_t = 2,
|
|
358
|
+
help_heading = "Search space"
|
|
359
|
+
)]
|
|
360
|
+
hidden_dim_stride: usize,
|
|
361
|
+
|
|
362
|
+
/// Chance a slot of an inherited circuit (mask, activation, combine, standardize, dropout,
|
|
363
|
+
/// port activation, hidden width, the `input_reach` wiring gene) is re-drawn.
|
|
364
|
+
#[arg(
|
|
365
|
+
long,
|
|
366
|
+
value_name = "P",
|
|
367
|
+
default_value_t = gras::engine::config::DEFAULT_TOPOLOGY_DRIFT,
|
|
368
|
+
help_heading = "Search space"
|
|
369
|
+
)]
|
|
370
|
+
drift: f32,
|
|
371
|
+
|
|
372
|
+
/// Dropout probability applied when building the run's networks.
|
|
373
|
+
#[arg(
|
|
374
|
+
long,
|
|
375
|
+
value_name = "P",
|
|
376
|
+
default_value_t = DROPOUT_PROB,
|
|
377
|
+
help_heading = "Search space"
|
|
378
|
+
)]
|
|
379
|
+
dropout: f32,
|
|
380
|
+
|
|
381
|
+
/// Recurrence: every hidden node whose input width equals its output width feeds its
|
|
382
|
+
/// pre-activation back through its OWN layer once — the same weights, twice. CartPole nets
|
|
383
|
+
/// are 4 → 2, so only the hidden nodes can loop; a crossover child can drift the gene either
|
|
384
|
+
/// way.
|
|
385
|
+
#[arg(
|
|
386
|
+
long,
|
|
387
|
+
value_name = "BOOL",
|
|
388
|
+
num_args = 0..=1,
|
|
389
|
+
default_missing_value = "true",
|
|
390
|
+
default_value_t = true,
|
|
391
|
+
help_heading = "Search space"
|
|
392
|
+
)]
|
|
393
|
+
recur: bool,
|
|
394
|
+
|
|
260
395
|
/// What the net is told about the past: `none`, `delta` (obs − prev) or a smoothed `ema`; the fed row doubles.
|
|
261
396
|
#[arg(
|
|
262
397
|
long,
|
|
263
398
|
value_name = "KIND",
|
|
264
399
|
value_parser = ["none", "delta", "ema"],
|
|
265
|
-
default_value = "none"
|
|
400
|
+
default_value = "none",
|
|
401
|
+
help_heading = "Policy (RL)"
|
|
266
402
|
)]
|
|
267
403
|
obs_memory: String,
|
|
268
404
|
|
|
269
|
-
/// EMA β for `--obs-memory ema
|
|
270
|
-
#[arg(
|
|
405
|
+
/// EMA β for `--obs-memory ema`. Clamped to `0.0 …= 1.0`.
|
|
406
|
+
#[arg(
|
|
407
|
+
long,
|
|
408
|
+
value_name = "F32",
|
|
409
|
+
default_value_t = 0.9,
|
|
410
|
+
help_heading = "Policy (RL)"
|
|
411
|
+
)]
|
|
271
412
|
obs_memory_beta: f32,
|
|
272
413
|
|
|
273
|
-
/// Exam axis: `true`
|
|
414
|
+
/// Exam axis: `true` draws fresh shared starts every CLOCK, `false` restores the ERA exam.
|
|
274
415
|
#[arg(
|
|
275
416
|
long,
|
|
276
417
|
value_name = "BOOL",
|
|
277
418
|
num_args = 0..=1,
|
|
278
419
|
default_missing_value = "true",
|
|
279
|
-
default_value_t = true
|
|
420
|
+
default_value_t = true,
|
|
421
|
+
help_heading = "Policy (RL)"
|
|
280
422
|
)]
|
|
281
423
|
per_clock_exam: bool,
|
|
282
424
|
|
|
@@ -285,20 +427,22 @@ struct Cli {
|
|
|
285
427
|
long,
|
|
286
428
|
value_name = "KIND",
|
|
287
429
|
value_parser = ["turns", "return"],
|
|
288
|
-
default_value = "turns"
|
|
430
|
+
default_value = "turns",
|
|
431
|
+
help_heading = "Policy (RL)"
|
|
289
432
|
)]
|
|
290
433
|
signal: String,
|
|
291
434
|
|
|
292
435
|
/// Discount γ shaping the per-turn returns the GRADIENT uses; the fitness stays undiscounted.
|
|
293
|
-
#[arg(long, value_name = "GAMMA", default_value_t = DISCOUNT)]
|
|
436
|
+
#[arg(long, value_name = "GAMMA", default_value_t = DISCOUNT, help_heading = "Policy (RL)")]
|
|
294
437
|
discount: f32,
|
|
295
438
|
|
|
296
|
-
/// TRAIN arm: `argmax`
|
|
439
|
+
/// TRAIN arm: `argmax` or `softmax` sampling at T from the episode's own seeded generator.
|
|
297
440
|
#[arg(
|
|
298
441
|
long,
|
|
299
442
|
value_name = "RULE",
|
|
300
443
|
value_parser = ["argmax", "softmax"],
|
|
301
|
-
default_value = "argmax"
|
|
444
|
+
default_value = "argmax",
|
|
445
|
+
help_heading = "Policy (RL)"
|
|
302
446
|
)]
|
|
303
447
|
action_rule: String,
|
|
304
448
|
|
|
@@ -307,47 +451,20 @@ struct Cli {
|
|
|
307
451
|
long,
|
|
308
452
|
value_name = "RULE",
|
|
309
453
|
value_parser = ["argmax", "softmax"],
|
|
310
|
-
default_value = "argmax"
|
|
454
|
+
default_value = "argmax",
|
|
455
|
+
help_heading = "Policy (RL)"
|
|
311
456
|
)]
|
|
312
457
|
eval_action_rule: String,
|
|
313
458
|
|
|
314
|
-
/// Temperature T for the softmax arm — SHARED by `--action-rule` and `--eval-action-rule
|
|
315
|
-
///
|
|
316
|
-
#[arg(
|
|
459
|
+
/// Temperature T for the softmax arm — SHARED by `--action-rule` and `--eval-action-rule`:
|
|
460
|
+
/// smaller sharpens toward argmax, larger flattens the policy.
|
|
461
|
+
#[arg(
|
|
462
|
+
long,
|
|
463
|
+
value_name = "T",
|
|
464
|
+
default_value_t = ACTING_TEMPERATURE,
|
|
465
|
+
help_heading = "Policy (RL)"
|
|
466
|
+
)]
|
|
317
467
|
softmax_temperature: f32,
|
|
318
|
-
|
|
319
|
-
/// Chance a slot of an inherited circuit (mask, activation, combine, standardize, dropout,
|
|
320
|
-
/// port activation, hidden width, the `input_reach` wiring gene) is re-drawn.
|
|
321
|
-
#[arg(long, value_name = "P", default_value_t = 0.05)]
|
|
322
|
-
drift: f32,
|
|
323
|
-
|
|
324
|
-
/// Name recorded in `engine.json` (informational only).
|
|
325
|
-
#[arg(long, value_name = "NAME", default_value = "cartpole")]
|
|
326
|
-
run_name: String,
|
|
327
|
-
|
|
328
|
-
/// Peak probability that a step fires the anti-plateau challenge; `0` disables it.
|
|
329
|
-
#[arg(long, value_name = "P", default_value_t = DEFAULT_CHALLENGE_PROB)]
|
|
330
|
-
challenge_prob: f32,
|
|
331
|
-
|
|
332
|
-
/// Hidden nodes per net: the upper sampling bound.
|
|
333
|
-
#[arg(long, value_name = "N", default_value_t = 20)]
|
|
334
|
-
hidden_max: usize,
|
|
335
|
-
|
|
336
|
-
/// Inputs per node: the upper sampling bound.
|
|
337
|
-
#[arg(long, value_name = "N", default_value_t = 20)]
|
|
338
|
-
inputs_max: usize,
|
|
339
|
-
|
|
340
|
-
/// Outputs per node: the upper sampling bound.
|
|
341
|
-
#[arg(long, value_name = "N", default_value_t = 20)]
|
|
342
|
-
outputs_max: usize,
|
|
343
|
-
|
|
344
|
-
/// Counter stride of the hidden-width range (`2` = 16, 18, 20, …).
|
|
345
|
-
#[arg(long, value_name = "N", default_value_t = 2)]
|
|
346
|
-
hidden_dim_stride: usize,
|
|
347
|
-
|
|
348
|
-
/// Dropout probability applied when building the run's networks.
|
|
349
|
-
#[arg(long, value_name = "P", default_value_t = DROPOUT_PROB)]
|
|
350
|
-
dropout: f32,
|
|
351
468
|
}
|
|
352
469
|
|
|
353
470
|
/// The body reads `cli.pop`, `cli.max_steps`, … — the overlay never hides a knob.
|
|
@@ -382,29 +499,46 @@ fn main() {
|
|
|
382
499
|
let baseline = random_baseline(20);
|
|
383
500
|
println!("baseline: random policy survives {baseline:.1} turns (race must beat this)");
|
|
384
501
|
|
|
385
|
-
|
|
502
|
+
// The fitness metric to be reported and optimized: "match_survival" by default. Declared
|
|
503
|
+
// BEFORE the config so the two stop criteria can read its direction.
|
|
504
|
+
let fitness = Fitness::reported(Direction::Maximize, "match_survival");
|
|
505
|
+
let direction = fitness.direction();
|
|
506
|
+
// STOP 2 of 3: the solved bar. The window CENTRE reaching `--stop-score` ends the race on
|
|
507
|
+
// that clock (compared in `direction`, so it is not a maximize-only `>=`); the step budget
|
|
508
|
+
// and the no-change stop below are the other two.
|
|
509
|
+
let bar = cli.stop_score;
|
|
510
|
+
let builder = common::engine_config(rl_race_config_builder(), &cli.engine, log_level)
|
|
386
511
|
// This example's own half: the flags whose default is its identity.
|
|
387
512
|
.set_run_name(cli.run_name.clone())
|
|
388
513
|
.set_topology_drift(cli.drift)
|
|
514
|
+
.set_topology_min_hidden_num_nodes(cli.hidden_min)
|
|
389
515
|
.set_topology_max_hidden_num_nodes(cli.hidden_max)
|
|
516
|
+
.set_topology_min_inputs_per_node(cli.inputs_min)
|
|
390
517
|
.set_topology_max_inputs_per_node(cli.inputs_max)
|
|
518
|
+
.set_topology_min_outputs_per_node(cli.outputs_min)
|
|
391
519
|
.set_topology_max_outputs_per_node(cli.outputs_max)
|
|
392
520
|
.set_topology_hidden_dim_stride(cli.hidden_dim_stride)
|
|
393
521
|
.set_topology_dropout_prob(cli.dropout)
|
|
394
522
|
.set_mutation_novelty_draws(cli.mutation_novelty_draws)
|
|
395
|
-
|
|
396
|
-
.set_stop_plateau(cli.stop_score, cli.stop_patience)
|
|
523
|
+
.set_stop_custom(move |snap: &RaceSnapshot| common::bar_reached(bar, snap))
|
|
397
524
|
.set_topology_input_dim(input_dim)
|
|
398
|
-
.set_topology_output_dim(ACTIONS)
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
525
|
+
.set_topology_output_dim(ACTIONS);
|
|
526
|
+
// The four POOLS (`--feature-split-pool`, `--combine-op-pool`, `--activation-pool`,
|
|
527
|
+
// `--standardize-pool`) are wired inside `common::engine_config`, where they are declared —
|
|
528
|
+
// a one-entry pool pins a policy, the same call `set_topology_feature_split` makes.
|
|
529
|
+
// STOP 3 of 3: the no-change stop, with NO bar of its own — `common::no_bar` parks the
|
|
530
|
+
// plateau's target on the hopeless end of this run's direction, so its target gate is always
|
|
531
|
+
// open and only the patience window decides. `0` turns it off (a `0` patience would stop at
|
|
532
|
+
// clock 0 instead).
|
|
533
|
+
let mut builder = builder;
|
|
534
|
+
if cli.stop_patience > 0 {
|
|
535
|
+
builder = builder.set_stop_plateau(common::no_bar(direction), cli.stop_patience);
|
|
536
|
+
}
|
|
537
|
+
let mut config = builder.build();
|
|
538
|
+
// Recurrence is a per-net gene carried in the blueprint, not a run measured from the
|
|
539
|
+
// header: stamp the flag on the search space so founders and immigrants are born with it.
|
|
540
|
+
config.topology.options.recur = cli.recur;
|
|
541
|
+
|
|
408
542
|
// The signal the step optimizes and ranks on: `return` at γ on request, else the const.
|
|
409
543
|
|
|
410
544
|
let signal = match cli.signal.as_str() {
|