Skip to content

[Bug] Unstable solve on GPU #531

@jbcaillau

Description

@jbcaillau

The following solve on GPU is not stable: successive runs with fixed max_iter may produce different iterates. no such issue on CPU.

NB. problem is probably not feasible. dynamics with x(0) == [1, 2, 3, 4]; (∂(x₁))(t) == x₁(t) ^ 2 + x₂(t) ^ 2 most likely leads to explosion.

julia> o = @def begin
                   t  [0, 1], time
                   x  R⁴, state
                   u  R², control

                   x(0) == [1, 2, 3, 4]

                   (x₁)(t) == x₁(t)^2 + x₂(t)^2
                   (x₂)(t) == u₁(t) * u₂(t)
                   (x₃)(t) == x₂(t) + x₃(t) + x₄(t)
                   (x₄)(t) == u₁(t)

                   (x₁(1) + x₂(1) + x₃(1))^2 + 0.5( u₁(t)^2 + u₂(t)^2 )  min
               end
Abstract definition:

    t  [0, 1], time
    x  R⁴, state
    u  R², control
    x(0) == [1, 2, 3, 4]
    ((x₁))(t) == x₁(t) ^ 2 + x₂(t) ^ 2
    ((x₂))(t) == u₁(t) * u₂(t)
    ((x₃))(t) == x₂(t) + x₃(t) + x₄(t)
    ((x₄))(t) == u₁(t)
    (x₁(1) + x₂(1) + x₃(1)) ^ 2 + 0.5 * (u₁(t) ^ 2 + u₂(t) ^ 2)  min

The (autonomous) optimal control problem is of the form:

    minimize  J(x, u) = g(x(0), x(1)) +f⁰(x(t), u(t)) dt, over [0, 1]

    subject to

        (t) = f(x(t), u(t)), t in [0, 1] a.e.,

        ϕ₋  ϕ(x(0), x(1))  ϕ₊, 

    where x(t)  R⁴ and u(t)  R².


julia> sol = solve(o, :exa, :madnlp; max_iter=10, exa_backend=backend)
▫ This is OptimalControl version v1.1.6 running with: direct, exa, madnlp.

▫ The optimal control problem is solved with CTDirect version v0.17.4.

   ┌─ The NLP is modelled with ExaModels and solved with MadNLP suite.
   │
   ├─ Number of time steps: 250
   └─ Discretisation scheme: midpoint

▫ This is MadNLP version v0.8.12, running with cuDSS v0.7.1

Number of nonzeros in constraint Jacobian............:     4254
Number of nonzeros in Lagrangian Hessian.............:     5006

Total number of variables............................:     1506
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1004
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.0000000e-01 3.90e+00 6.00e-01 1.58e-07  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.0000355e-01 3.90e+00 8.28e-03 3.48e-06  -1.0 1.88e+02    -  1.00e+00 2.00e-07h  2
   2  9.7919791e+00 2.92e+00 8.88e-04 3.11e-06  -1.0 2.70e+01    -  1.00e+00 2.50e-01h  3
   3  5.3284602e+01 1.60e-01 5.17e-04 2.00e-06  -1.0 9.50e+00   0.0 1.00e+00 1.00e+00h  1
   4  1.0994023e+02 2.45e-02 6.47e-03 2.03e-06  -2.5 3.30e+00   0.4 1.00e+00 1.00e+00h  1
   5  1.7675944e+02 2.19e-02 6.29e-02 2.23e-06  -3.8 2.65e+00  -0.1 1.00e+00 1.00e+00h  1
   6  2.0476903e+02 1.04e-01 3.21e+01 2.41e-06  -3.8 1.89e+01  -0.5 1.00e+00 2.50e-01h  3
   7  2.5090064e+02 8.95e-02 9.29e+01 2.81e-06  -3.8 6.93e+00  -0.1 1.00e+00 2.50e-01h  3
   8  3.1185887e+02 1.00e-01 1.00e+02 2.93e-06  -3.8 1.16e+01  -0.6 1.00e+00 2.50e-01h  3
   9  4.0594684e+02 8.04e-02 2.50e+02 3.63e-06  -3.8 1.06e+01  -0.2 1.00e+00 2.38e-01h  3
iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  4.7149148e+02 7.24e-02 3.51e+02 4.29e-06  -3.8 1.38e+01  -0.6 1.00e+00 1.25e-01h  4

