mappy_ds.continuation.continuation#

mappy_ds.continuation.continuation(fun, y0, params, param_key, end_value, *, resolution=100, show_progress=False, callback=None)#

Continue the solution of a step function along a parameter.

params[param_key] is swept linearly from its current value to end_value in resolution points, both ends included. At each point fun(y, params) is called, where y and params are those of the previous successful step (y0 and params at the first point) with params[param_key] set to the current value. The sweep stops at the first unsuccessful step.

Parameters:
funcallable

Step function fun(y, params) -> StepFunctionResult. It receives a dictionary it may modify freely.

y0T

Initial value of the continued variable.

paramsmapping

Initial parameters; it is copied and never modified.

param_keystr

Key of the parameter to continue.

end_valuefloat

Final value of params[param_key].

resolutionint, optional

Number of continuation points including both ends, by default 100. Must be at least 2.

show_progressbool, optional

Print one status line per successful step to standard error, by default False.

callbackcallable, optional

Called with each successful ContinuationStep as soon as it is found.

Returns:
list of ContinuationStep

The successful steps in order; shorter than resolution if a step failed.

Raises:
ValueError

If resolution is less than 2.

Examples

Follow the positive square root of p from p = 1 to p = 4:

>>> from mappy_ds.continuation import StepFunctionResult, continuation
>>> def step(y, p):
...     return StepFunctionResult(True, p["p"] ** 0.5)
>>> steps = continuation(step, 1.0, {"p": 1.0}, "p", 4.0, resolution=4)
>>> [(s.params["p"], s.y) for s in steps]
[(1.0, 1.0), (2.0, 1.4142135623730951), (3.0, 1.7320508075688772), (4.0, 2.0)]