Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid-searching based tuning scheme #110

Open
GardevoirX opened this issue Nov 23, 2024 · 4 comments · May be fixed by #130
Open

Grid-searching based tuning scheme #110

GardevoirX opened this issue Nov 23, 2024 · 4 comments · May be fixed by #130

Comments

@GardevoirX
Copy link
Contributor

GardevoirX commented Nov 23, 2024

This is inspired by the ESPResSo tuning code. In their tuning code, they take the running time into account (which we have not yet). Their code combines grid-search (for the mesh density and the interpolation order) and handcraft (for the smearing and the real space cutoff) together. Basically, what they have done is:

  1. Search the mesh_density iteratively from small to large in a certain range (m_mesh_density_min, m_mesh_density_max) .
    https://github.com/espressomd/espresso/blob/a8a00a06e4eb8b0726a318739d069e379619e400/src/core/electrostatics/p3m.cpp#L715-L754
  2. In the iteration of 1, for each mesh_density, iterate cao (charge assignment order, our interpolation_nodes) from low to high. https://github.com/espressomd/espresso/blob/a8a00a06e4eb8b0726a318739d069e379619e400/src/core/p3m/TuningAlgorithm.cpp#L228-L326
  3. For each pair of (mesh_density, cao), bisectionly search r_cut_iL
    https://github.com/espressomd/espresso/blob/a8a00a06e4eb8b0726a318739d069e379619e400/src/core/p3m/TuningAlgorithm.cpp#L155-L168
    and calculate an alpha_L (our smearing) according to the real space error and the desired accuracy
    https://github.com/espressomd/espresso/blob/a8a00a06e4eb8b0726a318739d069e379619e400/src/core/electrostatics/p3m.cpp#L646-L655
  4. For each pair of (mesh_density, cao, r_cut_iL, alpha_L), initialize P3M, run the calculation and record the calculation time.
  5. Return a pair of parameters with the shortest calculation time and satisfying the accuracy requirement.

There are some complicated exit conditions for the loops in 1 and 2, in order to shrink the size of the search space. The methods in 3 look like heuristic, and perhaps we can replace them with gradient-based optimization. For our case, we can grid-search each possible (mesh_spacing, interpolation_nodes), and use Adam optimizer to get (smearing, rc_cutoff). And for each possible parameter, we can do the calculation, record the time, and finally return a parameter pair with the shortest time.

I have already tried this for PME and here is the result, but I forgot to record the calculation time. One other problem is that the tuning time is very long. It took the computer 76 min to get all the results below (7 * 8 = 56 cases, avg. 1.4 min/case), so we may introduce some rules to help reduce the scale of searching.
Image

@PicoCentauri
Copy link
Contributor

Did you mesh_density or the integer grid size. I think once could try to get some estimates for the maximal number of grid points.

76 minutes its a lot. But what would be the time for lets say one structure of around 1k atoms?

@GardevoirX
Copy link
Contributor Author

GardevoirX commented Nov 24, 2024

Did you mesh_density or the integer grid size.

I just checked their code, the density here is a line density of the mesh points, like the reciprocal of our mesh_spacing.

I think once could try to get some estimates for the maximal number of grid points.

In their code, they simply set it as maximally 512 grid points along one dimension.
https://github.com/espressomd/espresso/blob/a8a00a06e4eb8b0726a318739d069e379619e400/src/core/electrostatics/p3m.cpp#L684-L691

But what would be the time for lets say one structure of around 1k atoms?

For 1k atoms, to reach an accuracy of 1e-7, it costs ~1 min. I just made some optimization to it,

@PicoCentauri
Copy link
Contributor

Okay 512 sounds reasonable!

And 1 min is fine for the beginning. I assume on a CPU? We can try to optimize this further.

@GardevoirX
Copy link
Contributor Author

Yes on a CPU

@GardevoirX GardevoirX linked a pull request Dec 17, 2024 that will close this issue
4 tasks
@GardevoirX GardevoirX linked a pull request Dec 17, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants