Problem
OpenMdaoSubProblem.compute_partials builds the of= and wrt= lists for compute_totals by appending once per entry in _partials_map, with no deduplication.
philote_mdo/openmdao/group.py:371-377:
func = []
var = []
for val in self._partials_map.values():
func += [val[0]]
var += [val[1]]
totals = self._prob.compute_totals(of=func, wrt=var)
_partials_map is keyed on the (output, input) pair, so an output with three inputs contributes its name to of three times, and an input feeding several outputs repeats in wrt.
Consequence
OpenMDAO tolerates the repeats, so results are correct. The cost is redundant work inside compute_totals, which grows with the number of declared partials -- exactly the disciplines where a gradient call is already the expensive part.
This is the mildest of the four issues found alongside #76 and is a cleanup rather than a defect.
Proposed fix
Deduplicate while preserving order:
func = list(dict.fromkeys(val[0] for val in self._partials_map.values()))
var = list(dict.fromkeys(val[1] for val in self._partials_map.values()))
The lookup below is unaffected, since it indexes totals by the (of, wrt) pair rather than by position:
for local, sub in self._partials_map.items():
partials[local] = totals[sub]
Worth a test that declares an output against two inputs and asserts the lists handed to compute_totals contain no repeats.
Notes
Found while tracing OpenMdaoSubProblem for #76. Pre-existing on main.
Problem
OpenMdaoSubProblem.compute_partialsbuilds theof=andwrt=lists forcompute_totalsby appending once per entry in_partials_map, with no deduplication.philote_mdo/openmdao/group.py:371-377:_partials_mapis keyed on the(output, input)pair, so an output with three inputs contributes its name toofthree times, and an input feeding several outputs repeats inwrt.Consequence
OpenMDAO tolerates the repeats, so results are correct. The cost is redundant work inside
compute_totals, which grows with the number of declared partials -- exactly the disciplines where a gradient call is already the expensive part.This is the mildest of the four issues found alongside #76 and is a cleanup rather than a defect.
Proposed fix
Deduplicate while preserving order:
The lookup below is unaffected, since it indexes
totalsby the(of, wrt)pair rather than by position:Worth a test that declares an output against two inputs and asserts the lists handed to
compute_totalscontain no repeats.Notes
Found while tracing
OpenMdaoSubProblemfor #76. Pre-existing onmain.