DifferentialEquations.jl icon indicating copy to clipboard operation
DifferentialEquations.jl copied to clipboard

Add checking for unsupported keyword arguments

Open annahdo opened this issue 3 years ago • 7 comments

I can run a function with wrong keyword arguments:

sol = solve(prob, undefined_keyword=4.0)

It is hard to find potential spelling mistakes in keyword arguments like this.

Per default this should be checked, shouldn't it?

Best

annahdo avatar Aug 12 '20 10:08 annahdo

@kanav99 has looked into this a bit. https://github.com/SciML/OrdinaryDiffEq.jl/pull/783 . I think it's a good time to finish this though. We should just clean up the major upstream libraries that we know have issues here and finally make the last of the kwarg handling not splat.

ChrisRackauckas avatar Aug 13 '20 05:08 ChrisRackauckas

@YingboMa @devmotion @frankschae @isaacsas @kanav99 @Vaibhavdixit02 let's just do this. We should remove the kwargs... of every integrator. In many repos it will warn already if an argument is allowed in the common interface but not used by a given integrator, i.e. passing Jacobians to lsoda, and I think we want to do a similar filter and warn. Though I think that should be a separate verbose_interfacecheck = true.

ChrisRackauckas avatar Jul 26 '21 22:07 ChrisRackauckas

I don't actually like that. It's very handy to write

function foo(args...; kwargs...)
    something_else(;kwargs...)
    prob = ODEProblem(...; kwargs...)
    solve(prob; kwargs...)
...

and leave which kwarg to apply to Julia. I think we should add verbose_interfacecheck = false as the default, so that users can enable the check when it's necessary.

YingboMa avatar Jul 27 '21 17:07 YingboMa

If it's a kwarg, no one will ever do it. I can't tell you how many kwarg typos I've seen recently. I think people need to start using named tuples to hold different sets of splatted kwargs.

ChrisRackauckas avatar Jul 27 '21 20:07 ChrisRackauckas

Or default verbose_interfacecheck = true

YingboMa avatar Jul 28 '21 01:07 YingboMa

Do you have an example of what you intend by using named tuples in place of kwarg spatting?

isaacsas avatar Jul 28 '21 16:07 isaacsas

function foo(args...; diffeq_kwargs = (saveat=0.1, alg=Tsit5()), other_kwargs...)
    something_else(;other_kwargs...)
    prob = ODEProblem(...; diffeq_kwargs...)
    solve(prob)
...

ChrisRackauckas avatar Jul 29 '21 11:07 ChrisRackauckas