Map assigned field values by element attributes - #98
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Fixes #96.
Changes
Add
FieldValues.dict_of(attr="backend_repr")to build dictionaries of assigned field values keyed by an element attribute. The default keys are backend expressions, suitable for substitution;dict_of("name")produces a name-keyed mapping.Values are read directly from the field dataclass, preserving array shapes and symbolic objects without copying. Each call returns a new dictionary. The existing
asdict()behavior remains unchanged. The docstring describes missing/unhashable attributes and ordinary dictionary handling of repeated keys; the API documentation includes an executable substitution example.Validation
The complete suite passes with 94 passed and two existing skips on local macOS arm64 with Python 3.12, and on hosted Ubuntu 24.04 with Python 3.11 and 3.12, against commit
eaae310510675d6ba624c3d0cace56d2b6b5caf4.Hosted validation and before/after logs
Eight new tests cover symbol/name keys, scalar/vector/matrix values, reference identity, symbolic dataclasses, actual CasADi substitution, output fields, empty fields, invalid attributes and independent mapping objects. Restoring the original
fields.pymakes all eight new cases fail while the three existing field tests pass. Restoring the fix passes the complete suite again. The documentation example, Ruff checks, formatting andgit diff --checkalso pass.Compatibility and scope
Python 3.9 has eight pre-existing trajectory-test failures from
zip(..., strict=...). A separate hosted comparison restores both upstream source and upstream field tests and verifies the same eight failures and messages: upstream has 78 passes, this change has 86 passes, and both retain two skips. All eleven field tests pass on Python 3.9. Those unrelated trajectory paths and the declared minimum Python version are unchanged.No solver behavior, dependencies or existing conversion methods are modified. Validation workflows are confined to a separate fork branch and are not included in this PR.