Number of Iterations....: 10

                                   (scaled)                 (unscaled)
Objective...............:   4.7149148065749313e+02    4.7149148065749313e+02
Dual infeasibility......:   3.5055929454207512e+02    3.5055929454207512e+02
Constraint violation....:   7.2358492745758812e-02    7.2358492745758812e-02
Complementarity.........:   4.2945788703848589e-06    4.2945788703848589e-06
Overall NLP error.......:   3.5055929454207512e+02    3.5055929454207512e+02

Number of objective function evaluations             = 31
Number of objective gradient evaluations             = 11
Number of constraint evaluations                     = 31
Number of constraint Jacobian evaluations            = 11
Number of Lagrangian Hessian evaluations             = 10
Total wall-clock secs in solver (w/o fun. eval./lin. alg.)  =  0.083
Total wall-clock secs in linear solver                      =  0.048
Total wall-clock secs in NLP function evaluations           =  0.012
Total wall-clock secs                                       =  0.143

EXIT: Maximum Number of Iterations Exceeded.
• Solver:
  ✓ Successful  : false
  │  Status     : MAXIMUM_ITERATIONS_EXCEEDED
  │  Message    : MadNLP
  │  Iterations : 10
  │  Objective  : 471.4914806574931
  └─ Constraints violation : 0.07235849274575881

• Boundary duals: [0.0, 0.0, 0.0, 0.0]


julia> sol = solve(o, :exa, :madnlp; max_iter=10, exa_backend=backend)
▫ This is OptimalControl version v1.1.6 running with: direct, exa, madnlp.

▫ The optimal control problem is solved with CTDirect version v0.17.4.

   ┌─ The NLP is modelled with ExaModels and solved with MadNLP suite.
   │
   ├─ Number of time steps: 250
   └─ Discretisation scheme: midpoint

▫ This is MadNLP version v0.8.12, running with cuDSS v0.7.1

Number of nonzeros in constraint Jacobian............:     4254
Number of nonzeros in Lagrangian Hessian.............:     5006

Total number of variables............................:     1506
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1004
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.0000000e-01 3.90e+00 6.00e-01 1.58e-07  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.0000355e-01 3.90e+00 8.28e-03 3.48e-06  -1.0 1.88e+02    -  1.00e+00 2.00e-07h  2
   2  9.7919769e+00 2.92e+00 8.88e-04 3.11e-06  -1.0 2.70e+01    -  1.00e+00 2.50e-01h  3
   3  5.3284532e+01 1.60e-01 5.17e-04 2.00e-06  -1.0 9.50e+00   0.0 1.00e+00 1.00e+00h  1
   4  1.0994010e+02 2.45e-02 6.47e-03 2.03e-06  -2.5 3.30e+00   0.4 1.00e+00 1.00e+00h  1
   5  1.7675926e+02 2.19e-02 6.29e-02 2.23e-06  -3.8 2.65e+00  -0.1 1.00e+00 1.00e+00h  1
   6  2.0476884e+02 1.04e-01 3.21e+01 2.41e-06  -3.8 1.89e+01  -0.5 1.00e+00 2.50e-01h  3
   7  2.5090041e+02 8.95e-02 9.29e+01 2.81e-06  -3.8 6.93e+00  -0.1 1.00e+00 2.50e-01h  3
   8  3.1185857e+02 1.00e-01 1.00e+02 2.93e-06  -3.8 1.16e+01  -0.6 1.00e+00 2.50e-01h  3
   9  4.0594652e+02 8.04e-02 2.50e+02 3.63e-06  -3.8 1.06e+01  -0.2 1.00e+00 2.38e-01h  3
iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  4.7149111e+02 7.24e-02 3.51e+02 4.29e-06  -3.8 1.38e+01  -0.6 1.00e+00 1.25e-01h  4

Number of Iterations....: 10

                                   (scaled)                 (unscaled)
Objective...............:   4.7149110750267818e+02    4.7149110750267818e+02
Dual infeasibility......:   3.5055899993134869e+02    3.5055899993134869e+02
Constraint violation....:   7.2358454841026612e-02    7.2358454841026612e-02
Complementarity.........:   4.2945774528465284e-06    4.2945774528465284e-06
Overall NLP error.......:   3.5055899993134869e+02    3.5055899993134869e+02

