compas_cem.optimization
¤
The constrained form-finding solver, its goals and its optimization parameters.
Classes¤
Optimizer
¤
An object that modifies a form diagram to meet multiple goals.
Source code in src/compas_cem/optimization/optimizer.py
Methods:¤
__repr__
¤
add_goal
¤
add_parameter
¤
check_optimization_sanity
¤
Verify the optimization problem is in its sane mind.
Source code in src/compas_cem/optimization/optimizer.py
gradient_func
¤
The objective function to calculate gradients from.
Source code in src/compas_cem/optimization/optimizer.py
number_of_goals
¤
number_of_parameters
¤
objective_func
¤
The objective function to minimize.
Source code in src/compas_cem/optimization/optimizer.py
optimization_bounds
¤
Creates optimization bounds array. Only one entry in the array per goal.
Source code in src/compas_cem/optimization/optimizer.py
optimization_parameters
¤
Creates optimization paremeters array. Only one entry in the array per goal. Takes care of keeping the ordering.
Source code in src/compas_cem/optimization/optimizer.py
remove_goal
¤
remove_parameter
¤
Removes an optimization parameter.
solve
¤
solve(
topology,
algorithm="SLSQP",
grad="AD",
step_size=1e-06,
iters=100,
eps=1e-06,
kappa=1e-08,
tmax=100,
eta=1e-06,
verbose=False,
)
Solve a constrained form-finding problem using gradient-based optimization.
Parameters:
-
topology(:class:`compas_cem.diagrams.TopologyDiagram`) –A topology diagram.
-
algorithm(``str``, default:'SLSQP') –The name of the gradient-based local optimization algorithm to use. Only the following local gradient-based optimization algorithms are supported:
- SLSQP: Sequential Least Squares Programming
- LBFGS: Low-Storage Broyden-Fletcher-Goldfarb-Shanno
- MMA: Method of Moving Asymptotes
- TNEWTON: Preconditioned Truncated Newton
- AUGLAG: Augmented Lagrangian
- VAR: Limited-Memory Variable-Metric Algorithm
Defaults to "SLSQP". Refer to the NLopt
documentation <https://nlopt.readthedocs.io/en/latest/>_ for more details on their theoretical underpinnings. -
grad(``str``, default:'AD') –The method to compute the gradient of the objective function. The currently available methods are:
- AD: Automatic differentiation
- FD: Finite differences
Defaults to "AD".
-
iters(``int``, default:100) –The maximum number of iterations to run the optimization algorithm for. Defaults to
100. -
eps(``float``, default:1e-06) –The convergence threshold for the output value of the objective function. Defaults to
1e-6. -
kappa(``float``, default:1e-08) –The convergence threshold for the norm of the gradient of the objective function. Defaults to
1e-8. -
step_size(``float``, default:1e-06) –The step size to calculate the gradient of the objective function via finite differences. It becomes active only if
grad="FD". It is otherwise ignored by this function. Defaults to1e-3. -
tmax(``int``, default:100) –The maximum number of iterations the CEM form-finding algorithm will run for. If
etais hit first, the form-finding algorithm will stop early. Defaults to100. -
eta(``float``, default:1e-06) –The numerical converge threshold of the CEM form-finding algorithm. If
tmaxis hit first, the form-finding algorithm will stop early. Defaults to1e-6. -
verbose(``bool``, default:False) –A flag to prints statistics of the optimization process. Defaults to
True.
Returns:
-
form(:class:`compas_cem.diagrams.FormDiagram`) –A form diagram.
Source code in src/compas_cem/optimization/optimizer.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
Functions:¤
grad_autograd
¤
Calculate the gradient with automatic differentiation. This function updates grad in place.
grad_finite_differences
¤
Approximate the gradient of a blackbox function using forward finite differences. This function updates grad in place.
Source code in src/compas_cem/optimization/grad.py
nlopt_algorithm
¤
Fetches an optimization algorithm from the nlopt library by name.
Parameters:
-
name(``str``) –The name of the algorithm to search for.
Returns:
-
algorithm(``nlopt.algorithm``) –An nlopt algorithm object.
Notes
Only the following local gradient-based optimization algorithms are supported:
- SLSQP: Sequential Least Squares Programming
- LBFGS: Low-Storage Broyden-Fletcher-Goldfarb-Shanno
- MMA: Method of Moving Asymptotes
- TNEWTON: Preconditioned Truncated Newton
- AUGLAG: Augmented Lagrangian
- VAR: Limited-Memory Variable-Metric Algorithm
Refer to the NLopt documentation <https://nlopt.readthedocs.io/en/latest/>_ for more details on their theoretical underpinnings.
Source code in src/compas_cem/optimization/nlopt.py
nlopt_algorithms
¤
A dictionary with all the supported nlopt algorithms.
Returns:
-
algorithms(``dict``) –A dictionary that maps algorithm names to nlopt algorithm objects.
Notes
Only the following local gradient-based optimization algorithms are supported:
- SLSQP: Sequential Least Squares Programming
- LBFGS: Low-Storage Broyden-Fletcher-Goldfarb-Shanno
- MMA: Method of Moving Asymptotes
- TNEWTON: Preconditioned Truncated Newton
- AUGLAG: Augmented Lagrangian
- VAR: Limited-Memory Variable-Metric Algorithm
Refer to the NLopt documentation <https://nlopt.readthedocs.io/en/latest/>_ for more details on their theoretical underpinnings.
Source code in src/compas_cem/optimization/nlopt.py
nlopt_solver
¤
Wrapper around a typical nlopt solver routine.
Source code in src/compas_cem/optimization/nlopt.py
nlopt_status
¤
Convert the number constant returned by the optimization process into a human-readable string.
Input
constant : int
The constant returned by the optimization algorithm as result.
Returns:
-
status(``str``) –A human-readable string.
Source code in src/compas_cem/optimization/nlopt.py
objective_function_numpy
¤
solve_proxy
¤
solve_proxy(
topology,
goals,
parameters,
algorithm,
iters,
eps=1e-06,
kappa=1e-08,
tmax=100,
eta=1e-06,
)
Solve a constrained form-finding problem through a Proxy hyperspace tunnel.
Parameters:
-
topology(:class:`compas_cem.diagrams.TopologyDiagram`) –A topology diagram.
-
goals(``list``) –A list with the goals to optimize for.
-
parameters(``list``) –A list of optimization parameters.
-
algorithm(``str``) –The name of the gradient-based local optimization algorithm to use. Only the following local gradient-based optimization algorithms are supported:
- SLSQP: Sequential Least Squares Programming
- LBFGS: Low-Storage Broyden-Fletcher-Goldfarb-Shanno
- MMA: Method of Moving Asymptotes
- TNEWTON: Preconditioned Truncated Newton
- AUGLAG: Augmented Lagrangian
- VAR: Limited-Memory Variable-Metric Algorithm
Defaults to "SLSQP". Refer to the NLopt
documentation <https://nlopt.readthedocs.io/en/latest/>_ for more details on their theoretical underpinnings. -
iters(``int``) –The maximum number of iterations to run the optimization algorithm for. Defaults to
100. -
eps(``float``, default:1e-06) –The convergence threshold for the output value of the objective function. Defaults to
1e-6. -
kappa(``float``, default:1e-08) –The convergence threshold for the norm of the gradient of the objective function. Defaults to
1e-8. -
tmax(``int``, default:100) –The maximum number of iterations the CEM form-finding algorithm will run for. If
etais hit first, the form-finding algorithm will stop early. Defaults to100. -
eta(``float``, default:1e-06) –The numerical converge threshold of the CEM form-finding algorithm. If
tmaxis hit first, the form-finding algorithm will stop early. Defaults to1e-6.
Returns:
-
topology(:class:`compas_cem.diagrams.TopologyDiagram`) –The topology diagram with optimal parameters as found by the optimization algorithm.
-
form(:class:`compas_cem.diagrams.FormDiagram`) –The constrained form diagram.
-
objective(`float`) –The final value of the objective function.
-
grad_norm(`float`) –The cummulative norm of the gradients.
-
iters(`int`) –The elapsed number of iterations.
-
duration(`float`) –The total optimization time in milliseconds.
-
status(`str`) –The final status of the optimization problem as per NLOpt.
Source code in src/compas_cem/optimization/proxy.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |