From 062080b9ee9ba1baa1a704d2ed348b6da1958331 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Thu, 17 Dec 2020 17:30:52 +0000 Subject: [PATCH 1/8] add kwargs --- src/check_result.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/check_result.jl b/src/check_result.jl index 6be1af04..4e58fd60 100644 --- a/src/check_result.jl +++ b/src/check_result.jl @@ -74,7 +74,7 @@ function check_equal(actual::Composite{P}, expected::Composite{P}; kwargs...) wh end function check_equal( - ::Composite{ActualPrimal}, expected::Composite{ExpectedPrimal} + ::Composite{ActualPrimal}, expected::Composite{ExpectedPrimal}; kwargs... ) where {ActualPrimal, ExpectedPrimal} # this will certainly fail as we have another dispatch for that, but this will give as # good error message @@ -99,10 +99,10 @@ end check_equal(x, y::Composite; kwargs...) = check_equal(y, x; kwargs...) # This catches comparisons of Composites and Tuples/NamedTuple -# and gives a error messaage complaining about that +# and gives an error message complaining about that const LegacyZygoteCompTypes = Union{Tuple,NamedTuple} -check_equal(::C, expected::T) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test C === T -check_equal(::T, expected::C) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test T === C +check_equal(::C, ::T; kwargs...) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test C === T +check_equal(::T, ::C; kwargs...) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test T === C # Generic fallback, probably a tuple or something function check_equal(actual::A, expected::E; kwargs...) where {A, E} From 2f6075537beafe250734fbfbcea6507545772fe3 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Thu, 17 Dec 2020 17:31:48 +0000 Subject: [PATCH 2/8] add to_composite --- src/testers.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/testers.jl b/src/testers.jl index 99a7273c..0d8e4ea3 100644 --- a/src/testers.jl +++ b/src/testers.jl @@ -97,9 +97,14 @@ function _make_jvp_call(fdm, f, xs, ẋs, ignores) ignores = collect(ignores) all(ignores) && return ntuple(_->nothing, length(xs)) sigargs = zip(xs[.!ignores], ẋs[.!ignores]) - return jvp(fdm, f2, sigargs...) + return to_composite(jvp(fdm, f2, sigargs...)) end +# remove after https://github.com/JuliaDiff/FiniteDifferences.jl/issues/97 +to_composite(x::Tuple) = Composite{typeof(x)}(x...) +to_composite(x::NamedTuple) = Composite{typeof(x)}(;x...) +to_composite(x) = x + """ test_scalar(f, z; rtol=1e-9, atol=1e-9, fdm=central_fdm(5, 1), fkwargs=NamedTuple(), kwargs...) From b84d271f98f31f7212c69d7712872ba9e4b71895 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Thu, 17 Dec 2020 18:15:52 +0000 Subject: [PATCH 3/8] add test --- test/testers.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/testers.jl b/test/testers.jl index f0e50fa0..1011f8da 100644 --- a/test/testers.jl +++ b/test/testers.jl @@ -169,6 +169,17 @@ end end end + @testset "function with tuple output" begin + # key is that backing type of Composite =/= natural differential + tuple_out(x) = return (x, 1.0) # i.e. (x, 1.0) and not (x, x) + function ChainRulesCore.frule((_, dx), ::typeof(tuple_out), x) + Ω = tuple_out(x) + ∂Ω = Composite{typeof(Ω)}(dx, Zero()) + return Ω, ∂Ω + end + frule_test(tuple_out, (2.0, 1)) + end + @testset "ignoring arguments" begin fsymtest(x, s::Symbol) = x ChainRulesCore.frule((_, Δx, _), ::typeof(fsymtest), x, s) = (x, Δx) From de1a3e78b46647397db4d4bb4f6318ddfcb64ced Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Thu, 17 Dec 2020 18:29:10 +0000 Subject: [PATCH 4/8] rename testset --- test/testers.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/testers.jl b/test/testers.jl index 1011f8da..640b7ba3 100644 --- a/test/testers.jl +++ b/test/testers.jl @@ -169,8 +169,7 @@ end end end - @testset "function with tuple output" begin - # key is that backing type of Composite =/= natural differential + @testset "tuple output (backing type of Composite =/= natural differential)" begin tuple_out(x) = return (x, 1.0) # i.e. (x, 1.0) and not (x, x) function ChainRulesCore.frule((_, dx), ::typeof(tuple_out), x) Ω = tuple_out(x) From 4ad1e967a036ecc91547d47a885a95d518c5e644 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Thu, 17 Dec 2020 18:44:21 +0000 Subject: [PATCH 5/8] code review --- src/testers.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/testers.jl b/src/testers.jl index 0d8e4ea3..fbbf518c 100644 --- a/src/testers.jl +++ b/src/testers.jl @@ -97,13 +97,15 @@ function _make_jvp_call(fdm, f, xs, ẋs, ignores) ignores = collect(ignores) all(ignores) && return ntuple(_->nothing, length(xs)) sigargs = zip(xs[.!ignores], ẋs[.!ignores]) - return to_composite(jvp(fdm, f2, sigargs...)) + return _maybe_fix_to_composite(jvp(fdm, f2, sigargs...)) end -# remove after https://github.com/JuliaDiff/FiniteDifferences.jl/issues/97 -to_composite(x::Tuple) = Composite{typeof(x)}(x...) -to_composite(x::NamedTuple) = Composite{typeof(x)}(;x...) -to_composite(x) = x +# TODO: remove after https://github.com/JuliaDiff/FiniteDifferences.jl/issues/97 +# For functions which return a tuple, FD returns a tuple to represent the differential. Tuple +# is not a natural differential, because it doesn't overload +, so make it a Composite. +_maybe_fix_to_composite(x::Tuple) = Composite{typeof(x)}(x...) +_maybe_fix_to_composite(x::NamedTuple) = Composite{typeof(x)}(;x...) +_maybe_fix_to_composite(x) = x """ test_scalar(f, z; rtol=1e-9, atol=1e-9, fdm=central_fdm(5, 1), fkwargs=NamedTuple(), kwargs...) From ef9f529037c9ffdd67d8d3bc4b0ffc53af3556c1 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Thu, 17 Dec 2020 19:02:39 +0000 Subject: [PATCH 6/8] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3f04c82b..24328640 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ChainRulesTestUtils" uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a" -version = "0.5.8" +version = "0.5.9" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" From bc8d27940273b96616b1179b3dcfa1291a8abc70 Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Thu, 17 Dec 2020 12:32:44 -0800 Subject: [PATCH 7/8] Add GitHub Actions CI workflows (#86) * Add GitHub Actions CI workflows * Add CI badge * Remove JuliaNightly workflow * Remove Travis * Add documenter workflow * Add documenter key * Move to correct directory --- .github/workflows/CI.yml | 48 ++++++++++++++++++++++++++++++++ .github/workflows/Documenter.yml | 20 +++++++++++++ .travis.yml | 32 --------------------- README.md | 1 + 4 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/Documenter.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..e5ca44aa --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,48 @@ +name: CI +on: + push: + branches: [master] + tags: [v*] + pull_request: + schedule: + - cron: "0 0 * * *" # run on default branch every night at midnight UTC + +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.0' + - '1' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x86 + - x64 + # 32-bit Julia binaries are not available on macOS + exclude: + - os: macOS-latest + arch: x86 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml new file mode 100644 index 00000000..ba4e2e27 --- /dev/null +++ b/.github/workflows/Documenter.yml @@ -0,0 +1,20 @@ +name: Documenter +on: + push: + branches: [master] + tags: [v*] + pull_request: + +jobs: + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: '1' + - uses: julia-actions/julia-docdeploy@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b117dd23..00000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -language: julia -os: - - linux - - osx -julia: - - 1.0 - - 1.3 - - 1.4 - - nightly -jobs: - allow_failures: - - julia: nightly - - julia: 1.4 - include: - - stage: "Documentation" - julia: 1 - os: linux - script: - - julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' - - julia --project=docs/ docs/make.jl - after_success: skip - -notifications: - email: - recipients: - - nightly-rse@invenia.ca - on_success: never - on_failure: always - if: type = cron -matrix: - allow_failures: - - julia: nightly diff --git a/README.md b/README.md index 99b41a27..446b1086 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # ChainRulesTestUtils.jl +[![CI](https://github.com/JuliaDiff/ChainRulesTestUtils.jl/workflows/CI/badge.svg?branch=master)](https://github.com/JuliaDiff/ChainRulesTestUtils.jl/actions?query=workflow%3ACI) [![Travis](https://travis-ci.org/JuliaDiff/ChainRulesTestUtils.jl.svg?branch=master)](https://travis-ci.org/JuliaDiff/ChainRulesTestUtils.jl) [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) From c7e6c22722ca73da6901a7e3e90c2315e623f4b0 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Fri, 18 Dec 2020 15:53:08 +0100 Subject: [PATCH 8/8] follow up change --- src/testers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testers.jl b/src/testers.jl index fbbf518c..10020f26 100644 --- a/src/testers.jl +++ b/src/testers.jl @@ -70,7 +70,7 @@ function _make_j′vp_call(fdm, f, ȳ, xs, ignores) @assert length(fd) == length(arginds) for (dx, ind) in zip(fd, arginds) - args[ind] = dx + args[ind] = _maybe_fix_to_composite(dx) end return (args...,) end