Add auto parallelization - #356
Draft
max-models wants to merge 14 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces experimental empirical autotuning utilities to help Struphy choose faster parallelization and particle-sorting configurations by timing short workload segments, and wires per-species sorting frequencies into the main simulation loop.
Changes:
- Add
struphy.topologyautotuning utilities for integer parameters (including sorting frequency) and for MPI domain-decomposition + clone-count selection. - Update
Simulation.run()to support per-particle sorting frequencies (withEnvironmentOptions.sort_stepas an override). - Add unit tests and profiling benchmark scripts/examples to exercise and measure the new tuning helpers.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/struphy/topology/tests/test_sorting_frequency.py | Adds a unit test for empirical sorting-frequency selection. |
| src/struphy/topology/tests/test_domain_decomposition.py | Adds unit tests for mask generation and decomposition/clone optimization. |
| src/struphy/topology/tests/init.py | Declares the topology test package. |
| src/struphy/topology/domain_decomposition.py | New helpers to enumerate and empirically optimize mpi_dims_mask and clone/decomposition combos. |
| src/struphy/topology/autotuning.py | New generic integer-parameter optimizer and ternary-search helper (used for sorting frequency). |
| src/struphy/topology/init.py | Exposes the new topology autotuning API via package exports. |
| src/struphy/simulation/sim.py | Changes particle-sorting logic to support per-particle sorting frequencies and override behavior. |
| profiling/submit_vlasov_sorting_frequency.py | Adds a launcher for the Vlasov sorting-frequency benchmark workflow. |
| profiling/submit_domain_decomposition.py | Adds a launcher for the anisotropic domain-decomposition benchmark workflow. |
| profiling/examples/Vlasov/clone_decomposition/benchmark_vlasov_clones.py | Adds a benchmark comparing clone/decomposition configurations and then tunes sorting frequency. |
| profiling/examples/ToyGyrokinetic/diocotron_instability/benchmark_domain_decomposition.py | Adds a benchmark comparing mpi_dims_mask choices for an anisotropic ToyDrift case. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+771
to
+778
| for val in particle_objects: | ||
| # An explicit EnvironmentOptions.sort_step overrides the | ||
| # per-particle SortingParameters frequency. Otherwise, | ||
| # honor the frequency configured for this particle species. | ||
| frequency = self.env.sort_step or val.sorting_params.sorting_frequency | ||
| if frequency and int(self.time_state["index"][0]) % frequency == 0: | ||
| particles_to_sort.append(val) | ||
| sort_functions.append(val.do_sort) |
Comment on lines
+128
to
+130
| timings = tuple(timings_by_value.values()) | ||
| best = min(timings, key=lambda timing: timing.seconds) | ||
| return ParameterOptimization(best_value=best.value, timings=timings) |
Comment on lines
+176
to
+179
| mask_pattern | ||
| Optional per-direction constraint. Use ``True`` or ``False`` to fix a | ||
| direction and ``"auto"`` to let the optimizer vary it, e.g. | ||
| ``(True, "auto", "auto")``. |
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.
Usually, it seems like using
(True, True, True)is the most efficient domain decomposition. But sometimes it isn't, for example when the number of elements in some direction is small. With this PR, I am trying out some automatic parallelization strategies. It's still a bit experimental.The main idea is to run 1 timestep (or a few timesteps?) with a specific configuration, time it, then compare it to other configurations.
What could be automatically chosen?