Number of objective function evaluations             = 31
Number of objective gradient evaluations             = 11
Number of constraint evaluations                     = 31
Number of constraint Jacobian evaluations            = 11
Number of Lagrangian Hessian evaluations             = 10
Total wall-clock secs in solver (w/o fun. eval./lin. alg.)  =  0.209
Total wall-clock secs in linear solver                      =  0.044
Total wall-clock secs in NLP function evaluations           =  0.012
Total wall-clock secs                                       =  0.264

EXIT: Maximum Number of Iterations Exceeded.
• Solver:
  ✓ Successful  : false
  │  Status     : MAXIMUM_ITERATIONS_EXCEEDED
  │  Message    : MadNLP
  │  Iterations : 10
  │  Objective  : 471.4911075026782
  └─ Constraints violation : 0.07235845484102661

• Boundary duals: [0.0, 0.0, 0.0, 0.0]


julia> sol = solve(o, :exa, :madnlp; max_iter=10, exa_backend=backend)
▫ This is OptimalControl version v1.1.6 running with: direct, exa, madnlp.

▫ The optimal control problem is solved with CTDirect version v0.17.4.

   ┌─ The NLP is modelled with ExaModels and solved with MadNLP suite.
   │
   ├─ Number of time steps: 250
   └─ Discretisation scheme: midpoint

▫ This is MadNLP version v0.8.12, running with cuDSS v0.7.1

Number of nonzeros in constraint Jacobian............:     4254
Number of nonzeros in Lagrangian Hessian.............:     5006

Total number of variables............................:     1506
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1004
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.0000000e-01 3.90e+00 6.00e-01 1.58e-07  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.0000355e-01 3.90e+00 8.28e-03 3.48e-06  -1.0 1.88e+02    -  1.00e+00 2.00e-07h  2
   2  9.8103812e+00 2.92e+00 9.08e-04 3.11e-06  -1.0 2.68e+01  -4.0 1.00e+00 2.50e-01h  3
   3  2.2668124e+01 1.46e+00 3.75e-03 2.56e-06  -1.0 1.02e+01  -0.9 1.00e+00 5.00e-01h  2
   4  1.2942906e+02 1.09e-01 7.33e-05 2.00e-06  -1.0 5.85e+00  -0.4 1.00e+00 1.00e+00h  1
   5  1.5004709e+02 1.84e-01 3.39e-04 2.01e-06  -2.5 6.99e+00  -0.9 1.00e+00 1.00e+00h  1
   6  1.9524911e+02 9.50e-02 6.84e-01 2.01e-06  -2.5 2.65e+00  -0.5 1.00e+00 5.00e-01h  2
   7  2.0983066e+02 8.62e-02 2.59e+00 2.02e-06  -2.5 7.51e+00  -1.0 1.00e+00 1.25e-01h  4
   8  2.5814608e+02 6.90e-02 4.01e+00 2.03e-06  -2.5 6.95e+00  -0.5 1.00e+00 2.50e-01h  3
   9  2.9647696e+02 6.08e-02 1.28e+01 2.09e-06  -2.5 9.31e+00  -0.1 1.00e+00 1.25e-01h  4
iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  3.3940577e+02 5.46e-02 1.19e+01 2.09e-06  -2.5 1.06e+01  -0.6 1.00e+00 1.25e-01h  4

Number of Iterations....: 10

                                   (scaled)                 (unscaled)
Objective...............:   3.3940577196717010e+02    3.3940577196717010e+02
Dual infeasibility......:   1.1944768937354576e+01    1.1944768937354576e+01
Constraint violation....:   5.4637889678052810e-02    5.4637889678052810e-02
Complementarity.........:   2.0883827423881080e-06    2.0883827423881080e-06
Overall NLP error.......:   1.1944768937354576e+01    1.1944768937354576e+01

Number of objective function evaluations             = 34
Number of objective gradient evaluations             = 11
Number of constraint evaluations                     = 34
Number of constraint Jacobian evaluations            = 11
Number of Lagrangian Hessian evaluations             = 10
Total wall-clock secs in solver (w/o fun. eval./lin. alg.)  =  0.094
Total wall-clock secs in linear solver                      =  0.064
Total wall-clock secs in NLP function evaluations           =  0.014
Total wall-clock secs                                       =  0.172

