finesse.utilities.misc.changed_params¶
- finesse.utilities.misc.changed_params(subs: dict)[source]¶
Temporarily change model parameters within a context.
This is a convenience function for providing a pattern of changing parameters temporarily, inside a context, without needing to make deep-copies of a
Model
. Usage of this function should be confined towith
contexts.- Parameters
subs : dict
Dictionary of temporary parameter subsitutions. Expects a dict of
Parameter
to float value mappings.
Examples
In this example a simple Fabry-Perot cavity is created and this function is used to inspect how some cavity properties vary when temporarily changing parameters.
import finesse import finesse.components as components from finesse.utilities import changed_params IFO = finesse.Model() IFO.chain( components.Laser("L0"), components.Mirror("ITM", Rc=-10), components.Space("CAV", L=1), components.Mirror("ETM", Rc=10), ) IFO.add(components.Cavity("FP", IFO.ITM.p2)) print(f"Initial FP.g = {IFO.FP.g}") print(f"Initial FP.gouy = {IFO.FP.gouy}\n") # Temporarily change ITM.Rcx to -15 m and ETM.Rcy to 9 m with changed_params({IFO.ITM.Rcx: -15, IFO.ETM.Rcy: 9}): print(f"Temporary FP.g = {IFO.FP.g}") print(f"Temporary FP.gouy = {IFO.FP.gouy}\n") # Check that params have been reset by looking at cavity again print(f"Final FP.g = {IFO.FP.g}") print(f"Final FP.gouy = {IFO.FP.gouy}")
Initial FP.g = [0.81 0.81] Initial FP.gouy = [51.68386553 51.68386553] Temporary FP.g = [0.84 0.8 ] Temporary FP.gouy = [47.15635696 53.13010235] Final FP.g = [0.81 0.81] Final FP.gouy = [51.68386553 51.68386553]