finesse.model.Model.temporary_parameters¶
- Model.temporary_parameters(include=None, exclude=None)[source]¶
Context manager that lets user change any ModelParameter then return it to the original value once completed. When the Model is in this temporary state it cannot have any structural changes, such as adding or removing components.
There is also the ability to include or exclude certain parameters from reverting back to their previous values if needed.
- Parameters
- includeiterable or str, optional
Parameters that should be reverted once the context has exitted.
If a single string is given it can be a Unix file style wildcard (See
fnmatch
). A value of None means everything is included.If an iterable is provided it must be a list of names or Parameter objects.
- excludeiterable or str, optional
Parameters that should not be reverted once the context has exitted.
If a single string is given it can be a Unix file style wildcard (See
fnmatch
). A value of None means nothing is excluded.If an iterable is provided it must be a list of names or Parameter objects.
Examples
import finesse model = finesse.Model() model.parse(''' l l1 P=1 m m1 R=0.99 T=0.01 Rc=-1934 m m2 R=1 T=0 Rc=2245 m m3 R=1 T=0 Rc=10000 ''' ) with model.temporary_parameters(): model.m1.Rc = 100 print(model.m1.Rc) print(model.m1.Rc) # Only reset m2 parameters with model.temporary_parameters(include="m2.*"): ... # Only reset m2.phi and m1.phi parameters with model.temporary_parameters(include=("m2.phi", "m1.phi")): ... # Reset everything apart from all phi parameters with model.temporary_parameters(exclude="*.phi"): ... # Reset everything apart from all phi parameters with model.temporary_parameters(exclude="m[13].phi"): ...