JuliaDiff / JuliaDiff/ChainRulesTestUtils.jl
getting error in `FiniteDifferences.to_vec` when `test_rrule` for structured type
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 50
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
mutable struct Mat{AType<:AbstractMatrix}
A::AType
trait::Bool
end
Mat(A::AbstractMatrix) = Mat(A, false)
Base.adjoint(M::Mat) = Mat(M.A')
Base.:*(M::Mat, u::AbstractVector) = M.A * u
function ChainRulesCore.rrule(::typeof(*), M::Mat, u::AbstractVector)
project_u = ProjectTo(u)
function pb(dv)
du = @thunk(project_u( M' * dv ))
dA = @thunk(project_p( dv * u' ))
dM = Tangent{Mat}(;A=dA)
NoTangent(), dM, du
end
M*u, pb
end
In this case, test_rrule attempts to perturb the boolean trait causing this error:
Random.seed!(0)
N = 8
M = Mat(rand(N,N), false)
u = rand(N)
test_rrule(*, M, u)
est_rrule: * on Mat{Matrix{Float64}},Vector{Float64}: Error During Test at /Users/vp
/.julia/packages/ChainRulesTestUtils/2VT4F/src/testers.jl:193
Got exception outside of a @test
TypeError: non-boolean (Float64) used in boolean context
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/FiniteDifferences/VpgIT/src/to_vec.jl:0 [inlined]
[2] _force_construct
@ ~/.julia/packages/FiniteDifferences/VpgIT/src/to_vec.jl:27 [inlined]
...
caused by: InexactError: Bool(-0.01)
Stacktrace:
[1] Bool
@ ./float.jl:158 [inlined]
...
Test Summary: | Pass Error Total Time
test_rrule: * on Mat{Matrix{Float64}},Vector{Float64} | 3 1 4 5.3s
ERROR: LoadError: Some tests did not pass: 3 passed, 0 failed, 1 errored, 0 broken.
in expression starting at /Users/vp/.julia/dev/smo_adj/test/f3.jl:46
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example through test_rrule, then inspect FiniteDifferences.to_vec and its _force_construct path, with the call site in ChainRulesTestUtils/testers.jl:193 as context. The work is done when structured values with a Bool field no longer trigger an invalid Bool(Float64) perturbation and the reproduced test_rrule call completes without an error.
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
- 35/100