Skip to content

Commit 6a71451

Browse files
committed
need to fix seeding rng issue for multiprocessing. refactored numba class->we get double speed overall for the hpc script. Ran unit tests for optimizations and numba methods. Need to add a pp_analysis.py unit test module as well after fixing the seeding issue
1 parent a3d3c72 commit 6a71451

12 files changed

Lines changed: 1662 additions & 2171 deletions

docs/kimon_prompts.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,24 @@
4646

4747
---
4848

49-
### Script Optimization\
50-
49+
### Script Optimization
5150

5251
1. I am considering using numba for optimization and faster runs in the HPC. Outline an implementation plan, practical considerations, and feasibility within a logical timeframe.
5352

54-
2. Walk me through modifying tg
53+
2. Walk me through modifying the update_async method for simulation speedup
54+
55+
3. Provide me with a script using cProfile to profile the analysis script and target optimization goals specifically.
56+
57+
4. Write a small benchmark script for a large simulation to test how much the performance using numba has imrpoved (or no)
58+
59+
5. Identify the major bottlenecks in the script and suggest possible (realisic) fixes. if you lie about performance improvement expecatations, you will be replaced.
60+
61+
6. I am currently storing anslysis data in a .json file. Help me refactor the 2D sweep function to store binary data instead to minimize communication overhead.
62+
63+
7. The PCF is O(N^2). Show me how to use cell lists instead and spatial hashing. This is the biggest bottlneck so we must prioritize this. Walk me through reftorings in numba_optimized.py
64+
65+
8. We should also pre-allocate the buffers outside the kernel. Right now we are allocating memoery on every call.
66+
67+
9. Help me write a benchmark script to test the updated version against a non-numba optimized version. Create a summary txt with benchmark results.
68+
69+
10. Create unit tests for pp_analysis and numba_optimized files. Test all methods and make sure the scripts are HPC ready. Provide me with an outline of tests.

docs/prompts.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,5 +690,3 @@ Lastly, add functionality to stop evolution after a certain time-step. This shou
690690
6. Create a time series analysis plot of the evolution of prey and predator density vs. time. Make sure enough time steps all visible to see how the system eventually stabilizes.
691691

692692
7. Create a bifuracation diagram to confirm the monotonic relationship for a varying prey death rate vs. equilibrium density.
693-
694-
###

models/CA.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010
import logging
11-
from scripts.numba_optimized import _pp_async_kernel
11+
from scripts.numba_optimized import PPKernel
1212
from numba import njit
1313

1414
# Module logger
@@ -891,6 +891,8 @@ def __init__(
891891
if seed is not None:
892892
# This sets the seed for all @njit functions globally
893893
set_numba_seed(seed)
894+
895+
self._kernel = PPKernel(rows, cols, neighborhood)
894896

895897

896898
# Remove PP-specific evolve wrapper; use CA.evolve with optional species
@@ -1175,30 +1177,26 @@ def _process_reproduction(sources, birth_param_key, birth_prob, target_state_req
11751177
_process_reproduction(pred_sources, "predator_birth", self.params["predator_birth"], 1, 2)
11761178

11771179
def update_async(self) -> None:
1178-
dr_arr, dc_arr, _ = self._neighbor_shifts()
1179-
11801180
# Get the evolved prey death map
11811181
# Fallback to a full array of the global param if it doesn't exist yet
11821182
p_death_arr = self.cell_params.get("prey_death")
11831183
if p_death_arr is None:
1184-
p_death_arr = np.full(self.grid.shape, self.params["prey_death"])
1184+
p_death_arr = np.full(self.grid.shape, self.params["prey_death"], dtype=np.float64)
11851185

11861186
meta = self._evolve_info.get("prey_death", {"sd": 0.05, "min": 0.001, "max": 0.1})
11871187

1188-
# Call the JIT kernel
1189-
self.grid = _pp_async_kernel(
1188+
# Call the optimized kernel (uses pre-allocated buffers)
1189+
self._kernel.update(
11901190
self.grid,
11911191
p_death_arr,
11921192
float(self.params["prey_birth"]),
11931193
float(self.params["prey_death"]),
11941194
float(self.params["predator_birth"]),
11951195
float(self.params["predator_death"]),
1196-
dr_arr.astype(np.int32),
1197-
dc_arr.astype(np.int32),
11981196
float(meta["sd"]),
11991197
float(meta["min"]),
12001198
float(meta["max"]),
1201-
self._evolution_stopped
1199+
self._evolution_stopped,
12021200
)
12031201

12041202
def update(self) -> None:

scripts/__jnit__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .numba_optimized import *

scripts/benchmark_numba.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

scripts/local_run.py

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)