Skip to content

[BUG] Short-circuit WrappedOptimizer when passed an existing SINDy optimizer #572

@Jacob-Stevens-Haas

Description

@Jacob-Stevens-Haas

WrappedOptimizer allows users to make SINDy-compatible optimizers (which accept unbiasing and normalizing) from generic regression optimizers. However, its called on a range of SINDy optimizers that natively prevent unbiasing.

Reproducing code example:

import pysindy as ps

ps.TrappingSR3(unbias=True)  # ValueError: Trapping does not allow unbiasing
ps.WrappedOptimizer(ps.TrappingSR3(), unbias=True)  # Should raise a ValueError but does not

Solution

Pretty straightforwardly, we can prevent this by implementing WrappedOptimizer.__new__(cls, optimizer, ...) and checking the type of optimizer. If it's already a ps.BaseOptimzer, then just return it (potentially, verifying that a conflicting unbias is not present)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions