Skip to content

Order of output dict keys for auto-diff endpoints can be unexpected #238

@jpbrodrick89

Description

@jpbrodrick89

As jvp_outputs, vjp_inputs, jac_inputs and jac_outputs are validated as sets by pydantic their order depends on the random hash assigned to them at validation. As the validated set is often used to explicitly create the (nested) dicts output by the AD endpoints and the order is not modifed by validation,

On the other hand, if using json outputs, the order will not necessarily correspond to either the user-provided argument or the validated set but will be alphabetically sorted by pydantic on serialization.

While this is surprising behaviour, potential fixes will likely introduce other confusing/surprising behaviour (as we would have to pick one specific ordering to guarantee in all cases) and may be sensitive to future changes in Pydantic/FastAPI, as such there are no immediate plans to address this. Please report here if you run into any usage issues due to this and believe a fix should be further explored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions