Optimisation Loop
- class stride.optimisation.optimisation_loop.OptimisationLoop(name='optimisation_loop', **kwargs)[source]
Bases:
stride.problem.base.Saved
Objects of this class act as managers of a local optimisation process.
The general convention is to divide the optimisation process in blocks and iterations, although that doesn’t have to be the case. A block determines a set of conditions that is maintained over a number of iterations, such as the frequency band used or the step size applied.
Blocks are generated through
Optimisation.blocks
:>>> for block in optimisation.blocks(num_blocks, *iterators): >>> block.config(...) >>>
The default running behaviour of the optimisation is obtained when calling
Optimisation.run(block, problem)
:>>> for block in optimisation.blocks(num_blocks, *iterators): >>> block.config(...) >>> await optimisation.run(block, problem)
but iterations can also be run manually:
>>> for block in optimisation.blocks(num_blocks, *iterators): >>> block.config(...) >>> >>> for iteration in block.iterations(num_iterations, *iterators): >>> pass
- Parameters
name (str, optional) – Optional name for the optimisation object.
- blocks(num, *iters, restart=False, restart_id=- 1, **kwargs)[source]
Generator for the blocks of the optimisation.
- Parameters
num (int) – Number of blocks to generate.
iters (tuple, optional) – Any other iterables to zip with the blocks.
restart (int or bool, optional) – Whether or not attempt to restart the loop from a previous block. Defaults to
False
.restart_id (int, optional) – If an integer greater than zero, it will restart from a specific block. Otherwise, it will restart from the latest available block.
- Returns
Blocks iterable.
- Return type
iterable
- property current_block
Get current active block.
- dump(*args, **kwargs)[source]
Dump latest version of the loop to a file.
See
Saved
for more information on the parameters of this method.- Parameters
args –
kwargs –
- property num_blocks
Get number of blocks.
- property problem
Access problem object.
- class stride.optimisation.optimisation_loop.Block(id, opt_loop, **kwargs)[source]
Bases:
object
A block determines a set of conditions that is maintained over a number of iterations, such as the frequency band used or the step size applied.
The iteration loop of the block can be started using the generator
Block.iterations
as:>>> for iteration in block.iterations(num_iterations, *iterators): >>> pass
- Parameters
id (int) – Numerical ID of the block.
opt_loop (OptimisationLoop) – Loop to which the block belongs.
- property current_iteration
Get current active iteration.
- property fun_value
Functional value for this block across all iterations.
- iterations(num, *iters, restart=None, restart_id=- 1)[source]
Generator of iterations.
- Parameters
num (int) – Number of iterations to generate.
iters (tuple, optional) – Any other iterables to zip with the iterations.
restart (int or bool, optional) – Whether or not attempt to restart the loop from a previous iteration. Defaults to the value given to the loop.
restart_id (int, optional) – If an integer greater than zero, it will restart from a specific iteration. Otherwise, it will restart from the latest available iteration.
- Returns
Iteration iterables.
- Return type
iterable
- property num_iterations
Number of iterations in the block.
- class stride.optimisation.optimisation_loop.Iteration(id, abs_id, block, opt_loop)[source]
Bases:
object
Objects of this class contain information about the iteration, such as the value of the functional.
- Parameters
id (int) – Numerical ID of the iteration.
abs_id (int) – Numerical ID of the iteration in absolute, global terms.
block (Block) – Block to which the iteration belongs.
opt_loop (OptimisationLoop) – Loop to which the iteration belongs.
- add_fun(fun)[source]
Add a functional value for a particular shot to the iteration.
- Parameters
fun (FunctionalValue) –
- add_step_fun(fun)[source]
Add a functional value, after step, for a particular shot to the iteration.
- Parameters
fun (FunctionalValue) –
- property fun_value
Functional value for this iteration across all shots.
- property step_fun_value
Functional value for this iteration across all shots after step.