CovertLab / wcEcoli

Whole Cell Model of E. coli
Other
18 stars 3 forks source link

Remove the Numba JIT-compilation code #1414

Closed 1fish2 closed 7 months ago

1fish2 commented 7 months ago

The JIT-compiled code time savings don't pay back the compilation time in Python 3.9+, so drop the library dependency. See #1400 and #1413, which improved the payback in some cases but not enough to matter to runSim.

See https://github.com/1fish2/numba-test and https://github.com/1fish2/numba-test/blob/main/observations.md for measurements of 4 matrices captured from a cell sim. Those matrices get evaluated about this many times in a typical cell generation:

Changes

Sidetrack

Cumulative string concatenation (see _matrix_to_array()) takes O(n^2) time, so standard practice is to accumulate a list then join it. In some programs n remains small enough to not matter although situations change and code gets reused. I'm either into standard practice, having fun with optimization, or thinking about Google code reviews where one would have to justify an n^2 algorithm.

Timing EQUILIBRIUM_RATES_JACOBIAN with ≈350 non-zero elements:

Those are shockingly close, and both are too small to matter to runSim.

Python guru Alex Martelli explains https://stackoverflow.com/a/1350289/1682419 that the CPython compiler optimizes a loop containing s += something if it detects the common case it can handle. The rationale is many Python programmers won't know to use join(), which makes sense. But the fragile optimization could be a trap. Alex recommends using join().

Still, I left _matrix_to_array() as is, but it does rely on a CPython-specific optimization.

1fish2 commented 7 months ago

@ggsun is Jenkins stuck?

rjuenemann commented 7 months ago

Just started another Jenkins task on Sherlock - hopefully that resolves it

1fish2 commented 7 months ago

That worked!