feat(model): allow {0,1} bounds for binaries in add_variables#778
Open
FBumann wants to merge 1 commit into
Open
feat(model): allow {0,1} bounds for binaries in add_variables#778FBumann wants to merge 1 commit into
FBumann wants to merge 1 commit into
Conversation
78a4598 to
1a6195c
Compare
Binary bounds could previously only be set via the .lower/.upper setters after creation; add_variables(binary=True, ...) raised on any lower/upper. Now it accepts bounds as long as every value is 0 or 1 (unset bounds still default to 0/1), and validates the rest. Refs #776 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1a6195c to
b0642f2
Compare
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.
Note
The following content was generated by AI.
Summary
Refs #776 (the follow-up requested in the issue comment). Stacked on #777 — review/merge that first; the base will retarget to
masteronce #777 lands.add_variables(binary=True, ...)previously raised on anylower/upper, so binary bounds could only be set via the.lower/.uppersetters after creation. This allows passing them directly at construction, as long as every bound value is 0 or 1.Behavior
0/1.ValueError: Binary variable {lower,upper} bounds must be 0 or 1.io_api="direct"andio_api="lp".Note on netcdf / backward compat
add_variablesonly validates inputs — no downstream code changed.read_netcdfrebuilds variables directly from stored data (bypassingadd_variables), but no load-time normalization is needed: 0/1 binary defaulting and the current netcdf format both landed in v0.2, so any file today'sread_netcdfcan parse already stores binaries as[0,1]. Older files withinf-bound binaries predate the format and aren't loadable anyway.Tests
test_variable_assignment_binary_with_bounds— per-elementupperand scalarlower=1at construction.test_variable_assignment_binary_fractional_bound_error— fractional bound raises.test_variable_assignment_binary_with_error(lower=-2) still raises under the new validation.