Skip to content

Commit 2ffc900

Browse files
update optimiser options and starting points
1 parent 0036dbb commit 2ffc900

7 files changed

Lines changed: 73 additions & 55 deletions

File tree

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from .analysis import Analysis
2-
from .routines import limit_analysis_GSF, thk_minmax_GSF, max_n_minmax_GSF
32

43
__all__ = [
54
"Analysis",
6-
"limit_analysis_GSF",
7-
"thk_minmax_GSF",
8-
"max_n_minmax_GSF",
95
]

src/compas_tno/optimisers/optimiser.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class Optimiser(Data):
3636
--------
3737
The main settings and default values are shown below:
3838
39-
* 'library' : ['Scipy', 'MATLAB', 'MMA', 'IPOPT', 'Scipy', ...]
40-
* 'solver' : ['SLSQP', 'IPOPT', 'MMA', ...],
39+
* 'solver' : ['SLSQP', 'IPOPT', ...],
4140
* 'objective' : ['min', 'max', 't', 'loadpath', 'bestfit', ...],
4241
* 'constraints' : ['funicular', 'envelope', 'reac_bounds', ...],
4342
* 'variables' : ['q', 'zb', 'xyb', 't', ...],
4443
* 'features' : ['fixed', 'sym', ...],
4544
* 'find_inds' : True,
45+
* 'solver_convex' : ['CLARABEL', 'MOSEK', 'CVXPY', ...],
4646
* 'exitflag' : 1,
4747
* 'printout' : True,
4848
* 'starting_point' : 'current',
@@ -80,7 +80,7 @@ def __init__(self, **kwargs):
8080
"printout": False,
8181
"plot": False,
8282
"starting_point": "current",
83-
"solver_convex": "CVXPY",
83+
"solver_convex": "CLARABEL",
8484
"support_displacement": None,
8585
"gradient": True,
8686
"jacobian": True,
@@ -269,7 +269,7 @@ def create_maxthrust_optimiser(
269269
@classmethod
270270
def create_max_horload_optimiser(
271271
cls,
272-
solver: str = "IPOPT",
272+
solver: str = "SLSQP",
273273
max_iter: int = 500,
274274
printout: bool = False,
275275
plot: bool = False,
@@ -364,7 +364,7 @@ def create_bestfit_optimiser(
364364
@classmethod
365365
def create_max_vertload_optimiser(
366366
cls,
367-
solver: str = "IPOPT",
367+
solver: str = "SLSQP",
368368
max_iter: int = 500,
369369
printout: bool = False,
370370
plot: bool = False,
@@ -416,7 +416,7 @@ def create_max_vertload_optimiser(
416416
@classmethod
417417
def create_lp_optimiser(
418418
cls,
419-
solver: str = "MATLAB",
419+
solver: str = "CLARABEL",
420420
printout: bool = False,
421421
plot: bool = False,
422422
max_iter: int = 500,
@@ -444,11 +444,11 @@ def create_lp_optimiser(
444444
Raises
445445
------
446446
ValueError
447-
If solver is not one of: "MATLAB", "CVXPY".
447+
If solver is not one of: "CLARABEL", "MOSEK", "CVXPY".
448448
449449
"""
450-
if solver not in ["MATLAB", "CVXPY"]:
451-
raise ValueError("For loadpath optimisation only MATLAB or CVXPY are possible solvers. See solvers page.")
450+
if solver not in ["CLARABEL", "MOSEK", "CVXPY"]:
451+
raise ValueError("For loadpath optimisation only CLARABEL, MOSEK, CVXPY are possible solvers. See solvers page.")
452452

453453
optimiser = cls()
454454
optimiser.set_solver(solver)

src/compas_tno/problems/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
from .callbacks import callback_save_json, callback_create_json, save_geometry_at_iterations
4949

50-
from .startingpoint import startingpoint_loadpath, startingpoint_tna, startingpoint_fdm
50+
from .startingpoint import startingpoint_loadpath, startingpoint_tna, startingpoint_fdm, startingpoint_sag
5151

5252
from .setup import (
5353
set_up_general_optimisation,
@@ -101,6 +101,7 @@
101101
"startingpoint_loadpath",
102102
"startingpoint_tna",
103103
"startingpoint_fdm",
104+
"startingpoint_sag",
104105
"set_up_general_optimisation",
105106
"set_up_convex_optimisation",
106107
"startingpoint_loadpath_proxy",

src/compas_tno/problems/callbacks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from numpy import array
44

55
import compas_tno
6-
from compas_tno.algorithms import reciprocal_from_form
6+
from compas_tna.diagrams import FormDiagram
7+
8+
# from compas_tno.algorithms import reciprocal_from_form
79
from compas_tno.algorithms import xyz_from_xopt
8-
from compas_tno.diagrams import FormDiagram
910
from compas_tno.optimisers import Optimiser
1011

1112

@@ -92,7 +93,8 @@ def save_geometry_at_iterations(form: FormDiagram, optimiser: Optimiser, force=F
9293
form.edge_attribute(edge, "q", problem.q.flatten()[k])
9394
k += 1
9495

95-
force = reciprocal_from_form(form)
96+
raise NotImplementedError("Force diagram not implemented for TNO yet")
97+
# force = reciprocal_from_form(form)
9698
Xforce_i = force.vertices_attributes("xyz")
9799
Xforce[str(i)] = Xforce_i
98100

src/compas_tno/problems/problems.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
from compas_tno.shapes import Shape
1414

1515
# from numpy import asarray
16+
from dataclasses import dataclass
17+
from dataclasses import field
18+
from typing import Any
19+
from typing import Dict
20+
from typing import List
21+
from typing import Optional
22+
23+
import numpy.typing as npt
1624
from numpy import array
1725
from numpy import hstack
1826
from numpy import identity
@@ -26,15 +34,14 @@
2634
from scipy.sparse import vstack as svstack
2735

2836
from compas.geometry import Point
29-
from compas.geometry import distance_point_point_xy
3037
from compas.matrices import connectivity_matrix
38+
from compas_tna.diagrams import FormDiagram
3139
from compas_tna.envelope import Envelope
3240

3341
# from compas_tno.algorithms import check_independents
3442
# from compas.utilities import reverse_geometric_key
3543
from compas_tno.algorithms import check_horizontal_loads
3644
from compas_tno.algorithms import find_independents
37-
from compas_tno.diagrams import FormDiagram
3845
from compas_tno.utilities import apply_radial_symmetry
3946
from compas_tno.utilities import apply_symmetry_from_axis
4047
from compas_tno.utilities import build_symmetry_transformation
@@ -45,16 +52,6 @@ def reverse_geometric_key(gkey):
4552
raise NotImplementedError
4653

4754

48-
from dataclasses import dataclass
49-
from dataclasses import field
50-
from typing import Any
51-
from typing import Dict
52-
from typing import List
53-
from typing import Optional
54-
55-
import numpy.typing as npt
56-
57-
5855
@dataclass
5956
class Problem:
6057
"""

src/compas_tno/problems/setup.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from numpy import vstack
88
from numpy import zeros
99

10-
from compas_tno.algorithms import apply_sag
1110
from compas_tno.algorithms import equilibrium_fdm
1211
from compas_tno.algorithms import q_from_variables
1312
from compas_tno.algorithms import xyz_from_q
@@ -21,6 +20,7 @@
2120
from compas_tno.problems import objective_selector
2221
from compas_tno.problems import sensitivities_wrapper
2322
from compas_tno.problems import startingpoint_loadpath
23+
from compas_tno.problems import startingpoint_sag
2424
from compas_tno.problems import startingpoint_tna
2525
from compas_tno.utilities import compute_edge_stiffness
2626
from compas_tno.utilities import compute_form_initial_lengths
@@ -66,7 +66,7 @@ def set_up_general_optimisation(analysis: "Analysis"):
6666
qmax = optimiser.settings.get("qmax", +1e-8)
6767
features = optimiser.settings.get("features", [])
6868
save_iterations = optimiser.settings.get("save_iterations", False)
69-
solver_convex = optimiser.settings.get("solver_convex", "MATLAB")
69+
solver_convex = optimiser.settings.get("solver_convex", "CLARABEL")
7070
autodiff = optimiser.settings.get("autodiff", False)
7171

7272
pattern_center = form.centroid()
@@ -115,8 +115,8 @@ def set_up_general_optimisation(analysis: "Analysis"):
115115
pass
116116

117117
elif starting_point == "sag":
118-
apply_sag(form, boundary_force=50.0) # the issue here is that after the sag the problem.x0, problem.y0 are not updated
119-
startingpoint_tna(form)
118+
boundary_force = 50.0
119+
startingpoint_sag(form, boundary_force=boundary_force)
120120

121121
elif starting_point == "loadpath":
122122
printout_loadpath = False # this need to be a proper verbose level
@@ -447,7 +447,15 @@ def set_up_convex_optimisation(analysis: "Analysis"):
447447
else:
448448
print("Warning: Non-convex problem for the constraints: ", constraints, ". Considering only 'funicular' instead.")
449449

450-
form.apply_bounds_on_q(qmin=qmin, qmax=qmax)
450+
# Apply bounds on the edges' force densities (apply_bounds_on_q)
451+
if isinstance(qmin, list):
452+
for i, edge in enumerate(form.edges_where({"_is_edge": True})):
453+
form.edge_attribute(edge, "qmin", qmin[i])
454+
form.edge_attribute(edge, "qmax", qmax[i])
455+
else:
456+
for i, edge in enumerate(form.edges_where({"_is_edge": True})):
457+
form.edge_attribute(edge, "qmin", qmin)
458+
form.edge_attribute(edge, "qmax", qmax)
451459

452460
problem = initialise_problem_general(form)
453461
problem.variables = variables

src/compas_tno/problems/startingpoint.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22

33
from compas_tno.algorithms import compute_reactions
44
from compas_tno.algorithms import equilibrium_fdm
5-
from compas_tno.algorithms import form_update_with_parallelisation
6-
from compas_tno.solvers.solver_cvxpy import run_loadpath_from_form_CVXPY
7-
from compas_tno.solvers.solver_MATLAB import run_loadpath_from_form_MATLAB
5+
from compas_tno.solvers import run_loadpath_from_form_CVXPY
86

97

10-
def startingpoint_loadpath(form, problem=None, find_inds=False, solver_convex="CVXPY", printout=False):
8+
def startingpoint_sag(form, boundary_force=50.0, **kwargs):
9+
"""Initialize the equilibrium in a form diagram with applied loads using sag approach
10+
11+
Parameters
12+
----------
13+
form : :class:`~compas_tno.diagrams.FormDiagram`
14+
The form diagram. Loads and support must already have been assigned
15+
boundary_force : float, optional
16+
Force density in the edges on the boundary.
17+
The default value is ``50.0``.
18+
"""
19+
form.edges_attribute("q", min(boundary_force, -1 * boundary_force), list(form.edges_on_boundary()))
20+
startingpoint_fdm(form)
21+
for key in form.vertices():
22+
form.vertex_attribute(key, "z", 0.0)
23+
return form
24+
25+
26+
def startingpoint_loadpath(form, problem=None, find_inds=False, solver_convex="CLARABEL", printout=False, **kwargs):
1127
"""Built-in function to optimise the loadpath considering diagram fixed projection.
12-
Note: This function will select the most appropriate solver (CVX or MOSEK)
1328
1429
Parameters
1530
----------
@@ -20,7 +35,8 @@ def startingpoint_loadpath(form, problem=None, find_inds=False, solver_convex="C
2035
find_inds : bool, optional
2136
If independents need to be found before the loadpath computation, by default False
2237
solver_convex : str, optional
23-
Solver to compute the convex optimisation, by default CVXPY
38+
Solver to use, by default CLARABEL. Options are "CLARABEL", "MOSEK" or "CVXOPT".
39+
Note: "MOSEK" and "CVXOPT" are not available in the default installation of TNO.
2440
printout : bool, optional
2541
If prints about the optimisation data should appear in the screen, by default False
2642
@@ -30,22 +46,18 @@ def startingpoint_loadpath(form, problem=None, find_inds=False, solver_convex="C
3046
The class with the main matrices of the problem
3147
"""
3248

33-
if solver_convex == "CVX" or solver_convex == "MATLAB":
34-
if not importlib.util.find_spec("matlab"):
35-
raise ValueError("MATLAB/CVX not configured. Try changing the <solver_convex> attribute.")
36-
problem = run_loadpath_from_form_MATLAB(form, problem=problem, find_inds=find_inds, printout=printout)
37-
elif solver_convex == "CVXPY" or solver_convex == "MOSEK":
38-
if not importlib.util.find_spec("cvxpy"):
39-
raise ValueError("CVXPY/MOSEK not configured. Try changing the <solver_convex> attribute.")
40-
problem = run_loadpath_from_form_CVXPY(form, problem=problem, find_inds=find_inds, printout=printout)
41-
else:
42-
raise ValueError("Could not initilalise loadpath optimisation with {}. Try changing the <solver_convex> attribute.".format(solver_convex))
49+
problem = run_loadpath_from_form_CVXPY(
50+
form,
51+
problem=problem,
52+
find_inds=find_inds,
53+
solver_convex=solver_convex,
54+
printout=printout,
55+
)
4356

4457
return problem
4558

4659

47-
# Use the appropiate functions at TNA here
48-
def startingpoint_tna(form, plot=False):
60+
def startingpoint_tna(form, plot=False, **kwargs):
4961
"""Initialize the equilibrium in a form diagram with applied loads using TNA interative solver procedure (form and force diagrams are parallel)
5062
5163
Parameters
@@ -56,13 +68,15 @@ def startingpoint_tna(form, plot=False):
5668
Plots of the intermediare and final force diagrams to follow the process, by default False
5769
"""
5870

59-
form_update_with_parallelisation(form, plot=plot)
71+
# form_update_with_parallelisation(form, plot=plot)
6072

61-
compute_reactions(form)
73+
# compute_reactions(form)
74+
75+
raise NotImplementedError("Starting point not implemented for TNA")
6276

6377

6478
# Use the appropiate functions at TNA here
65-
def startingpoint_fdm(form):
79+
def startingpoint_fdm(form, **kwargs):
6680
"""Initialize the equilibrium in a form diagram with applied loads using FDM approach for the q's stored in the form
6781
6882
Parameters

0 commit comments

Comments
 (0)