Planet-Factory / legacy-claude

The CLAuDE model
https://planet-factory.github.io/claude-docs/
MIT License
167 stars 28 forks source link

[Another] Numba acceleration, replacing cython with automatic parallelism #20

Closed FractalMachinist closed 3 years ago

FractalMachinist commented 3 years ago

To address limited performance, two main changes:

1. Don't wait for the drawing to finish

Move the matplotlib drawing step to a separate thread. This is responsible for a very significant speedup, but increases complexity (more in Pros/Cons). The single largest contributor to the drawing step is the flow lines, which can't be accelerated without a very significant re-write of matplotlib. This does mean we can compute far more than one step per drawing, which invites higher-resolution models.

2. Let Numba manage parallelism

Instead of writing explicitly multi-threaded model evaluation, use the Numba compiler (getting rid of Cython) in ways that allow for automatically managed multi-core execution.

Pros:

  1. Automatic parallelism and optimization without asking for dual fluency in Python and Cython
  2. Significantly increased execution speed at every step
  3. Headroom for higher-resolution models

Cons:

  1. The matplotlib drawing thread.
    • All plotting data has to get explicitly passed through a multiprocessing Queue.
    • These changes are invisible unless the drawing system needs modified (EG it's build-and-forget).
  2. Any common multiprocessing library is going to require knowledge beyond base python, and while Numba is >95% original Python, it's still more complex than no multiprocessing.
arenmarsden commented 3 years ago

@FractalMachinist I'd remove commit 221c8d4

TargetPolymath commented 3 years ago

@arenmarsden Oops, you're absolutely right.

EDIT: I don't know how to edit this particular pull request in-place. I'll get the Doctor's attention during the stream if it comes up.

ATGSilva commented 3 years ago

Stale