-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Alternative interface to produce many events with varying initial states #188
Comments
Cool. We also have a similar use case in a hybrid air shower Monte Carlo. @jncots has spent some time studying the performance profile of chromo in this type of application and may have some educated comments on this. |
Oh that would be very useful, because my judgement is based on conjecture. |
The problem with performance, as @HDembinski noticed, occurs at initiating and copy of Another alternative to Actually, as it is seen from 2nd figure in #180, adding beam particles to the stack in Python takes a lot of time. It is a serious problem in terms of performance. It could be fixed by writing C++/Fortran code that deals with the task. |
I think there is a misunderstanding here. You don't need awkward arrays for the input side, but for the output side. Because the output is not a single event now, but multiple events concatenated. The awkward arrays make that concatenation efficient (concatenating numpy arrays would be slow). |
Implementing stuff in C++ or Fortran should be our last option always, because that is a serious maintenance overhead.
I already said when we implemented that feature that it would be more efficient to generate all beam configurations first, then sort them, so that identical beam configurations are consecutive. With such a sorted input stack, one has to switch initial state in the generator much less frequently. This not only helps us on the Python side, but also helps the model to minimize the cost from switching beam configurations. For some models, doing that is costly. |
This is an idea that arose out of a lunch discussion with @mohller today, who is using Chromo in CRPROPA, and from the discussion around #174, and it is also related to #65
The current Chromo API is designed around the use-case where you generate lots of a events with a fixed inital state (same particles at same ecm). However, there are also use cases where the initial state varies a lot, for example, when you simulate interactions in an air shower:
Running Chromo in this use-case is still efficient if the time spend in the model the generate and process one event (B, C) is large compared to the setup time of the model (A). This likely won't be the case, however, if
beam_energy
is small.We could technically speed up Chromo for this use-case with an alternative API that pushes this for loop into C or Fortran. It is not a simple change, but it is technically possible.
The call would then look like this:
where some_state_stack is a numpy array representating a table with the input state beam_energy, pid1, pid2 (we could add a flag to also support inputs in the center-of-mass frame), and events is a awkward array that contains the event data for each input state. We need the awkward array data structure here because we have a variable number of outgoing particles per input particle and we want to keep the association between input and output particles. Awkward arrays are able to represent such a mapping, while normal numpy arrays cannot.
The potential speed-up here is two-fold.
CC @jpivarski
The text was updated successfully, but these errors were encountered: