Skip to content

Add optional NumPy Bunch import/export and type stubs - #180

Draft
woodtp wants to merge 5 commits into
PyORBIT-Collaboration:mainfrom
woodtp:feature/bunch-numpy-interop-api-v2
Draft

woodtp wants to merge 5 commits into
PyORBIT-Collaboration:mainfrom
woodtp:feature/bunch-numpy-interop-api-v2

Conversation

@woodtp

@woodtp woodtp commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Reopening #119 to shrink the scope + some modifications. I still have the i/o attached to the Bunch class rather than separate utility functions, because I think this API is more cohesive when considered alongside the existing methods. For example, the bulk-append counterpart to addParticle(...) is addParticles(...). Additionally,addParticles will accept any numeric Python sequence as long as the shape conforms to (N, 6).

  • Add Bunch.addParticles(coordinates) to append local coordinates from arrays or nested sequences.
  • Add Bunch.coordinates() to export an independent, C-contiguous float64 snapshot.
  • Gate both methods behind USE_NUMPY, disabled by default.
  • Ship type stubs for all classes exported by orbit.core.bunch.
  • Enable NumPy support in multithreaded CI and document build configuration.

Coordinates use shape (N, 6) with columns (x, xp, y, yp, z, dE).
Export does not compress the bunch or filter deleted slots; callers should
compress first when appropriate.

Bunch I/O benchmark

Hardware: Apple M4 · 10 CPU cores · 16 GiB RAM

Times are mean ± sample standard deviation, in milliseconds, across five timed runs after one untimed warm-up.

Input

Particles Bunch.addParticle loop Bunch.addParticles
1K 0.429 ± 0.007 0.017 ± 0.001
10K 3.693 ± 0.030 0.145 ± 0.007
100K 38.744 ± 0.531 1.802 ± 0.147
1M 398.573 ± 5.075 22.277 ± 0.392
10M 4077.077 ± 38.409 268.436 ± 2.671

Output

Particles Scalar getters Bunch.coordinates, 1 thread 2 threads 4 threads
1K 0.299 ± 0.011 0.002 ± <0.001 0.007 ± 0.004 0.013 ± 0.003
10K 3.015 ± 0.010 0.012 ± 0.001 0.013 ± 0.002 0.022 ± 0.009
100K 30.801 ± 0.102 0.313 ± 0.020 0.260 ± 0.040 0.166 ± 0.018
1M 317.976 ± 2.594 4.064 ± 0.156 2.864 ± 0.101 2.112 ± 0.012
10M 3171.360 ± 16.146 35.585 ± 0.789 24.857 ± 3.228 17.888 ± 1.731
bunch_io

@woodtp woodtp self-assigned this Nov 20, 2026
@woodtp woodtp added the enhancement New feature or request label Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant