SciML / SciMLBase.jl

The Base interface of the SciML ecosystem
https://docs.sciml.ai/SciMLBase/stable
MIT License
119 stars 91 forks source link

Some SciMLFunctions don't error for too few arguments #608

Closed lxvm closed 5 months ago

lxvm commented 5 months ago

Is your feature request related to a problem? Please describe.

I find I often write a one-argument function to pass to an IntegralProblem but I only get an error at solve time. Here is a list of all SciMLFunctions and whether or not they throw a too-few argument error. Here is a test that confirms they all throw the expected error

using SciMLBase, Test

few(x) = x

@testset "too few argument error" begin
    @test_throws SciMLBase.TooFewArgumentsError ODEFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError DiscreteFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError ImplicitDiscreteFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError SplitFunction(few, few)
    @test_throws SciMLBase.TooFewArgumentsError DAEFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError DDEFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError SDEFunction(few, few)
    @test_throws SciMLBase.TooFewArgumentsError SplitSDEFunction(few, few, few)
    @test_throws SciMLBase.TooFewArgumentsError RODEFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError SDDEFunction(few, few)
    @test_throws SciMLBase.TooFewArgumentsError IncrementingODEFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError NonlinearFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError IntervalNonlinearFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError BVPFunction(few, few)
    @test_throws SciMLBase.TooFewArgumentsError IntegralFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError BatchIntegralFunction(few)
    @test_throws SciMLBase.TooFewArgumentsError OptimizationFunction(few)
end

Describe the solution you’d like

Ideally all SciMLFunctions should detect too few arguments and throw an error in that case.

Describe alternatives you’ve considered

Adding tests for these cases

Additional context

This would be a helpful usability and consistency feature

lxvm commented 5 months ago

I had a bad MWE since sin has methods with more than one argument defined in Lazy.jl. The updated comment above tests the expected error messages.