Skip to content

Commit

Permalink
Fix typo in testing of infeasible parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lassepe committed Jan 8, 2024
1 parent 00807b2 commit a86acd3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using FiniteDiff: FiniteDiff
lower_bounds = [-Inf, -Inf, 0, 0]
upper_bounds = [Inf, Inf, Inf, Inf]
problem = ParametricMCPs.ParametricMCP(f, lower_bounds, upper_bounds, parameter_dimension)
problem_no_jacobian = ParametricMCPs.ParametricMCP(f, lower_bounds, upper_bounds, parameter_dimension; compute_sensitivities = false)
problem_no_jacobian = ParametricMCPs.ParametricMCP(f, lower_bounds, upper_bounds, parameter_dimension; compute_sensitivities=false)

feasible_parameters = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [rand(rng, 2) for _ in 1:10]...]
infeasible_parameters = -feasible_parameters
Expand All @@ -26,7 +26,7 @@ using FiniteDiff: FiniteDiff
@test solution.z[1:2] θ
end

for θ in feasible_parameters
for θ in infeasible_parameters
solution = ParametricMCPs.solve(problem, θ)
@test norm(solution.z[1:2] - θ) <= norm(θ)
end
Expand All @@ -42,17 +42,17 @@ using FiniteDiff: FiniteDiff
∇_autodiff_reverse = only(Zygote.gradient(dummy_pipeline, θ))
∇_autodiff_forward = only(Zygote.gradient-> Zygote.forwarddiff(dummy_pipeline, θ), θ))
∇_finitediff = FiniteDiff.finite_difference_gradient(dummy_pipeline, θ)
@test isapprox(∇_autodiff_reverse, ∇_finitediff; atol = 1e-4)
@test isapprox(∇_autodiff_reverse, ∇_autodiff_forward; atol = 1e-4)
@test isapprox(∇_autodiff_reverse, ∇_finitediff; atol=1e-4)
@test isapprox(∇_autodiff_reverse, ∇_autodiff_forward; atol=1e-4)
end
end
end

@testset "missing jacobian" begin
function dummy_pipeline(θ, problem)
solution = ParametricMCPs.solve(problem, θ)
sum(solution.z .^ 2)
end

@test_throws ArgumentError Zygote.gradient-> dummy_pipeline(θ, problem_no_jacobian), feasible_parameters[1])
end
end
end

0 comments on commit a86acd3

Please sign in to comment.