zlatko-minev / pyEPR

Powerful, automated analysis and design of quantum microwave chips & devices [Energy-Participation Ratio and more]
https://pyepr-docs.readthedocs.io
Other
160 stars 219 forks source link

Cache calls to `calc_energy_electric` and `calc_energy_magnetic` #124

Open nikosavola opened 2 years ago

nikosavola commented 2 years ago

calc_energy_electric (and calc_energy_magnetic) are called in many places in DistributedAnalysis and currently you are supposed to transfer the result of these as a parameter like U_E and U_H to for example get_Qdielectric_all and get_Qseam_sweep.

It would make sense to instead just cache the values, as the inputs consist of simple strings, bools and ints. A simple lru_cache from the standard library almost works. I think this would fail only if the Ansys simulation is changed in a way that does not invalidate the simulation solution but would change the values of the computed fields. This might be a rare case, but still unwanted behaviour.

nikosavola commented 2 years ago

If someone knows of a way to hash current state of Ansys or somehow check if the simulations were edited, this should be easy.