Skip to content

Map assigned field values by element attributes - #98

Open
sylvesterkaczmarek wants to merge 1 commit into
nasa:mainfrom
sylvesterkaczmarek:fix/96-field-value-dictionaries-20260926
Open

sylvesterkaczmarek wants to merge 1 commit into
nasa:mainfrom
sylvesterkaczmarek:fix/96-field-value-dictionaries-20260926

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

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.py makes 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 and git diff --check also 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.

This branch has not been deployed

No deployments
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.

make it easier to make dictionaries of field elements assigned values

1 participant