Skip to content

Commit

Permalink
update syntax to not use sol.value() but instead sol()
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Jan 26, 2024
1 parent 818fa08 commit 178f8c9
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 155 deletions.
58 changes: 43 additions & 15 deletions tutorial/01 - Optimization and Math/01 - 2D Rosenbrock.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"This is Ipopt version 3.12.3, running with linear solver mumps.\n",
"NOTE: Other linear solvers might be more efficient (see Ipopt documentation).\n",
"This is Ipopt version 3.14.11, running with linear solver MUMPS 5.4.1.\n",
"\n",
"Number of nonzeros in equality constraint Jacobian...: 0\n",
"Number of nonzeros in inequality constraint Jacobian.: 0\n",
Expand All @@ -45,17 +44,18 @@
" inequality constraints with only upper bounds: 0\n",
"\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 0 1.0000000e+002 0.00e+000 2.00e+000 0.0 0.00e+000 - 0.00e+000 0.00e+000 0\n",
" 1 0.0000000e+000 0.00e+000 0.00e+000 -11.0 1.00e+000 - 1.00e+000 1.00e+000f 1\n",
" 0 1.0000000e+02 0.00e+00 2.00e+00 0.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
" 1 0.0000000e+00 0.00e+00 0.00e+00 -11.0 1.00e+00 - 1.00e+00 1.00e+00f 1\n",
"\n",
"Number of Iterations....: 1\n",
"\n",
" (scaled) (unscaled)\n",
"Objective...............: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Dual infeasibility......: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Constraint violation....: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Complementarity.........: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Overall NLP error.......: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Objective...............: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Dual infeasibility......: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Constraint violation....: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Variable bound violation: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Overall NLP error.......: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"\n",
"\n",
"Number of objective function evaluations = 2\n",
Expand All @@ -65,15 +65,14 @@
"Number of equality constraint Jacobian evaluations = 0\n",
"Number of inequality constraint Jacobian evaluations = 0\n",
"Number of Lagrangian Hessian evaluations = 1\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.001\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"Total seconds in IPOPT = 0.002\n",
"\n",
"EXIT: Optimal Solution Found.\n",
" solver : t_proc (avg) t_wall (avg) n_eval\n",
" nlp_f | 0 ( 0) 0 ( 0) 2\n",
" nlp_grad_f | 0 ( 0) 0 ( 0) 3\n",
" nlp_hess_l | 0 ( 0) 0 ( 0) 1\n",
" total | 2.00ms ( 2.00ms) 1.99ms ( 1.99ms) 1\n",
" nlp_f | 0 ( 0) 4.00us ( 2.00us) 2\n",
" nlp_grad_f | 0 ( 0) 11.00us ( 3.67us) 3\n",
" nlp_hess_l | 0 ( 0) 4.00us ( 4.00us) 1\n",
" total | 2.00ms ( 2.00ms) 1.91ms ( 1.91ms) 1\n",
"x = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
" 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
" 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
Expand Down Expand Up @@ -103,7 +102,7 @@
"sol = opti.solve()\n",
"\n",
"# Extract values at the optimum\n",
"x_opt = sol.value(x)\n",
"x_opt = sol(x)\n",
"\n",
"# Print values\n",
"print(f\"x = {x_opt}\")"
Expand All @@ -112,6 +111,10 @@
"collapsed": false,
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-01-26T03:17:07.748321900Z",
"start_time": "2024-01-26T03:17:06.208595600Z"
}
}
},
Expand Down Expand Up @@ -177,4 +180,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
"collapsed": false,
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-01-26T03:17:16.237726500Z",
"start_time": "2024-01-26T03:17:14.988130600Z"
}
}
},
Expand All @@ -118,8 +122,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"This is Ipopt version 3.12.3, running with linear solver mumps.\n",
"NOTE: Other linear solvers might be more efficient (see Ipopt documentation).\n",
"This is Ipopt version 3.14.11, running with linear solver MUMPS 5.4.1.\n",
"\n",
"Number of nonzeros in equality constraint Jacobian...: 0\n",
"Number of nonzeros in inequality constraint Jacobian.: 2\n",
Expand All @@ -136,21 +139,22 @@
" inequality constraints with only upper bounds: 1\n",
"\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 0 3.7157948e-001 1.43e+000 2.48e-002 0.0 0.00e+000 - 0.00e+000 0.00e+000 0\n",
" 1 1.0109896e+000 0.00e+000 1.25e+000 -1.9 1.44e+000 - 1.00e+000 1.00e+000h 1\n",
" 2 1.0081910e+000 0.00e+000 5.21e-004 -2.1 2.77e-003 - 9.99e-001 1.00e+000f 1\n",
" 3 1.0001005e+000 0.00e+000 1.66e-004 -8.1 8.06e-003 - 9.87e-001 1.00e+000f 1\n",
" 4 1.0000000e+000 0.00e+000 5.56e-008 -10.1 1.00e-004 - 1.00e+000 1.00e+000f 1\n",
" 5 9.9999998e-001 0.00e+000 4.44e-016 -11.0 2.44e-008 - 1.00e+000 1.00e+000f 1\n",
" 0 3.7157948e-01 1.43e+00 2.48e-02 0.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
" 1 1.0109896e+00 0.00e+00 1.25e+00 -1.9 1.44e+00 - 1.00e+00 1.00e+00h 1\n",
" 2 1.0081910e+00 0.00e+00 5.21e-04 -2.1 2.77e-03 - 9.99e-01 1.00e+00f 1\n",
" 3 1.0001005e+00 0.00e+00 1.66e-04 -8.1 8.06e-03 - 9.87e-01 1.00e+00f 1\n",
" 4 1.0000000e+00 0.00e+00 5.56e-08 -10.1 1.00e-04 - 1.00e+00 1.00e+00f 1\n",
" 5 9.9999998e-01 0.00e+00 4.44e-16 -11.0 2.44e-08 - 1.00e+00 1.00e+00f 1\n",
"\n",
"Number of Iterations....: 5\n",
"\n",
" (scaled) (unscaled)\n",
"Objective...............: 9.9999998430203862e-001 9.9999998430203862e-001\n",
"Dual infeasibility......: 4.4408920985006262e-016 4.4408920985006262e-016\n",
"Constraint violation....: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Complementarity.........: 1.0001999071900712e-011 1.0001999071900712e-011\n",
"Overall NLP error.......: 1.0001999071900712e-011 1.0001999071900712e-011\n",
"Objective...............: 9.9999998430203862e-01 9.9999998430203862e-01\n",
"Dual infeasibility......: 4.4408920985006262e-16 4.4408920985006262e-16\n",
"Constraint violation....: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Variable bound violation: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Complementarity.........: 1.0001999071900710e-11 1.0001999071900710e-11\n",
"Overall NLP error.......: 1.0001999071900710e-11 1.0001999071900710e-11\n",
"\n",
"\n",
"Number of objective function evaluations = 6\n",
Expand All @@ -160,32 +164,35 @@
"Number of equality constraint Jacobian evaluations = 0\n",
"Number of inequality constraint Jacobian evaluations = 6\n",
"Number of Lagrangian Hessian evaluations = 5\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.004\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"Total seconds in IPOPT = 0.004\n",
"\n",
"EXIT: Optimal Solution Found.\n",
" solver : t_proc (avg) t_wall (avg) n_eval\n",
" nlp_f | 0 ( 0) 0 ( 0) 6\n",
" nlp_g | 0 ( 0) 0 ( 0) 6\n",
" nlp_grad_f | 0 ( 0) 0 ( 0) 7\n",
" nlp_hess_l | 0 ( 0) 0 ( 0) 5\n",
" nlp_jac_g | 0 ( 0) 0 ( 0) 7\n",
" total | 6.00ms ( 6.00ms) 5.98ms ( 5.98ms) 1\n",
" nlp_f | 0 ( 0) 9.00us ( 1.50us) 6\n",
" nlp_g | 0 ( 0) 7.00us ( 1.17us) 6\n",
" nlp_grad_f | 0 ( 0) 14.00us ( 2.00us) 7\n",
" nlp_hess_l | 0 ( 0) 11.00us ( 2.20us) 5\n",
" nlp_jac_g | 0 ( 0) 4.00us (571.43ns) 7\n",
" total | 4.00ms ( 4.00ms) 3.88ms ( 3.88ms) 1\n",
"x = 1.5707963424928582\n"
]
}
],
"source": [
"sol = opti.solve()\n",
"\n",
"x_opt = sol.value(x)\n",
"x_opt = sol(x)\n",
"\n",
"print(f\"x = {x_opt}\")"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-01-26T03:17:16.252353200Z",
"start_time": "2024-01-26T03:17:16.235722200Z"
}
}
},
Expand Down Expand Up @@ -226,4 +233,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Loading

0 comments on commit 178f8c9

Please sign in to comment.