Skip to content

BUG: TypeError: _LevMarLSQFitter2x2.objective_function() got an unexpected keyword argument 'fit_param_indices' #17085

Closed

Description

@pllim

As reported by @mcara at #16982 (comment) , #16982 to fix backward compatibility that #16673 broke was incomplete fix. More fix is needed.

TypeError: _LevMarLSQFitter2x2.objective_function() got an unexpected keyword argument 'fit_param_indices'

Activity

  1. added
    API changePRs and issues that change an existing API, possibly requiring a deprecation period
    on Sep 27, 2024
  2. added this to the v7.0.0 milestone on Sep 27, 2024
  3. astrofrog commented on Sep 30, 2024

    @astrofrog
    Member

    Just thinking out loud, I feel like a lot of things on fitters are public and shouldn't really be. Shouldn't the only public method on fitters be __call__? I wonder if a solution would be that the base classes actually implement _objective_function and use it and this would support the additional kwargs and then check if objective_function is defined on the function and call it without the kwarg if so, but potentially emit a deprecation warning about objective_function?

    Alternatively, we could check whether objective_function has be overriden and if so not pass the extra arguments if so?

  4. Cadair commented on Sep 30, 2024

    @Cadair
    Member

    I like the idea of migrating to _objective_function, I am not sure I see much in the way of legitimate use of customising that method when what you should be fitting is the model.

    I think the thing here is the difference between the user API and the developer API for people who want to write their own fitters outside of core? I think that the developer API for this fitting module is shockingly bad and ill documented. The class hierarchy here is a mess and I think it needs a cleanup.

    In this case the error was caused by us passing in an kwarg to a function not expecting it: https://github.com/spacetelescope/tweakwcs/pull/212/files#diff-fb9a903d102a166923773794afe09730d72c88f416b641c178b2c213c6986aa5R853

    I don't know how to handle supporting people writing their own fitters, and actually making forward progress on performance here. I do not want to start passing around fitting state on the class itself just to prevent any potential API breakage for people writing their own fitters as subclasses of _NonLinearLSQFitter (or it's public subclasses).

    My preferred solution to this would be to add a breaking changelog entry and move onto cleaning up the whole mess at a later date.

  5. mcara commented on Sep 30, 2024

    @mcara
    Contributor

    I like the idea of migrating to _objective_function, I am not sure I see much in the way of legitimate use of customising that method when what you should be fitting is the model.

    Does "...customising that method..." refer to _objective_function or objective_function? I think there are legitimate uses when users want to minimize a different measure from what current fitters offer. Maybe I am mis-understanding the issue (sorry, I have not been following closely the fitting module and recent PRs).

    Looking back: #11736 would be an example. And following links in the issues, I get to #11735 which could be related to this discussion.

    I think the thing here is the difference between the user API and the developer API for people who want to write their own fitters outside of core? I think that the developer API for this fitting module is shockingly bad and ill documented. The class hierarchy here is a mess and I think it needs a cleanup.

    I actually do not find the user-facing documentation that bad, i.e.,
    https://docs.astropy.org/en/stable/modeling/new-fitter.html

    I don't know how to handle supporting people writing their own fitters, and actually making forward progress on performance here. I do not want to start passing around fitting state on the class itself just to prevent any potential API breakage for people writing their own fitters as subclasses of _NonLinearLSQFitter (or it's public subclasses).

    My preferred solution to this would be to add a breaking changelog entry and move onto cleaning up the whole mess at a later date.

    Not being a maintainer for this module, it is hard for me to evaluate consequences for this. However, I just find hard to believe that subclassing fitters is not needed at all. If that is the case, why are fitters classes at all and not functions?

    CC: @WilliamJamieson

  6. astrofrog commented on Sep 30, 2024

    @astrofrog
    Member

    I think the preferred API that we should be striving towards is that of the Fitter class where users can specify optimisers and statistics.

  7. astrofrog commented on Sep 30, 2024

    @astrofrog
    Member

    (But the current non linear fitters need to be migrated to that API)

  8. Cadair commented on Oct 1, 2024

    @Cadair
    Member

    I have opened a PR with a changelog entry calling out the API change for people who are subclassing one of the non-linear fitters.

    I think that you are right @mcara the public API for subclassing Fitter is pretty well documented and should obviously be supported for custom things. What we are talking about here though is a breakage for people subclassing one of the existing non-linear fitter classes, which are a lot more complex.

    As @astrofrog says, I think the whole module could do with a API cleanup to make everything clear, but I don't expect many people will be doing what you are doing and subclassing an existing non-linear fitter to adjust the objective_function? Maybe they will who knows.

    I am open to better options here, but I also think this small API change is worth the significant performance increase it enables.


    As a sidenote @mcara you can also make use of the new kwarg in your fitter to get a nice perf boost, by passing it through to fitter_to_model_params.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API changePRs and issues that change an existing API, possibly requiring a deprecation periodBugmodeling

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions