Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove randomness in scenario creation #623

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DifferentiationInterfaceTest/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DifferentiationInterfaceTest"
uuid = "a82114a7-5aa3-49a8-9643-716bb13727a3"
authors = ["Guillaume Dalle", "Adrian Hill"]
version = "0.8.5"
version = "0.9.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using DifferentiationInterfaceTest
import DifferentiationInterfaceTest as DIT
using LinearAlgebra: dot
using Random: AbstractRNG, default_rng

## Vector to scalar

Expand Down Expand Up @@ -49,11 +48,11 @@

## Gather

function DIT.component_scenarios(rng::AbstractRNG=default_rng())
dy_ = rand(rng)
function DIT.component_scenarios()
dy_ = -1 / 12

Check warning on line 52 in DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestComponentArraysExt/DifferentiationInterfaceTestComponentArraysExt.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestComponentArraysExt/DifferentiationInterfaceTestComponentArraysExt.jl#L51-L52

Added lines #L51 - L52 were not covered by tests

x_comp = ComponentVector(; a=randn(rng, 4), b=randn(rng, 2))
dx_comp = ComponentVector(; a=randn(rng, 4), b=randn(rng, 2))
x_comp = ComponentVector(; a=float.(1:4), b=float.(5:6))
dx_comp = ComponentVector(; a=float.(4:-1:1), b=float.(6:-1:5))

Check warning on line 55 in DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestComponentArraysExt/DifferentiationInterfaceTestComponentArraysExt.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestComponentArraysExt/DifferentiationInterfaceTestComponentArraysExt.jl#L54-L55

Added lines #L54 - L55 were not covered by tests

