Conversation
…alled function to do the wrapping so I made a helper
…se to the orchestrator. Get the results back.
…for lins not some paths
… want to oversubscribe on cores
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a parallelisation strategy for the
harpyharmonic analysis.Let me preface this by saying: no code that does any of the calculations has been touched.
This is a long PR text, I'll try to split it.
Context
Currently, when performing harmonic analysis for the bunches in a file,
harpyruns the analysis serially, bunch after bunch. We have a wall time of ~25-30s for analysing a bunch so this scales roughly asn_bunches * 30 seconds.The operations within
harpy(SVD, some big dot products, FFTs) dispatch hungrily across all available threads viaBLAS.As it turns out for our operations this is not a great idea, and benchmarks show that limiting
BLASto a single thread gives similar results (slightly faster for SVD, slightly slower for dot product, all within 5-10% in any case). This is an opportunity.What is changed
The parallelisation strategy is changed. Instead of running bunch after bunch and letting
BLASeat up all threads unproductively, the following is done:harpyworkload of single bunches sets a hard cap forBLASto one (1) thread,Implementation
Most of the new code is in a new
omc3.harpy._parallelmodule, with heuristics to determine the number of workers to dispatch to. This is done based on estimated peak RSS for a given bunch (from the TbT data and from theharpyoptions), the detected number of available logical cores and RAM, and user input (more on that later).The main function in
harpynow calls this heuristic first then dispatches work. It performs the same thing as the current behaviour ifn_jobs=1, and starts aProcessPoolExecutorto parallelise across bunches ifn_jobs>1.A CLI flag
--n_jobsis provided to give the user (and GUI) control over this strategy. Providing0leads to automatic determination as described above. Giving1leads to serial processing, which is the current behaviour. ProvidingN>0uses uses up to N workers, still bounded by the automatic safety limits (available cores, number of bunches, and RAM budget): an explicitNcan only throttle the pool below the automatic choice, but never oversubscribe it.Some little things:
harpyI am reserving for another PR.threadpoolctlis added to the dependencies (was already a transitive dependency),psutilis added to the dependencies.Performance Gains
The theoretical gains, assuming we are not limited by the resources of the machine, is a factor of
n_bunchesat most. In practice there is some overhead due to the dispatch of jobs but it is small.Previously: a file with
n_buncheswould do one by one.Now: a file with
n_buncheswill start all simultaneously and be done in ~ the same time it takes to complete a single bunch's analysis.Tests
I have added unit tests for both the parallelisation heuristics, and for comparing serial results vs parallel workers results on the same inputs. The latter is done for lin files but also the
.amps[xy]and.freqs[xy]files from thefull_spectraoutput (as full_spectra is our default in the GUI).Field Tests
I have tested this in the CCC starting workloads from the GUI. Reproducing previous analyses leads to the exact same results, down to the optics analysis downstream.
See below for GUI + harpy parallelisation considerations when we are dealing with multiple files.
Wider parallelisation with GUI
There are two layers to the interplay here. This is assuming the default GUI setting of "Run Per-File Tasks in Parallel".
When selecting multiple files in the BPM panel and starting the
Analyse spectracommand, the GUI issues apython -m omc3.hole_in_one --harpy [...]command for each file, instantly. This is done viasshsubmission to the relevant optics server. What happens next is:n_bunches. ConsideringBLASmaxes out the threads on the server, with a lot of files (or the newer 5 bunches / beam measurements) this can lead to throttling and additional slowdown on top of the30s x n_bunches.~30sfor a given bunch's analysis.The general outcomes:
n_bunches x ~30s->~30s.~30severy time. This lets analysis stay on top of the measurements considering we can only get a kick every minute (currently, especially with the 5 bunches the analysis falls behind measurements quite quickly).Benchmarks from the CCC
The python edge environment is currently on this branch. I have reproduced some analyses from earlier in the year and compared the prod version's performance (current
omc3) to the edge version (this branch).All results down to the optics analysis are perfectly identical. Below are some screenshots of the performance gains, for the 5 bunches measurements.
Current omc3 version
Verdict: we now finish all much faster and close to the min wall time for one bunch analysis, and we utilise much less of the machine resources, which means we have room for a lot more parallelisation (more files, more bunches).
Notice also that the new
harpyis a little more talkative in the logs :)Results of the analyses are the exact same, see the final optics for instance:
For more benchmark details see the OMC logbook entries of today,
2026-07-03.