Skip to content

Commit

Permalink
Add scaling notebook
Browse files Browse the repository at this point in the history
# Conflicts:
#	profiling/timing.py
  • Loading branch information
rafmudaf committed Sep 11, 2023
1 parent 047c534 commit 411c20b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
56 changes: 56 additions & 0 deletions profiling/profiling_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import copy
import time
import numpy as np
import memory_profiler
from floris.simulation import Floris


def run_floris(input_dict: dict) -> float:

# Deep copy the input dictionary to ensure no side effects
input_dict = copy.deepcopy(input_dict)

# Start timing
start = time.perf_counter()

# Run floris calculation
floris = Floris.from_dict(input_dict)
floris.initialize_domain()
floris.steady_state_atmospheric_condition()

# Stop timing
end = time.perf_counter()

return end - start


def time_profile(input_dict, N_ITERATIONS=30) -> float:
"""
Runs the wake calculation for N_ITERATIONS and returns
the average of the timing results.
An initial iteration of the calculation is run and not included in the
timing results in order to allow Python to compile what it needs to and
initialize the computer's memory.
"""

# Run once to initialize Python and memory
run_floris(input_dict)

# Get timing for each iteration
times = np.zeros(N_ITERATIONS)
for i in range(N_ITERATIONS):
times[i] = run_floris(input_dict)

# Return the average
return np.mean(times)


def memory_profile(input_dict):
floris = Floris.from_dict(copy.deepcopy(input_dict["floris"]))
floris.initialize_domain() # TODO: include this in memory_usage()?
mem_usage = memory_profiler.memory_usage(
(floris.steady_state_atmospheric_condition, (), {}),
max_usage=True
)
return mem_usage
8 changes: 6 additions & 2 deletions profiling/timing.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@

import copy
import time

import matplotlib.pyplot as plt
import memory_profiler
import numpy as np
from conftest import SampleInputs

from floris.simulation import Floris
from runners import time_profile, memory_profile


def internal_probe(input_dict):
floris = Floris(input_dict=input_dict.floris)
internal_quantity = floris.steady_state_atmospheric_condition()
return internal_quantity


if __name__=="__main__":
sample_inputs = SampleInputs()
TURBINE_DIAMETER = sample_inputs.turbine["rotor_diameter"]
Expand Down
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ def __init__(self):
"kd": 0.05,
},
"empirical_gauss": {
"horizontal_deflection_gain_D": 3.0,
"vertical_deflection_gain_D": -1,
"deflection_rate": 15,
"mixing_gain_deflection": 0.0,
"yaw_added_mixing_gain": 0.0
"horizontal_deflection_gain_D": 3.0,
"vertical_deflection_gain_D": -1,
"deflection_rate": 15,
"mixing_gain_deflection": 0.0,
"yaw_added_mixing_gain": 0.0
},
},
"wake_velocity_parameters": {
Expand Down

0 comments on commit 411c20b

Please sign in to comment.