JuliaDiff / JuliaDiff/ChainRulesTestUtils.jl

Better error message when using `test_scalar` for functions with multiple outputs

Open
#106 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation good first issue
Dominant language
Julia
Stars
50
Forks
18
PR merge metrics
No merged PRs in 30d

Description

When using test_scalar to test functions with multiple outputs the error messages are uninformative:

julia> simo(x) = (x, 2x)

julia> @scalar_rule simo(x) 1.0 2.0

julia> test_scalar(simo, 3.0)
Test Summary:                 | Pass  Total
simo at 3.0, with tangent 1.0 |    3      3
ERROR: MethodError: no method matching one(::Tuple{Float64,Float64})
Closest candidates are:
  one(::Type{Missing}) at missing.jl:103
  one(::BitArray{2}) at bitarray.jl:400
  one(::Missing) at missing.jl:100
  ...
Stacktrace:
 [1] #test_scalar#26(::Float64, ::Float64, ::FiniteDifferences.FiniteDifferenceMethod{Array{Int64,1},Array{Float64,1},FiniteDifferences.var"#27#29"{FiniteDifferences.FiniteDifferenceMethod{Array{Int64,1},Array{Float64,1},FiniteDifferences.var"#default_bound_estimator#19"{Int64}}}}, ::NamedTuple{(),Tuple{}}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(test_scalar), ::typeof(simo), ::Float64) at /Users/mzgubic/Projects/ChainRules.jl/dev/ChainRulesTestUtils/src/testers.jl:154
 [2] test_scalar(::Function, ::Float64) at /Users/mzgubic/Projects/ChainRules.jl/dev/ChainRulesTestUtils/src/testers.jl:125
 [3] top-level scope at REPL[23]:1

We could also support multiple outputs though I don't think it is a priority given rrule_test and frule_test are available.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The failing path is ChainRulesTestUtils/src/testers.jl at line 154; start by reproducing the shown test_scalar(simo, 3.0) case and inspect how the tuple output reaches one. Define an informative failure for multiple outputs, or confirm the supported behavior boundary, then run the existing test suite and add coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.