Inverse
inverse
This module provides classes to perform an adjoint inverse optimisation and checkpoint
intermediate results. Users instantiate the LinMoreOptimiser
class by providing
relevant parameters and call the run
method to perform the optimisation.
ROLSolver(problem, parameters, inner_product='L2', vector_class=pyadjoint_rol.ROLVector, vector_args=[])
Bases: ROLSolver
A ROLSolver that may use a class other than ROLVector to hold its vectors.
In the non-checkpointing case, this reduces down to the original ROLSolver class.
However, if ROL checkpointing is enabled, every vector within the solver needs to be
a CheckpointedROLVector. We can achieve this by overwriting the base
self.rolvector
member.
Initialises the solver instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
problem |
MinimizationProblem
|
PyAdjoint minimisation problem to solve. |
required |
parameters |
dict
|
Dictionary containing the parameters governing ROL. |
required |
inner_product |
str
|
String representing the inner product to use for vector operations. |
'L2'
|
vector_class |
PyAdjoint ROL vector representing the underlying vector class. |
ROLVector
|
|
vector_args |
list
|
List of arguments for initialisation of the vector class. |
[]
|
Source code in g-adopt/gadopt/inverse.py
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 |
|
LinMoreOptimiser(problem, parameters, checkpoint_dir=None, auto_checkpoint=True)
The management class for Lin-More trust region optimisation using ROL.
This class sets up ROL to use the Lin-More trust region method, with a limited-memory BFGS secant for determining the steps. A pyadjoint problem has to be set up first, containing the optimisation functional and other constraints (like bounds).
This optimiser also supports checkpointing ROL's state, to allow resumption of
a previous optimisation without having to refill the L-BFGS memory. The underlying
objects will be configured for checkpointing if checkpoint_dir
is specified,
and optionally the automatic checkpointing each iteration can be disabled by the
auto_checkpoint
parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
problem |
MinimizationProblem
|
The actual problem to solve. |
required |
parameters |
dict
|
A dictionary containing the parameters governing ROL. |
required |
checkpoint_dir |
Optional[str]
|
A path to hold any checkpoints that are saved. |
None
|
auto_checkpoint |
Optional[bool]
|
Whether to automatically checkpoint each iteration. |
True
|
Source code in g-adopt/gadopt/inverse.py
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 110 111 112 113 114 115 116 117 118 119 120 121 |
|
checkpoint()
Checkpoints the current ROL state to disk.
Source code in g-adopt/gadopt/inverse.py
136 137 138 139 140 141 142 143 144 |
|
restore(iteration=None)
Restores the ROL state from disk.
The last stored iteration in checkpoint_dir
is used unless a given iteration
is specifed.
Source code in g-adopt/gadopt/inverse.py
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 |
|
run()
Runs the actual ROL optimisation.
This will continue until the status test flags the optimisation to complete.
Source code in g-adopt/gadopt/inverse.py
183 184 185 186 187 188 189 190 191 192 193 194 |
|
add_callback(callback)
Adds a callback to run after every optimisation iteration.
Source code in g-adopt/gadopt/inverse.py
213 214 215 216 |
|
CheckpointedROLVector(dat, optimiser, inner_product='L2')
Bases: ROLVector
An extension of ROLVector that supports checkpointing to disk.
The ROLVector itself is the Python-side implementation of the ROL.Vector interface; it defines all the operations ROL may perform on vectors (e.g., scaling, addition) and links ROL to the underlying Firedrake vectors.
When the serialisation library hits a ROL.Vector on the C++ side, it will pickle
this object, so we provide implementations of __getstate__
and __setstate__
that will correctly participate in the serialisation pipeline.
Initialises the checkpointed ROL vector instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dat |
Function
|
Firedrake function. |
required |
optimiser |
LinMoreOptimiser
|
The managing optimiser for controlling checkpointing paths. |
required |
inner_product |
str
|
String representing the inner product to use for vector operations. |
'L2'
|
Source code in g-adopt/gadopt/inverse.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
save(checkpoint_path)
Checkpoints the data within this vector to disk.
Called when this object is pickled as part of the ROL state serialisation.
Source code in g-adopt/gadopt/inverse.py
261 262 263 264 265 266 267 268 269 270 |
|
load(mesh)
Loads the checkpointed data for this vector from disk.
Called by the parent Optimiser after the ROL state has been deserialised. The pickling routine will register this vector within the registry.
Source code in g-adopt/gadopt/inverse.py
272 273 274 275 276 277 278 279 280 281 282 |
|
__setstate__(state)
Sets the state from the result of unpickling.
This happens during the restoration of a checkpoint. self.dat needs to be separately set, then self.load() can be called.
Source code in g-adopt/gadopt/inverse.py
284 285 286 287 288 289 290 291 292 293 294 295 |
|
__getstate__()
Returns a state tuple suitable for pickling
Source code in g-adopt/gadopt/inverse.py
297 298 299 300 301 302 303 304 |
|