Skip to content

get_partials_definitions dedup guard compares a string to a list of messages #78

Description

@chrislupp

Problem

The deduplication guard in DisciplineClient.get_partials_definitions never fires, because it compares a str against a list of PartialsMetaData messages.

philote_mdo/general/discipline_client.py (main, lines 162-164):

for message in self._disc_stub.GetPartialDefinitions(empty.Empty()):
    if message.name not in self._partials_meta:      # str vs list[PartialsMetaData]
        self._partials_meta += [message]

Confirmed:

>>> meta = [data.PartialsMetaData(name="f", subname="x")]
>>> "f" not in meta
True

The condition is always true, so every message is appended unconditionally.

Consequence

Calling setup twice on one client appends the whole partials list again. _recover_partials then preallocates the same Jacobian block repeatedly, and declare_partials in the OpenMDAO binding (openmdao/utils.py:137-138) declares each pair more than once.

This is latent rather than active: nothing in the repo calls setup twice on a single client today. It becomes reachable as soon as a client is reused across jobs, which the job work makes a natural thing to want.

get_variable_definitions has the same append-rather-than-replace shape a few lines above, with no guard at all.

Proposed fix

Either compare on the identifying pair:

seen = {(m.name, m.subname) for m in self._partials_meta}
...
if (message.name, message.subname) not in seen:

or, more simply, clear both metadata lists at the start of each call so that a repeated setup replaces rather than accumulates. The second matches what the server does in Setup, which calls _clear_data() before rebuilding.

Notes

Found while tracing the client for #76. Pre-existing on main.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions