model.built() memory leak
Building a model seems to leak memory. Here is a short script mem-benchmark.py
to reproduce it.
import finesse
import gc
code_cav = """
l L0 P=1
s dd L0.p1 ITMX.p1
m ITMX T=0.014 L=0 Rc=[-1934, -1934]
s LX ITMX.p2 ETMX.p1 L=3994
m ETMX T=5e-6 L=0 Rc=[2245, 2245]
cav arm ITMX.p2
noxaxis()
"""
kat = finesse.Model()
kat.parse(code_cav)
@profile
def profile_this():
print(1)
kat.modes(maxtem=29)
with kat.built() as sim:
pass
gc.collect()
print(2)
kat.modes(maxtem=30)
with kat.built() as sim:
pass
gc.collect()
print(3)
kat.modes(maxtem=31)
with kat.built() as sim:
pass
gc.collect()
print(4)
kat.modes(maxtem=28)
with kat.built() as sim:
pass
gc.collect()
print(5)
kat.modes(maxtem=32)
with kat.built() as sim:
pass
gc.collect()
if __name__ == '__main__':
profile_this()
The following code can then be profiled with memory_profiler
by running python -m memory_profiler mem-benchmark.py
which on my machine results in
This leak doesn't seem to affect model.run()
since replacing all the kat.built()
with kat.run()
gives the following profile