You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like there is a memory leak in the FlorisModel.run method i.e. if it is run multiple times sequentially, especially for a large number of wind speeds/directions, the total RAM usage increases steadily until the computer reaches its capacity, at which point most computers will issue a warning asking to shut down the process, and proceed to shut down if this is ignored.
Test with the memory_profiler tool, import the function decorator as :
frommemory_profilerimportprofile
and then add the @profile decorator before the header of memory intensive functions. e.g. in floris.floris_model
@profiledefrun(self) ->None:
...
For my use case, the memory leak traces were: FlorisModel.run->floris.core.steady_state_atmospheric_condition() -> floris.core.solver.sequential_solver -> model_manager.deflection_model.function, calculate_transverse_velocity, model_manager.velocity_model.function
My workaround was to run floris in a subprocess (see this stackoverflow thread) , which is guaranteed to reallocate memory upon completion:
# define in global scopedefrun_floris_proc(floris_env, turbine_powers_arr):
floris_env.run()
turbine_powers_arr=np.frombuffer(turbine_powers_arr, dtype=np.double, count=len(turbine_powers_arr))
turbine_powers_arr[:] =floris_env.get_turbine_powers().flatten()
...
# within loopturbine_powers_arr=RawArray('d', [0] *self.fi.env.core.flow_field.n_findex*self.n_turbines)
p=Process(target=run_floris_proc, args=(self.fi.env, self.turbine_powers_arr))
p.start()
p.join()
all_yawed_turbine_powers=np.frombuffer(self.turbine_powers_arr, dtype=np.double, count=len(self.turbine_powers_arr)).reshape((self.fi.env.core.flow_field.n_findex, self.n_turbines))
Another less reliable method is a combination of the del keyword and gc.collect() calls for redundant variables, but these do not guarantee memory deallocation if references still exist.
test_floris.py
importnumpyasnpfrommemory_profilerimportprofilefromflorisimportFlorisModel, TimeSeries@profiledefrun_floris():
# Load the Floris modelfmodel=FlorisModel("inputs/gch.yaml")
N=100000np.random.seed(0)
# Set up inflow wind conditionstime_series=TimeSeries(
wind_directions=270+30*np.random.randn(N),
wind_speeds=8+2*np.random.randn(N),
turbulence_intensities=0.06+0.02*np.random.randn(N),
)
# Set the wind conditions for the modelfmodel.set(wind_data=time_series)
# Run the calculationsfmodel.run()
fmodel.run()
# Extract turbine and farm powersturbine_powers=fmodel.get_turbine_powers() /1000.0farm_power=fmodel.get_farm_power() /1000.0print(turbine_powers.shape)
print(farm_power.shape)
if__name__=="__main__":
run_floris()
It looks like there is a memory leak in the
FlorisModel.run
method i.e. if it is run multiple times sequentially, especially for a large number of wind speeds/directions, the total RAM usage increases steadily until the computer reaches its capacity, at which point most computers will issue a warning asking to shut down the process, and proceed to shut down if this is ignored.Test with the memory_profiler tool, import the function decorator as :
and then add the
@profile
decorator before the header of memory intensive functions. e.g. infloris.floris_model
For my use case, the memory leak traces were:
FlorisModel.run
->floris.core.steady_state_atmospheric_condition()
->floris.core.solver.sequential_solver
->model_manager.deflection_model.function
,calculate_transverse_velocity
,model_manager.velocity_model.function
My workaround was to run floris in a subprocess (see this stackoverflow thread) , which is guaranteed to reallocate memory upon completion:
Another less reliable method is a combination of the
del
keyword andgc.collect()
calls for redundant variables, but these do not guarantee memory deallocation if references still exist.test_floris.py
The output of the memory profiling is:
And if the
run
method is called repeatedly, in a loop for example, it will continue to use more and more memory.The text was updated successfully, but these errors were encountered: