Skip to content
Snippets Groups Projects
Commit 2b53d51e authored by Martin Lange's avatar Martin Lange
Browse files

add profiling and benchmarks for runs with numpy arrays

parent 0d771720
No related branches found
No related tags found
1 merge request!222Xarray optimizations
Pipeline #133133 passed with stages
in 7 minutes and 4 seconds
"""Simple coupling setup for profiling, using numpy arrays.
Two components, coupled via a single link.
Simulation runs for 1 year with a daily step in both components.
Components exchange a 128x64 uniform grid.
"""
import datetime as dt
import finam as fm
def run_model():
start_time = dt.datetime(2000, 1, 1)
end_time = dt.datetime(2000, 12, 31)
counter = 0
size = (128, 64)
info1 = fm.Info(time=None, grid=fm.UniformGrid(size), units="m")
info2 = fm.Info(time=None, grid=fm.UniformGrid(size), units="m")
data = [
fm.data.strip_data(fm.data.full(0.0, "input", info1, start_time)),
fm.data.strip_data(fm.data.full(0.0, "input", info1, start_time)),
]
def gen_data(t):
nonlocal counter
d = data[counter % 2]
counter += 1
return d
source = fm.modules.CallbackGenerator(
callbacks={"Out": (gen_data, info1.copy())},
start=start_time,
step=dt.timedelta(days=1),
)
sink = fm.modules.DebugConsumer(
inputs={
"In": info2.copy(),
},
start=start_time,
step=dt.timedelta(days=1),
)
composition = fm.Composition([source, sink])
composition.initialize()
source["Out"] >> sink["In"]
composition.run(end_time=end_time)
if __name__ == "__main__":
for i in range(10):
run_model()
......@@ -135,3 +135,54 @@ class TestSimpleRunUnits(SimpleRunBase):
@pytest.mark.benchmark(group="run-sim")
def test_run_units_08_2048x1024(self):
self.run_test(2048, 1024)
class TestSimpleRunNumpy(SimpleRunBase):
@pytest.fixture(autouse=True)
def setupBenchmark(self, benchmark):
self.setup(benchmark)
def setup_data(self, size):
self.info1 = fm.Info(time=None, grid=fm.UniformGrid(size), units="m")
self.info2 = fm.Info(time=None, grid=fm.UniformGrid(size), units="m")
self.data = [
fm.data.strip_data(fm.data.full(0.0, "input", self.info1, self.start_time)),
fm.data.strip_data(fm.data.full(0.0, "input", self.info1, self.start_time)),
]
def gen_data(self, t):
d = self.data[self.counter % 2]
self.counter += 1
return d
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_01_2x1(self):
self.run_test(2, 1)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_02_32x16(self):
self.run_test(32, 16)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_03_64x32(self):
self.run_test(64, 32)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_04_128x64(self):
self.run_test(128, 64)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_05_256x128(self):
self.run_test(256, 128)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_06_512x256(self):
self.run_test(512, 256)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_07_1024x512(self):
self.run_test(1024, 512)
@pytest.mark.benchmark(group="run-sim")
def test_run_numpy_08_2048x1024(self):
self.run_test(2048, 1024)
#!/bin/bash
echo Profiling...
mkdir -p prof
python -m cProfile -o prof/simple_run.pstats benchmarks/profiling/simple_run.py
gprof2dot --colour-nodes-by-selftime -f pstats prof/simple_run.pstats > prof/simple_run.dot
dot -Tsvg -o prof/simple_run.svg prof/simple_run.dot
dot -Tpng -o prof/simple_run.png prof/simple_run.dot
for filename in benchmarks/profiling/*.py; do
fn=$(basename -- "$filename")
fn="${fn%.*}"
echo "$fn"
python -m cProfile -o prof/"$fn".pstats benchmarks/profiling/"$fn".py
gprof2dot --colour-nodes-by-selftime -f pstats prof/"$fn".pstats > prof/"$fn".dot
dot -Tsvg -o prof/"$fn".svg prof/"$fn".dot
dot -Tpng -o prof/"$fn".png prof/"$fn".dot
done
python benchmarks/pstats_to_csv.py
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment