Skip to content

Patch: Save NPY files by default, CSV with filetype="csv" - #16

Merged
areenberg merged 3 commits into
masterfrom
general_development
Nov 14, 2026
Merged

areenberg merged 3 commits into
masterfrom
general_development

Conversation

@areenberg

Copy link
Copy Markdown
Owner

saveToFile() gets a filetype argument, "npy" (the default) or "csv", so results can be saved in both formats, just as the input files can be read in both.

  • "npy" writes a NumPy .npy file with one entry per state: int64 for the policy, float64 for the value vector. np.load gives the same array as getPolicy()/getValueVector(), and the file is byte-identical to what np.save writes.
  • "csv" writes the same comma-separated file as before.
  • filetype is accepted in any case, e.g. "NPY".
  • fileName now defaults to None, which means result.npy, or result.csv with filetype="csv".
  • A name ending in .csv with filetype="npy", or in .npy with filetype="csv", raises a ValueError that names the filetype to use.
  • Both writers now raise an error if the file can't be fully written, e.g. on a full disk.

Breaking change: The default output is now NPY. Existing calls like saveToFile("policy.csv") raise a ValueError; add filetype="csv" to keep CSV output.

Tests: Case 1 of test_output.py covers both file types, the default names, upper-case filetypes and the error cases, also on the compiled module. test_order.py now reads the saved policy as .npy. All 12 tests pass locally (macOS, Python 3.14).

Docs: The wiki's Classes and methods page is updated to match; the wiki is a separate repository and is pushed separately.

@areenberg
areenberg merged commit 077e94d into master Nov 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant