Repository navigation
AgentiGrid: MATPOWER reader/writer hardening (8 defects) - #150
Merged
Merged
Conversation
…nd trips Five defects found while specifying the parser and writer: 1. Rows with a non-numeric value were skipped with only a log warning, so a bus, generator or branch could silently disappear; too-short rows crashed with IndexError. Known sections (bus, gen, branch, gencost) now raise ValueError naming the section and row for non-numeric values, column counts outside the section's limits, and non-integral values in integer columns. 2. Valid MATLAB syntax was misread: two rows on one line became one garbage row and comma-separated rows were all dropped. These, '...' continuations, unterminated blocks and a missing mpc.bus now raise ValueError. 3. The writer crashed on Inf/NaN, which the reader accepts. They are written as Inf/-Inf/NaN; bus solution columns no longer lose precision to .4f. 4. Every read/write round trip added another "MATPOWER Case Format" header line. Writing is now idempotent. 5. Case version '1' was accepted although ExaGO reads version 2; it now raises. A missing version still means '2'. CRLF input is normalised on read and output is always LF. The function line always carries network.casename. All 29 case files in datafiles/ still parse and round-trip to equivalent networks. New tests/grid_files/test_matpower_hardening.py (29 tests, 22 fail without the fix). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rounding, baseMVA literals Three defects found by property-based round-trip testing: 1. A finite value near the float maximum was written with 10 significant digits that round past it and read back as Inf. The writer now falls back to the exact representation when rounding overflows. 2. A value that rounds to an integer (e.g. 9999999999.5) was written as "1e+10" the first time and "10000000000" after re-reading, so writing was not idempotent. The integer form is now decided on the rounded value. 3. mpc.baseMVA was read with a digits-and-dots pattern: "1e2" (and "1e+15", which the writer itself emits for large values) was silently read as 1, and a negative value was reported as missing. Any numeric literal (sign, exponent, Inf/NaN) on an mpc.baseMVA line is now accepted, text in comments is ignored, and a non-numeric value raises ValueError. 18 more tests in tests/grid_files/test_matpower_hardening.py (12 fail without the fix). All 29 case files in datafiles/ still round-trip. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #138 (fork PR, closed so CI can run).
Depends on #149 — review only the last two commits.
Merge request type
Relates to
This MR updates
claude_code_changes.md)Summary
Follow-up to #137 (
};terminator for cell arrays), as agreed: same two files, found while writing an independent spec for the MATPOWER reader and writer.Depends on #137. Until that merges, this branch also shows PR-A's two commits; please review only the last two ("reject malformed input, stable round trips" and "exact near-max floats, idempotent rounding, baseMVA literals"). Once #137 is merged I'll rebase this branch onto
developso only these two commits remain.Defects fixed
IndexError.ValueErrornaming the section and row for non-numeric values, wrong column counts, and non-integral values in integer columns.ValueErrorwith a clear message. The same applies to...continuations, unterminated blocks and a missingmpc.bus.Inf/NaN, which the reader accepts.Inf/-Inf/NaN.'1'was accepted even though ExaGO reads version 2.ValueError. A missing version still means'2'.Also: CRLF input reads the same as LF and output is always LF. The
function mpc = …line always carriescasename.Compatibility
All 29 case files in
datafiles/(fromcase5tocase_ACTIVSg10k, including the CRLF ones) still parse and round-trip to equivalent networks. Sections other than bus, gen, branch and gencost (areas,dcline, …) are kept as opaque text and are not validated.Tests
The new
tests/grid_files/test_matpower_hardening.pyhas 29 tests; 22 of them fail without the fix. The existing suite still passes, and PR-B applies cleanly on top.