Skip to content

Register implicit residual metadata and disambiguate partial shape lookups - #83

Merged
chrislupp merged 2 commits into
developfrom
bugfix/79-residual-metadata-index
Aug 30, 2026
Merged

Register implicit residual metadata and disambiguate partial shape lookups#83
chrislupp merged 2 commits into
developfrom
bugfix/79-residual-metadata-index

Conversation

@chrislupp

Copy link
Copy Markdown
Collaborator

Fixes #79.

Problem

Discipline.add_output appends a second VariableMetaData typed kResidual for implicit disciplines, but never registered that key in _declared. The duplicate-name index added in #74 therefore covered the output and not its residual, so the index and the metadata list could drift.

The same name collision showed up downstream: DisciplineServer.preallocate_partials and DisciplineClient._recover_partials both built shapes = {var.name: tuple(var.shape) for var in ..._var_meta}. The residual comes after the output in the list, so it overwrote the output entry and every partial of an implicit discipline was sized against the residual, on both sides of the pair. Benign while the two shapes agree, wrong the moment they diverge.

Changes

  • add_output registers (kResidual, name) alongside (kOutput, name), and the dead res_meta.type = kOutput assignment that was immediately overwritten is gone.
  • New shared helpers in philote_mdo/utils/helper.py: build_shape_index (keyed on (type, name)), get_function_shape (residual first, then output) and get_variable_shape (input first, then output). A partial is always d(function)/d(variable), where the function is an output for an explicit discipline or a residual for an implicit one, and the variable is an input or, for implicit disciplines, an output — the lookup order encodes exactly that.
  • Both partial-preallocation sites use those helpers, so they now agree with SetVariableShapes, which already indexes by (type, name).
  • A partial declared against a name with no metadata raises PhiloteValidationError instead of a bare KeyError.

The wire protocol is unchanged; this is all local metadata bookkeeping.

Tests

Six new tests: residual registration and redeclaration after _clear_data (test_discipline.py), and the diverged-shape lookup plus the unknown-name error on both the server and the client. All six fail against the pre-fix source and pass after. Full suite: 315 passed.

Changelog

Two entries under [Unreleased] → Bug Fixes.

…okups

Discipline.add_output appends a second VariableMetaData typed kResidual for
implicit disciplines, but never registered that key in _declared, so the
duplicate-name index covered the output and not its residual. The residual
key is now registered alongside the output, and the dead kOutput assignment
that preceded it is gone.

Both preallocate_partials (server) and _recover_partials (client) keyed the
shape lookup on the variable name alone. The residual comes after the output
in the metadata list, so it shadowed the output and every partial of an
implicit discipline was sized against the residual entry regardless of which
side of the pair was being resolved. Both sites now build a (type, name)
index and resolve the function against the residual (falling back to the
output) and the variable against the input (falling back to the output),
which is how SetVariableShapes already indexes. An unknown name now raises
PhiloteValidationError rather than KeyError.

Closes #79.
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chrislupp chrislupp self-assigned this Aug 30, 2026
@chrislupp chrislupp added the bug Something isn't working label Aug 30, 2026
@chrislupp chrislupp added this to the Version 0.9.0 milestone Aug 30, 2026
@chrislupp
chrislupp merged commit 37a6387 into develop Aug 30, 2026
8 checks passed
@chrislupp
chrislupp deleted the bugfix/79-residual-metadata-index branch August 30, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant