Deduplicate the of/wrt lists passed to compute_totals (#80) - #84
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
force-pushed
the
bugfix/80-subproblem-totals-dedup
branch
from
August 30, 2026 22:16
243cf87 to
86f0aeb
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.
Closes #80.
Problem
OpenMdaoSubProblem.compute_partialsbuilt theofandwrtlists forcompute_totalsby 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 inof, and an input feeding several outputs repeated inwrt.OpenMDAO tolerates the repeats and the assembled derivatives were correct — the lookup below indexes
totalsby the(of, wrt)pair rather than by position — butcompute_totalsredid 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_argumentsdeclaresy1against bothx1andx2andy2againstx1— the case that repeats a name on both sides — wrapscompute_totalsto 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.