Arraymancer viability spike #2

Closed
opened 2026-08-15 22:05:08 +02:00 by SirStone · 2 comments
Owner

Question

Does Arraymancer compile and train a small MLP on the user's Nim 2.2.x + NixOS setup?

Run the XOR perceptron example from Arraymancer's repo. Confirm: nimble install works, autograd works, Adam optimizer runs, weights are extractable after training. Report any compilation errors or runtime issues.

This is a go/no-go gate for the ML stack choice.

## Question Does Arraymancer compile and train a small MLP on the user's Nim 2.2.x + NixOS setup? Run the XOR perceptron example from Arraymancer's repo. Confirm: nimble install works, autograd works, Adam optimizer runs, weights are extractable after training. Report any compilation errors or runtime issues. This is a go/no-go gate for the ML stack choice.
SirStone added the wayfinder:task label 2026-08-15 22:05:08 +02:00
Author
Owner

Arraymancer spike results — NixOS / Nim 2.2.4

Verdict: WORKS, with one NixOS-specific workaround required.


Environment

  • Nim 2.2.4 (NixOS, amd64)
  • Nimble 0.20.1
  • Arraymancer 0.7.33 (latest)

Step-by-step results

nimble install arraymancer -y — SUCCESS, ~73 seconds

  • Downloaded arraymancer + all deps (nimblas, nimlapack, nimcuda, nimcl, opencl, stb_image, zip, untar, nim-clblast)
  • Several Info: Ignoring ... because out of range messages for older dep versions — harmless, nimble resolved correctly
  • No errors

nim c test_xor.nim — SUCCESS, 3.2 seconds (debug build)

  • Compiled 127,857 lines across arraymancer + stdlib
  • Peak memory: 339 MB
  • No warnings or errors

Running the binary — FAILS without fix, WORKS with fix

  • NixOS issue: BLAS/OpenBLAS is in the Nix store (/nix/store/z3y5mylg3144fyy6v99r5iwakw0sr6jb-openblas-0.3.29/lib/), not in the standard dynamic linker path
  • Fix: LD_LIBRARY_PATH=/nix/store/z3y5mylg3144fyy6v99r5iwakw0sr6jb-openblas-0.3.29/lib ./test_xor
  • Without it: could not load: lib(blas|cblas|openblas).so(|.3|.2|.1|.0)
  • This is a NixOS packaging concern, not an Arraymancer bug

Training results (2-layer MLP, Adam lr=0.01, 1000 epochs, batch=4)

Epoch  200  loss = 0.178398
Epoch  400  loss = 0.048284
Epoch  600  loss = 0.014194
Epoch  800  loss = 0.006782
Epoch 1000  loss = 0.004104

Final predictions:

[0,0] -> 0.0275  (rounded: 0, expected: 0)  ✓
[0,1] -> 0.9236  (rounded: 1, expected: 1)  ✓
[1,0] -> 0.9535  (rounded: 1, expected: 1)  ✓
[1,1] -> 0.0873  (rounded: 0, expected: 0)  ✓

All 4 XOR outputs predicted correctly. Training time: 0.10s.


NixOS integration path

To avoid requiring LD_LIBRARY_PATH at runtime, the real project will need one of:

  1. A shell.nix / flake.nix that brings openblas into the build environment (standard NixOS approach)
  2. Compile with -d:openblas and -passL:-L/nix/store/.../lib baked in
  3. Use nix develop shell where BLAS is on the linker path automatically

Option 1 (flake.nix with pkgs.openblas in buildInputs) is the standard and will resolve the runtime issue entirely.


Conclusion

Arraymancer is viable on this machine. The library installs, compiles, and runs correctly. The only friction is the standard NixOS dynamic linking issue, which is solved by the flake. No Nim or Arraymancer code changes needed.

## Arraymancer spike results — NixOS / Nim 2.2.4 **Verdict: WORKS, with one NixOS-specific workaround required.** --- ### Environment - Nim 2.2.4 (NixOS, amd64) - Nimble 0.20.1 - Arraymancer 0.7.33 (latest) --- ### Step-by-step results **`nimble install arraymancer -y`** — SUCCESS, ~73 seconds - Downloaded arraymancer + all deps (nimblas, nimlapack, nimcuda, nimcl, opencl, stb_image, zip, untar, nim-clblast) - Several `Info: Ignoring ... because out of range` messages for older dep versions — harmless, nimble resolved correctly - No errors **`nim c test_xor.nim`** — SUCCESS, 3.2 seconds (debug build) - Compiled 127,857 lines across arraymancer + stdlib - Peak memory: 339 MB - No warnings or errors **Running the binary** — FAILS without fix, WORKS with fix - NixOS issue: BLAS/OpenBLAS is in the Nix store (`/nix/store/z3y5mylg3144fyy6v99r5iwakw0sr6jb-openblas-0.3.29/lib/`), not in the standard dynamic linker path - Fix: `LD_LIBRARY_PATH=/nix/store/z3y5mylg3144fyy6v99r5iwakw0sr6jb-openblas-0.3.29/lib ./test_xor` - Without it: `could not load: lib(blas|cblas|openblas).so(|.3|.2|.1|.0)` - This is a NixOS packaging concern, not an Arraymancer bug --- ### Training results (2-layer MLP, Adam lr=0.01, 1000 epochs, batch=4) ``` Epoch 200 loss = 0.178398 Epoch 400 loss = 0.048284 Epoch 600 loss = 0.014194 Epoch 800 loss = 0.006782 Epoch 1000 loss = 0.004104 ``` **Final predictions:** ``` [0,0] -> 0.0275 (rounded: 0, expected: 0) ✓ [0,1] -> 0.9236 (rounded: 1, expected: 1) ✓ [1,0] -> 0.9535 (rounded: 1, expected: 1) ✓ [1,1] -> 0.0873 (rounded: 0, expected: 0) ✓ ``` All 4 XOR outputs predicted correctly. Training time: **0.10s**. --- ### NixOS integration path To avoid requiring `LD_LIBRARY_PATH` at runtime, the real project will need one of: 1. A `shell.nix` / `flake.nix` that brings `openblas` into the build environment (standard NixOS approach) 2. Compile with `-d:openblas` and `-passL:-L/nix/store/.../lib` baked in 3. Use `nix develop` shell where BLAS is on the linker path automatically Option 1 (flake.nix with `pkgs.openblas` in `buildInputs`) is the standard and will resolve the runtime issue entirely. --- ### Conclusion Arraymancer is viable on this machine. The library installs, compiles, and runs correctly. The only friction is the standard NixOS dynamic linking issue, which is solved by the flake. No Nim or Arraymancer code changes needed.
Author
Owner

Resolution: Arraymancer 0.7.33 compiles and trains on Nim 2.2.4 + NixOS. XOR MLP trains in 0.10s, all predictions correct. NixOS requires LD_LIBRARY_PATH for OpenBLAS (standard flake.nix fix). Go/no-go: GO. Arraymancer is the ML stack.

**Resolution:** Arraymancer 0.7.33 compiles and trains on Nim 2.2.4 + NixOS. XOR MLP trains in 0.10s, all predictions correct. NixOS requires LD_LIBRARY_PATH for OpenBLAS (standard flake.nix fix). Go/no-go: **GO.** Arraymancer is the ML stack.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#2