EXIT: Maximum Number of Iterations Exceeded.
• Solver:
  ✓ Successful  : false
  │  Status     : MAXIMUM_ITERATIONS_EXCEEDED
  │  Message    : MadNLP
  │  Iterations : 10
  │  Objective  : 339.4057719671701
  └─ Constraints violation : 0.05463788967805281

• Boundary duals: [0.0, 0.0, 0.0, 0.0]


julia> sol = solve(o, :exa, :madnlp; max_iter=10, exa_backend=backend)
▫ This is OptimalControl version v1.1.6 running with: direct, exa, madnlp.

▫ The optimal control problem is solved with CTDirect version v0.17.4.

   ┌─ The NLP is modelled with ExaModels and solved with MadNLP suite.
   │
   ├─ Number of time steps: 250
   └─ Discretisation scheme: midpoint

▫ This is MadNLP version v0.8.12, running with cuDSS v0.7.1

Number of nonzeros in constraint Jacobian............:     4254
Number of nonzeros in Lagrangian Hessian.............:     5006

Total number of variables............................:     1506
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1004
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.0000000e-01 3.90e+00 6.00e-01 1.58e-07  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.0000355e-01 3.90e+00 8.28e-03 3.48e-06  -1.0 1.88e+02    -  1.00e+00 2.00e-07h  2
   2  5.1449485e+01 1.95e+00 1.49e-03 2.74e-06  -1.0 1.82e+01  -2.0 1.00e+00 5.00e-01h  2
   3  7.9293991e+01 5.24e-01 3.21e-05 2.00e-06  -1.0 1.19e+01  -0.7 1.00e+00 1.00e+00h  1
   4  1.2006318e+02 1.19e-02 2.89e-04 2.00e-06  -1.7 3.52e+00  -0.2 1.00e+00 1.00e+00h  1
   5  1.5471721e+02 1.63e-02 9.18e+00 2.17e-06  -3.8 5.77e+00  -0.7 1.00e+00 5.00e-01h  2
   6  2.2239687e+02 3.32e-02 3.09e+01 2.23e-06  -3.8 6.92e+00  -0.3 1.00e+00 5.00e-01h  2
   7  2.7195615e+02 5.32e-02 7.82e+01 2.60e-06  -3.8 1.13e+01  -0.8 1.00e+00 2.50e-01h  3
   8  3.1523638e+02 4.85e-02 2.32e+02 3.77e-06  -3.8 1.06e+01  -0.3 1.00e+00 1.25e-01h  4
   9  3.6219801e+02 4.81e-02 2.29e+02 3.92e-06  -3.8 2.06e+01  -0.8 1.00e+00 1.25e-01h  4
iter    objective    inf_pr   inf_du inf_compl lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  4.2547402e+02 4.75e-02 3.73e+02 4.80e-06  -3.8 1.35e+01  -0.4 1.00e+00 1.25e-01h  4

Number of Iterations....: 10

                                   (scaled)                 (unscaled)
Objective...............:   4.2547401691846102e+02    4.2547401691846102e+02
Dual infeasibility......:   3.7297322993663613e+02    3.7297322993663613e+02
Constraint violation....:   4.7491506630344779e-02    4.7491506630344779e-02
Complementarity.........:   4.7952429881045119e-06    4.7952429881045119e-06
Overall NLP error.......:   3.7297322993663613e+02    3.7297322993663613e+02

Number of objective function evaluations             = 33
Number of objective gradient evaluations             = 11
Number of constraint evaluations                     = 33
Number of constraint Jacobian evaluations            = 11
Number of Lagrangian Hessian evaluations             = 10
Total wall-clock secs in solver (w/o fun. eval./lin. alg.)  =  0.094
Total wall-clock secs in linear solver                      =  0.072
Total wall-clock secs in NLP function evaluations           =  0.014
Total wall-clock secs                                       =  0.179

EXIT: Maximum Number of Iterations Exceeded.
• Solver:
  ✓ Successful  : false
  │  Status     : MAXIMUM_ITERATIONS_EXCEEDED
  │  Message    : MadNLP
  │  Iterations : 10
  │  Objective  : 425.474016918461
  └─ Constraints violation : 0.04749150663034478

• Boundary duals: [0.0, 0.0, 0.0, 0.0]

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions