diff --git a/src/chapter3.ipynb b/src/chapter3.ipynb index c3861ec..cc4ec84 100644 --- a/src/chapter3.ipynb +++ b/src/chapter3.ipynb @@ -487,15 +487,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "f:(x[4],y)->(2x[4]) SXFunction\n" + "f:(x[4],y)->(f1[4]) SXFunction\n" ] } ], "source": [ "x = casadi.SX.sym('x',4)\n", "y = casadi.SX.sym(\"y\",1)\n", + "f1 = 2*x+y\n", "f = casadi.Function('f',\\\n", - " [x,y],[2*x+y],[\"x\",\"y\"],[\"2x\"])\n", + " [x,y],[f1],[\"x\",\"y\"],[\"f1\"])\n", "print(f)" ] }, @@ -508,10 +509,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'2x': DM([0, 0, 0, 0])}\n", - "{'2x': DM([2, 2, 2, 2])}\n", - "{'2x': DM([2, 4, 6, 8])}\n", - "{'2x': DM([3, 5, 7, 9])}\n" + "{'f1': DM([0, 0, 0, 0])}\n", + "{'f1': DM([2, 2, 2, 2])}\n", + "{'f1': DM([2, 4, 6, 8])}\n", + "{'f1': DM([3, 5, 7, 9])}\n" ] } ], @@ -619,16 +620,16 @@ "Number of equality constraint Jacobian evaluations = 8\n", "Number of inequality constraint Jacobian evaluations = 0\n", "Number of Lagrangian Hessian evaluations = 7\n", - "Total seconds in IPOPT = 0.003\n", + "Total seconds in IPOPT = 0.004\n", "\n", "EXIT: Optimal Solution Found.\n", " S : t_proc (avg) t_wall (avg) n_eval\n", - " nlp_f | 70.00us ( 8.75us) 5.89us (735.87ns) 8\n", - " nlp_g | 117.00us ( 14.62us) 8.44us ( 1.06us) 8\n", - " nlp_grad_f | 156.00us ( 17.33us) 11.28us ( 1.25us) 9\n", - " nlp_hess_l | 72.00us ( 10.29us) 5.51us (787.57ns) 7\n", - " nlp_jac_g | 78.00us ( 8.67us) 6.25us (694.78ns) 9\n", - " total | 46.37ms ( 46.37ms) 3.56ms ( 3.56ms) 1\n", + " nlp_f | 147.00us ( 18.38us) 9.17us ( 1.15us) 8\n", + " nlp_g | 359.00us ( 44.88us) 18.18us ( 2.27us) 8\n", + " nlp_grad_f | 219.00us ( 24.33us) 13.04us ( 1.45us) 9\n", + " nlp_hess_l | 133.00us ( 19.00us) 7.87us ( 1.12us) 7\n", + " nlp_jac_g | 145.00us ( 16.11us) 8.64us (960.22ns) 9\n", + " total | 64.01ms ( 64.01ms) 4.00ms ( 4.00ms) 1\n", "x_opt: [[-0.98575744]\n", " [ 0.16817333]]\n" ] @@ -797,16 +798,16 @@ "Number of equality constraint Jacobian evaluations = 0\n", "Number of inequality constraint Jacobian evaluations = 23\n", "Number of Lagrangian Hessian evaluations = 22\n", - "Total seconds in IPOPT = 0.015\n", + "Total seconds in IPOPT = 0.007\n", "\n", "EXIT: Optimal Solution Found.\n", " S : t_proc (avg) t_wall (avg) n_eval\n", - " nlp_f | 40.00us ( 1.43us) 33.28us ( 1.19us) 28\n", - " nlp_g | 113.00us ( 4.04us) 79.37us ( 2.83us) 28\n", - " nlp_grad_f | 44.00us ( 1.83us) 35.58us ( 1.48us) 24\n", - " nlp_hess_l | 50.00us ( 2.27us) 46.66us ( 2.12us) 22\n", - " nlp_jac_g | 59.00us ( 2.46us) 57.80us ( 2.41us) 24\n", - " total | 15.76ms ( 15.76ms) 15.67ms ( 15.67ms) 1\n", + " nlp_f | 20.00us (714.29ns) 14.03us (501.00ns) 28\n", + " nlp_g | 40.00us ( 1.43us) 28.40us ( 1.01us) 28\n", + " nlp_grad_f | 18.00us (750.00ns) 16.54us (689.25ns) 24\n", + " nlp_hess_l | 24.00us ( 1.09us) 21.71us (986.59ns) 22\n", + " nlp_jac_g | 32.00us ( 1.33us) 30.91us ( 1.29us) 24\n", + " total | 7.34ms ( 7.34ms) 7.36ms ( 7.36ms) 1\n", "x_opt: [1.40852591 1.40852594 3.5833495 8.06545437 7.18294817 2.81705192\n", " 3.19903525 1.40852594 8.24549622 3.62175816 7.18294816]\n" ] @@ -922,12 +923,12 @@ "\n", "EXIT: Optimal Solution Found.\n", " S : t_proc (avg) t_wall (avg) n_eval\n", - " nlp_f | 48.00us ( 1.14us) 40.46us (963.24ns) 42\n", - " nlp_g | 136.00us ( 3.24us) 93.24us ( 2.22us) 42\n", - " nlp_grad_f | 54.00us ( 1.38us) 45.96us ( 1.18us) 39\n", - " nlp_hess_l | 63.00us ( 1.80us) 58.16us ( 1.66us) 35\n", - " nlp_jac_g | 76.00us ( 1.95us) 74.57us ( 1.91us) 39\n", - " total | 4.67ms ( 4.67ms) 4.57ms ( 4.57ms) 1\n", + " nlp_f | 30.00us (714.29ns) 22.17us (527.79ns) 42\n", + " nlp_g | 64.00us ( 1.52us) 45.28us ( 1.08us) 42\n", + " nlp_grad_f | 33.00us (846.15ns) 29.85us (765.31ns) 39\n", + " nlp_hess_l | 41.00us ( 1.17us) 35.09us ( 1.00us) 35\n", + " nlp_jac_g | 52.00us ( 1.33us) 51.27us ( 1.31us) 39\n", + " total | 4.29ms ( 4.29ms) 4.29ms ( 4.29ms) 1\n", "x_opt: [1.35400803 1.35400806 3.26886459 8.00535938 7.29198392 2.70801631\n", " 1.35400806 3.26886459 8.00535938 2.70801631 7.29198392]\n" ] @@ -995,7 +996,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "S:(x0[2],p[],lbx[2],ubx[2],lbg[5],ubg[5],lam_x0[2],lam_g0[5])->(x[2],f,g[5],lam_x[2],lam_g[5],lam_p[]) MXFunction-----------------------------------------------------------------\n", + "S:(x0[2],p[],lbx[2],ubx[2],lbg[5],ubg[5],lam_x0[2],lam_g0[5])->(x[2],f,g[5],lam_x[2],lam_g[5],lam_p[]) MXFunction\n", + "-----------------------------------------------------------------\n", " OSQP v0.6.2 - Operator Splitting QP Solver\n", " (c) Bartolomeo Stellato, Goran Banjac\n", " University of Oxford - Stanford University 2021\n", @@ -1009,8 +1011,7 @@ " sigma = 1.00e-06, alpha = 1.60, max_iter = 4000\n", " check_termination: on (interval 25),\n", " scaling: on, scaled_termination: off\n", - " warm start: off, \n", - "polish: off, \n" + " warm start: off, polish: off, \n" ] } ], @@ -1039,7 +1040,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "x_opt: -----------------------------------------------------------------\n", + "x_opt: [[1.83318971]\n", + " [1.16662521]]\n", + "-----------------------------------------------------------------\n", " OSQP v0.6.2 - Operator Splitting QP Solver\n", " (c) Bartolomeo Stellato, Goran Banjac\n", " University of Oxford - Stanford University 2021\n", @@ -1047,9 +1050,7 @@ "problem: variables n = 2, constraints m = 7\n", " nnz(P) + nnz(A) = 12\n", "settings: linear system solver = qdldl,\n", - " [[1.83318971]\n", - " [1.16662521]]\n", - "eps_abs = 1.0e-03, eps_rel = 1.0e-03,\n", + " eps_abs = 1.0e-03, eps_rel = 1.0e-03,\n", " eps_prim_inf = 1.0e-04, eps_dual_inf = 1.0e-04,\n", " rho = 1.00e-01 (adaptive),\n", " sigma = 1.00e-06, alpha = 1.60, max_iter = 4000\n",