scens = vcat(
# one argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DifferentiationInterface as DI
using DifferentiationInterfaceTest
import DifferentiationInterfaceTest as DIT
using JLArrays: JLArray, JLVector, JLMatrix, jl
using Random: AbstractRNG, default_rng

myjl(f::Function) = f
function myjl(::DIT.NumToArr{A}) where {T,N,A<:AbstractArray{T,N}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module DifferentiationInterfaceTestStaticArraysExt
import DifferentiationInterface as DI
using DifferentiationInterfaceTest
import DifferentiationInterfaceTest as DIT
using Random: AbstractRNG, default_rng
using SparseArrays: SparseArrays, SparseMatrixCSC, nnz, spdiagm
using StaticArrays: MArray, MMatrix, MVector, SArray, SMatrix, SVector

Expand Down
16 changes: 8 additions & 8 deletions DifferentiationInterfaceTest/src/scenarios/allocfree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ function copyto!_scenarios(x::AbstractArray; dx::AbstractArray, dy::AbstractArra
end

"""
allocfree_scenarios(rng::AbstractRNG=default_rng())
allocfree_scenarios()

Create a vector of [`Scenario`](@ref)s with functions that do not allocate.

!!! warning
At the moment, second-order scenarios are excluded.
"""
function allocfree_scenarios(rng::AbstractRNG=default_rng())
x_ = rand(rng)
dx_ = rand(rng)
dy_ = rand(rng)
function allocfree_scenarios()
x_ = 0.42
dx_ = 3.14
dy_ = -1 / 12

x_6 = rand(rng, 6)
dx_6 = rand(rng, 6)
dy_6 = rand(rng, 6)
x_6 = float.(1:6)
dx_6 = float.(-1:-1:-6)
dy_6 = float.(-5:2:5)

scens = vcat(
identity_scenarios(x_; dx=dx_, dy=dy_), #
Expand Down
27 changes: 13 additions & 14 deletions DifferentiationInterfaceTest/src/scenarios/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,33 +448,32 @@ end
## Gather

"""
default_scenarios(rng=Random.default_rng())
default_scenarios()

Create a vector of [`Scenario`](@ref)s with standard array types.
"""
function default_scenarios(
rng::AbstractRNG=default_rng();
function default_scenarios(;
linalg=true,
include_normal=true,
include_batchified=true,
include_closurified=false,
include_constantified=false,
include_cachified=false,
)
x_ = rand(rng)
dx_ = rand(rng)
dy_ = rand(rng)
x_ = 0.42
dx_ = 3.14
dy_ = -1 / 12

x_6 = rand(rng, 6)
dx_6 = rand(rng, 6)
x_6 = float.(1:6)
dx_6 = float.(-1:-1:-6)

x_2_3 = rand(rng, 2, 3)
dx_2_3 = rand(rng, 2, 3)
x_2_3 = float.(reshape(1:6, 2, 3))
dx_2_3 = float.(reshape(-1:-1:-6, 2, 3))

dy_6 = rand(rng, 6)
dy_12 = rand(rng, 12)
dy_2_3 = rand(rng, 2, 3)
dy_6_2 = rand(rng, 6, 2)
dy_6 = float.(-5:2:5)
dy_12 = float.(-11:2:11)
dy_2_3 = float.(reshape(-5:2:5, 2, 3))
dy_6_2 = float.(reshape(-11:2:11, 6, 2))

V = Vector{Float64}
M = Matrix{Float64}
Expand Down
6 changes: 3 additions & 3 deletions DifferentiationInterfaceTest/src/scenarios/extensions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
static_scenarios(rng=Random.default_rng())
static_scenarios()

Create a vector of [`Scenario`](@ref)s with static array types from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl).

Expand All @@ -9,7 +9,7 @@ Create a vector of [`Scenario`](@ref)s with static array types from [StaticArray
function static_scenarios end

"""
component_scenarios(rng=Random.default_rng())
component_scenarios()

Create a vector of [`Scenario`](@ref)s with component array types from [ComponentArrays.jl](https://github.com/jonniedie/ComponentArrays.jl).

Expand All @@ -19,7 +19,7 @@ Create a vector of [`Scenario`](@ref)s with component array types from [Componen
function component_scenarios end

"""
gpu_scenarios(rng=Random.default_rng())
gpu_scenarios()

Create a vector of [`Scenario`](@ref)s with GPU array types from [JLArrays.jl](https://github.com/JuliaGPU/GPUArrays.jl/tree/master/lib/JLArrays).

Expand Down
26 changes: 14 additions & 12 deletions DifferentiationInterfaceTest/src/scenarios/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,26 @@ end
## Gather

"""
sparse_scenarios(rng=Random.default_rng())
sparse_scenarios()

Create a vector of [`Scenario`](@ref)s with sparse array types, focused on sparse Jacobians and Hessians.
"""
function sparse_scenarios(
rng::AbstractRNG=default_rng(); band_sizes=[5, 10, 20], include_constantified=false
)
function sparse_scenarios(; band_sizes=[5, 10, 20], include_constantified=false)
x_6 = float.(1:6)
x_2_3 = float.(reshape(1:6, 2, 3))
x_50 = float.(1:50)

scens = vcat(
sparse_vec_to_vec_scenarios(rand(rng, 6)),
sparse_vec_to_mat_scenarios(rand(rng, 6)),
sparse_mat_to_vec_scenarios(rand(rng, 2, 3)),
sparse_mat_to_mat_scenarios(rand(rng, 2, 3)),
sparse_vec_to_num_scenarios(rand(rng, 6)),
sparse_mat_to_num_scenarios(rand(rng, 2, 3)),
sparse_vec_to_vec_scenarios(x_6),
sparse_vec_to_mat_scenarios(x_6),
sparse_mat_to_vec_scenarios(x_2_3),
sparse_mat_to_mat_scenarios(x_2_3),
sparse_vec_to_num_scenarios(x_6),
sparse_mat_to_num_scenarios(x_2_3),
)
if !isempty(band_sizes)
append!(scens, squarelinearmap_scenarios(rand(rng, 50), band_sizes))
append!(scens, squarequadraticform_scenarios(rand(rng, 50), band_sizes))
append!(scens, squarelinearmap_scenarios(x_50, band_sizes))
append!(scens, squarequadraticform_scenarios(x_50, band_sizes))
end
include_constantified && append!(scens, constantify(scens))
return scens
Expand Down
4 changes: 1 addition & 3 deletions DifferentiationInterfaceTest/test/standard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ LOGGING = get(ENV, "CI", "false") == "false"
## Dense

test_differentiation(
AutoForwardDiff(),
default_scenarios(Random.default_rng(); include_constantified=true);
logging=LOGGING,
AutoForwardDiff(), default_scenarios(; include_constantified=true); logging=LOGGING
)

## Sparse
Expand Down
Loading