[docs]defcache_s_matrix(start:_typ.Callable):"""Decorator that can be used in :func:`Model.start` to cache results."""@_func.wraps(start)def_start(model,component,frequencies,*args,**kwargs):# Global config must be part of the keycache_target=_ext.Component("",_ext.config.default_technology)cache_target.add_reference(component)cache_target.add_model(model,"")kwargs[""]=(tuple(frequencies),_ext.config.default_mesh_refinement,_ext.config.default_kwargs,*args,)cache_target.parametric_kwargs=kwargstry:key=cache_target.as_bytesexceptException:_warn.warn(f"Unable to cache results for component '{component.name}'.",RuntimeWarning,2)returnstart(model,component,frequencies,*args,**kwargs)result=_s_matrix_cache[key]ifresultisNone:result=start(model,component,frequencies,*args,**kwargs)_s_matrix_cache[key]=resultelifkwargs.get("verbose",False):print(f"Using cached result for {component}/{model}.")returnresultreturn_start
[docs]defclear_cache()->None:"""Clear the runtime caches, but not the file cache. The file cache is stored in :data:`photonforge.cache.path`. It can be cleared by simply deleting the contents in that directory. """forcin_all_caches:c.clear()
[docs]defcache_capacity(capacity:int)->None:"""Set the runtime cache capacity. Args: capacity: Set a new cache capacity. A negative value removes the capacity limit. """forcin_all_caches:c.capacity=capacity