From f226441629cae771b1f48ea800bcfcaf0ba510d7 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 19 Jan 2024 11:33:43 +0530 Subject: [PATCH 01/10] build: add SciMLSensitivity tests to downstream CI --- .github/workflows/Downstream.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 519640b6..7b4d8415 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -25,6 +25,11 @@ jobs: - {user: SciML, repo: OrdinaryDiffEq.jl, group: Core} - {user: SciML, repo: OrdinaryDiffEq.jl, group: Interface} - {user: SciML, repo: DelayDiffEq.jl, group: Interface} + - {user: SciML, repo: SciMLSensitivity.jl, group: Core1} + - {user: SciML, repo: SciMLSensitivity.jl, group: Core2} + - {user: SciML, repo: SciMLSensitivity.jl, group: Core3} + - {user: SciML, repo: SciMLSensitivity.jl, group: Core4} + - {user: SciML, repo: SciMLSensitivity.jl, group: Core5} steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 From cc55ee68c85e8c370da93ed5a87d1f7d1cacb385 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 19 Jan 2024 18:19:22 +0530 Subject: [PATCH 02/10] fix: fix `Array(::AbstractVectorOfArray)` adjoint --- ext/RecursiveArrayToolsZygoteExt.jl | 2 +- src/utils.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/RecursiveArrayToolsZygoteExt.jl b/ext/RecursiveArrayToolsZygoteExt.jl index c4611137..2c15b6e8 100644 --- a/ext/RecursiveArrayToolsZygoteExt.jl +++ b/ext/RecursiveArrayToolsZygoteExt.jl @@ -110,7 +110,7 @@ end @adjoint function Base.Array(VA::AbstractVectorOfArray) adj = let VA=VA function Array_adjoint(y) - VA = copy(VA) + VA = recursivecopy(VA) copyto!(VA, y) return (VA,) end diff --git a/src/utils.jl b/src/utils.jl index 658e8418..4af362c9 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -28,7 +28,7 @@ end function recursivecopy(a::AbstractVectorOfArray) b = copy(a) - b.u = recursivecopy.(a.u) + b.u .= recursivecopy.(a.u) return b end From 680e756812252394585c241cad778b7a11211d01 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 22 Jan 2024 11:00:16 +0530 Subject: [PATCH 03/10] fix: view adjoints --- ext/RecursiveArrayToolsZygoteExt.jl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ext/RecursiveArrayToolsZygoteExt.jl b/ext/RecursiveArrayToolsZygoteExt.jl index 2c15b6e8..0b75593f 100644 --- a/ext/RecursiveArrayToolsZygoteExt.jl +++ b/ext/RecursiveArrayToolsZygoteExt.jl @@ -118,15 +118,21 @@ end Array(VA), adj end +@adjoint function Base.view(A::AbstractVectorOfArray, I::Colon...) + function adjoint(y) + (recursivecopy(parent(y)), map(_ -> nothing, I)...) + end + return view(A, I...), adjoint +end + @adjoint function Base.view(A::AbstractVectorOfArray, I...) - adj = let A = A, I = I - function view_adjoint(y) - A = zero(A) - view(A, I...) .= y - return (A, map(_ -> nothing, I)...) - end + function view_adjoint(y) + A = recursivecopy(parent(y)) + recursivefill!(A, zero(eltype(A))) + A[I...] .= y + return (A, map(_ -> nothing, I)...) end - view(A, I...), adj + view(A, I...), view_adjoint end ChainRulesCore.ProjectTo(a::AbstractVectorOfArray) = ChainRulesCore.ProjectTo{VectorOfArray}((sz = size(a))) From 4e27909c0ffc57768df98f58d5bcc4d85f000ff2 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 22 Jan 2024 03:02:08 -0500 Subject: [PATCH 04/10] Update .github/workflows/Downstream.yml --- .github/workflows/Downstream.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 7b4d8415..0ba79820 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -30,6 +30,7 @@ jobs: - {user: SciML, repo: SciMLSensitivity.jl, group: Core3} - {user: SciML, repo: SciMLSensitivity.jl, group: Core4} - {user: SciML, repo: SciMLSensitivity.jl, group: Core5} + - {user: SciML, repo: SciMLSensitivity.jl, group: Core6} steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 From 13b2a674c07dc1bf0761b877eedd674a71bd60f4 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 22 Jan 2024 14:32:22 +0530 Subject: [PATCH 05/10] fix: fix copyto! for StaticArrays --- src/vector_of_array.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index d348cac4..b4f6f2e7 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -585,16 +585,26 @@ end function Base.checkbounds(VA::AbstractVectorOfArray, idx...) checkbounds(Bool, VA, idx...) || throw(BoundsError(VA, idx)) end -function Base.copyto!(dest::AbstractVectorOfArray{T,N}, src::AbstractVectorOfArray{T,N}) where {T,N} - copyto!.(dest.u, src.u) +function Base.copyto!(dest::AbstractVectorOfArray{T,N}, src::AbstractVectorOfArray{T2,N}) where {T, T2, N} + for (i, j) in zip(eachindex(dest.u), eachindex(src.u)) + if ArrayInterface.ismutable(dest.u[i]) || dest.u[i] isa AbstractVectorOfArray + copyto!(dest.u[i], src.u[j]) + else + dest.u[i] = StaticArraysCore.similar_type(dest.u[i])(src.u[j]) + end + end end -function Base.copyto!(dest::AbstractVectorOfArray{T, N}, src::AbstractArray{T, N}) where {T, N} - for (i, slice) in enumerate(eachslice(src, dims = ndims(src))) - copyto!(dest.u[i], slice) +function Base.copyto!(dest::AbstractVectorOfArray{T, N}, src::AbstractArray{T2, N}) where {T, T2, N} + for (i, slice) in zip(eachindex(dest.u), eachslice(src, dims = ndims(src))) + if ArrayInterface.ismutable(dest.u[i]) || dest.u[i] isa AbstractVectorOfArray + copyto!(dest.u[i], slice) + else + dest.u[i] = StaticArraysCore.similar_type(dest.u[i])(slice) + end end dest end -function Base.copyto!(dest::AbstractVectorOfArray{T, N, <:AbstractVector{T}}, src::AbstractVector{T}) where {T, N} +function Base.copyto!(dest::AbstractVectorOfArray{T, N, <:AbstractVector{T}}, src::AbstractVector{T2}) where {T, T2, N} copyto!(dest.u, src) dest end From 8bd263dfb259610705d1b011f4756ff9c6480722 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:14:19 +0000 Subject: [PATCH 06/10] build(deps): bump crate-ci/typos from 1.17.1 to 1.17.2 Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.17.1 to 1.17.2. - [Release notes](https://github.com/crate-ci/typos/releases) - [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md) - [Commits](https://github.com/crate-ci/typos/compare/v1.17.1...v1.17.2) --- updated-dependencies: - dependency-name: crate-ci/typos dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/SpellCheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/SpellCheck.yml b/.github/workflows/SpellCheck.yml index c2bff255..473706be 100644 --- a/.github/workflows/SpellCheck.yml +++ b/.github/workflows/SpellCheck.yml @@ -10,4 +10,4 @@ jobs: - name: Checkout Actions Repository uses: actions/checkout@v4 - name: Check spelling - uses: crate-ci/typos@v1.17.1 \ No newline at end of file + uses: crate-ci/typos@v1.17.2 \ No newline at end of file From 0e1c9c50be353f8d4aa9e6147c981bb98dd6465d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:14:22 +0000 Subject: [PATCH 07/10] build(deps): bump actions/cache from 3 to 4 Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 15f8ddb8..2903b709 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -25,7 +25,7 @@ jobs: - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} - - uses: actions/cache@v3 + - uses: actions/cache@v4 env: cache-name: cache-artifacts with: From 55e740f15628fcae017bc30e4e902d61e303ea0f Mon Sep 17 00:00:00 2001 From: Arno Strouwen Date: Mon, 22 Jan 2024 13:18:34 +0100 Subject: [PATCH 08/10] [skip ci] configure dependabot to skip typos patches --- .github/dependabot.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 700707ce..1e8a051e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,6 @@ updates: directory: "/" # Location of package manifests schedule: interval: "weekly" + ignore: + - dependency-name: "crate-ci/typos" + update-types: ["version-update:semver-patch"] From 4d6845f0a05d2b4cbf74adff79d75d45cc974ba7 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 22 Jan 2024 14:33:40 +0530 Subject: [PATCH 09/10] fix: add RecursiveArrayToolsReverseDiffExt --- Project.toml | 3 +++ ext/RecursiveArrayToolsReverseDiffExt.jl | 25 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ext/RecursiveArrayToolsReverseDiffExt.jl diff --git a/Project.toml b/Project.toml index 6a33022e..62d8ed85 100644 --- a/Project.toml +++ b/Project.toml @@ -23,11 +23,13 @@ Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" MonteCarloMeasurements = "0987c9cc-fe09-11e8-30f0-b96dd679fdca" Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" +ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" [extensions] RecursiveArrayToolsFastBroadcastExt = "FastBroadcast" RecursiveArrayToolsMeasurementsExt = "Measurements" RecursiveArrayToolsMonteCarloMeasurementsExt = "MonteCarloMeasurements" +RecursiveArrayToolsReverseDiffExt = ["ReverseDiff", "Zygote"] RecursiveArrayToolsTrackerExt = "Tracker" RecursiveArrayToolsZygoteExt = "Zygote" @@ -49,6 +51,7 @@ OrdinaryDiffEq = "6.62" Pkg = "1" Random = "1" RecipesBase = "1.1" +ReverseDiff = "1.15" SafeTestsets = "0.1" SparseArrays = "1.10" StaticArrays = "1.6" diff --git a/ext/RecursiveArrayToolsReverseDiffExt.jl b/ext/RecursiveArrayToolsReverseDiffExt.jl new file mode 100644 index 00000000..115949a1 --- /dev/null +++ b/ext/RecursiveArrayToolsReverseDiffExt.jl @@ -0,0 +1,25 @@ +module RecursiveArrayToolsReverseDiffExt + +using RecursiveArrayTools +using ReverseDiff +using Zygote: @adjoint + +function trackedarraycopyto!(dest, src) + for (i, slice) in zip(eachindex(dest.u), eachslice(src, dims=ndims(src))) + if dest.u[i] isa AbstractArray + dest.u[i] = reshape(reduce(vcat, slice), size(dest.u[i])) + else + trackedarraycopyto!(dest.u[i], slice) + end + end +end + +@adjoint function Array(VA::AbstractVectorOfArray{<:ReverseDiff.TrackedReal}) + function Array_adjoint(y) + VA = recursivecopy(VA) + trackedarraycopyto!(VA, y) + return (VA,) + end + return Array(VA), Array_adjoint +end +end # module From b678985136e7c06d11b9b6d2a60002ee07705fc8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 24 Jan 2024 05:41:55 -0500 Subject: [PATCH 10/10] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 62d8ed85..8a9a2924 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RecursiveArrayTools" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" authors = ["Chris Rackauckas "] -version = "3.6.0" +version = "3.6.1" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"