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

ReverseAD doesn't error for out-of-bound writes #2440

Closed
Tracked by #2439
odow opened this issue Feb 21, 2024 · 0 comments · Fixed by #2441
Closed
Tracked by #2439

ReverseAD doesn't error for out-of-bound writes #2440

odow opened this issue Feb 21, 2024 · 0 comments · Fixed by #2441
Labels
Submodule: Nonlinear About the Nonlinear submodule Type: Bug

Comments

@odow
Copy link
Member

odow commented Feb 21, 2024

Test added by #2438 did not allocate enough space for Hessian, but no error was thrown.

Caused GC fault in #2439

See

# TODO(odow): consider reverting to a view.
output_slice = _UnsafeVectorView(nzcount, length(ex.hess_I), pointer(H))
Coloring.recover_from_matmat!(
output_slice,
ex.seed_matrix,
ex.rinfo,
d.output_ϵ,
)

Test needs to be

function test_timers()
    x = MOI.VariableIndex(1)
    model = Nonlinear.Model()
    Nonlinear.set_objective(model, :(log($x)))
    Nonlinear.add_constraint(model, :(sin($x)), MOI.LessThan(0.5))
    evaluator = Nonlinear.Evaluator(model, Nonlinear.SparseReverseMode(), [x])
    y = [1.2]
    g = [NaN]
    MOI.initialize(evaluator, [:Grad, :Jac, :Hess])
    MOI.eval_objective(evaluator, y)
    MOI.eval_constraint(evaluator, g, y)
    MOI.eval_objective_gradient(evaluator, g, y)
    MOI.eval_constraint_gradient(evaluator, g, y, 1)
    J = zeros(length(MOI.jacobian_structure(evaluator)))
    MOI.eval_constraint_jacobian(evaluator, J, y)
    H = zeros(length(MOI.hessian_objective_structure(evaluator)))
    MOI.eval_hessian_objective(evaluator, H, y)
    H = zeros(length(MOI.hessian_constraint_structure(evaluator, 1)))
    MOI.eval_hessian_constraint(evaluator, H, y, 1)
    H = zeros(length(MOI.hessian_lagrangian_structure(evaluator)))
    MOI.eval_hessian_lagrangian(evaluator, H, y, 1.0, [1.0])
    timers = [
        evaluator.initialize_timer,
        evaluator.eval_objective_timer,
        evaluator.eval_constraint_timer,
        evaluator.eval_objective_gradient_timer,
        evaluator.eval_constraint_gradient_timer,
        evaluator.eval_constraint_jacobian_timer,
        evaluator.eval_hessian_objective_timer,
        evaluator.eval_hessian_constraint_timer,
        evaluator.eval_hessian_lagrangian_timer,
    ]
    @test all(>=(0.0), timers)
    if !Sys.iswindows()
        # Windows times only in milliseconds, which can be too coarse to
        # accurately measure and test.
        @test sum(timers) > 0.0
    end
    return
end
@odow odow added Type: Bug Submodule: Nonlinear About the Nonlinear submodule labels Feb 21, 2024
@odow odow changed the title ReverseAD does to error for out-of-bound writes ReverseAD doesn't error for out-of-bound writes Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Submodule: Nonlinear About the Nonlinear submodule Type: Bug
Development

Successfully merging a pull request may close this issue.

1 participant