Skip to content

Deduplicate the of/wrt lists passed to compute_totals (#80) - #84

Merged
chrislupp merged 1 commit into
developfrom
bugfix/80-subproblem-totals-dedup
Aug 30, 2026
Merged

Deduplicate the of/wrt lists passed to compute_totals (#80)#84
chrislupp merged 1 commit into
developfrom
bugfix/80-subproblem-totals-dedup

Conversation

@chrislupp

Copy link
Copy Markdown
Collaborator

Closes #80.

Problem

OpenMdaoSubProblem.compute_partials built the of and wrt lists for compute_totals by appending once per entry in _partials_map, which is keyed on the (output, input) pair. An output declared against three inputs therefore named itself three times in of, and an input feeding several outputs repeated in wrt.

OpenMDAO tolerates the repeats and the assembled derivatives were correct — the lookup below indexes totals by the (of, wrt) pair rather than by position — but compute_totals redid the work, and the cost grows with the number of declared partials.

Fix

Both lists are now built with dict.fromkeys, which drops the repeats and preserves declaration order.

Test

test_compute_partials_deduplicates_totals_arguments declares y1 against both x1 and x2 and y2 against x1 — the case that repeats a name on both sides — wraps compute_totals to capture its arguments, and asserts neither list has repeats while the three derivatives still come back as 2, 3, and 4. It fails against the old code and passes against the new.

Full suite: 327 passed.

@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
OpenMdaoSubProblem.compute_partials built the argument lists for
compute_totals by appending once per entry in _partials_map, which is
keyed on the (output, input) pair.  An output declared against three
inputs therefore named itself three times in `of`, and an input feeding
several outputs repeated in `wrt`.

OpenMDAO tolerates the repeats and the assembled derivatives were
correct -- the lookup below indexes `totals` by the (of, wrt) pair, not
by position -- but compute_totals redid the work, and the cost grows
with the number of declared partials.

Both lists are now built with dict.fromkeys, which drops the repeats
and preserves declaration order.
@chrislupp
chrislupp force-pushed the bugfix/80-subproblem-totals-dedup branch from 243cf87 to 86f0aeb Compare August 30, 2026 22:16
@chrislupp
chrislupp merged commit 1115058 into develop Aug 30, 2026
8 checks passed
@chrislupp
chrislupp deleted the bugfix/80-subproblem-totals-dedup branch August 30, 2026 22:39
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