load_if_needed#
- FdtdSession.load_if_needed(filename: str) bool#
Load
filenameonly if it isn’t already the active project.Each call to
fdtd.load(...)costs roughly 700 ms because Lumerical has to deserialize the entire project. Within a single gradient evaluation the same forward .fsp is typically loaded 3-5 times (inset_adj,get_jacobian,get_fwd_fields,get_adjoint_fields, …) and the adjoint .fsp 1-2 times. This helper checks whether the requested file is already loaded with the same on-disk contents (compared by absolute path + mtime) and, if so, skips the actual load.Callers that mutate the in-memory state (
switchtolayout,set, geometry edits, …) must invalidate the cache afterwards viainvalidate_loaded_state()so subsequentload_if_neededcalls do a real load. Afterfdtd.save(filename)succeeds, the in-memory state matches the file just written, so callers can callmark_as_loaded()to update the cache and avoid a round-trip on the next read.