Skip to content

allow an OC print format without a format word - #548

Closed
wpbonelli wants to merge 1 commit into
modflowpy:developfrom
wpbonelli:oc-format-optional
Closed

wpbonelli wants to merge 1 commit into
modflowpy:developfrom
wpbonelli:oc-format-optional

Conversation

@wpbonelli

@wpbonelli wpbonelli commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Status: to be reworked after a devtools DFN migration fix lands, which corrects this record, including requiring columns, width and digits. This PR should then reduce to the regenerated files, KNOWN_PASSING, snapshots and tests, without dfn_fixes.py.

Simulation.load fails on an OC print format with no format word, which MF6 accepts. mf6/test/test060_gms_ets was the one model in mf6/test that couldn't load:

HEAD PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4
TypeError: Oc.Format.__init__() missing 1 required positional argument: 'format_'

The DFN says optional false for format, but MF6's print_format reads whatever words follow DIGITS, and without any keeps the caller's edit descriptor.

  • Add utils/codegen/dfn_fixes.py, applied when generating classes and grammars, marking formatrecord's format optional. A hand edit wouldn't survive flopy4 mf6 sync, which regenerates from any release's DFNs
  • Regenerate from the contract's DFN commit (203d72f0), so _contract.py is unchanged. This affects GWF, GWT, GWE, CHF and OLF OC, and GWT IST. Regenerating without the fix reproduced the committed files exactly, so this diff is only the fix
  • Add the model to KNOWN_PASSING, with snapshots

A missing word stays missing when written. MF6 (6.9.0.dev0+1469b358b9.dirty) runs the rewritten model to normal termination, with head and budget files byte-identical to the original's.

Behavior changes

format_ was first only because attrs sorts required fields first. All the fields are optional now, so the class follows the DFN and file order, columns, width, digits, format_:

  • The tuple form changes from ("GENERAL", 10, 12, 6) to (10, 12, 6, "GENERAL"). The old form raises a TypeError
  • A fully positional Format("GENERAL", 10, 12, 6) is silently misread, and writes COLUMNS GENERAL WIDTH 10 DIGITS 12 6. Nothing in the repo calls it this way, but keywords are safer

Partial print formats no longer raise in flopy4, since they lacked the format word:

  • COLUMNS 10 WIDTH 11 and COLUMNS 10 now load, and MF6 runs them to normal termination. MF6 ignores a format without COLUMNS, WIDTH and DIGITS, without saying so, so the format is silently lost
  • An empty HEAD PRINT_FORMAT now loads, and MF6 rejects it. test_from_tokens_missing_required_raises relied on this raising, so it now uses Npf.Rewet

Not done

  • Changing the DFN to optional true in MF6. It's still worth doing, and this fix becomes a no-op once it lands, then can go when no supported release needs it
  • Requiring columns, width and digits. MF6 doesn't reject input without them, but it needs all three to use the format, so requiring them would catch the partial and empty cases above. Existing tests rely on the looser forms, like from_tokens(["COLUMNS", "10", "exponential"]), and would need rewriting

🤖 Generated with Claude Code

MF6 runs `HEAD PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4`, keeping the
caller's edit descriptor, but the DFN says `optional false` for `format`, so
`Simulation.load` raised a TypeError on mf6/test/test060_gms_ets.

Correct this during generation, so it survives a sync from any MF6 release.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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