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 toend_valueinresolutionpoints, both ends included. At each pointfun(y, params)is called, whereyandparamsare those of the previous successful step (y0andparamsat the first point) withparams[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 least2.- show_progressbool, optional
Print one status line per successful step to standard error, by default
False.- callbackcallable, optional
Called with each successful
ContinuationStepas soon as it is found.
- Returns:
- list of ContinuationStep
The successful steps in order; shorter than
resolutionif a step failed.
- Raises:
- ValueError
If
resolutionis less than2.
Examples
Follow the positive square root of
pfromp = 1top = 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)]