xnn.common.deploy.domain.DomainParallel#
- class xnn.common.deploy.domain.DomainParallel(model, grid=None, receptive_field=None, compute_stress=True, group=None, halo='auto', skin=0.0)[source]#
Bases:
ModuleEvaluate one structure split over the processes of a distributed launch.
Each process evaluates only its sub-domain and a shell of ghost atoms, so the memory per process falls with the number of processes, and the results equal a single-process evaluation to rounding. The model runs as it would on one device, fast paths included. Evaluation only: no second derivatives. Every method is collective: all processes call it together.
- Parameters:
model (torch.nn.Module) – The potential (an
InteratomicPotential, or aForceStressOutputaround one). Its energy must be local: it needs areceptive_field()(models with long-range terms have none), unlessreceptive_fieldis given.grid (sequence of int, optional) – Sub-domains along the three lattice vectors (Cartesian axes for a molecule), with product equal to the number of processes. By default the grid with the fewest ghosts (
choose_grid()).receptive_field (float, optional) – Distance in Angstrom beyond which atoms no longer change an atom’s energy, by default the model’s
receptive_field().compute_stress (bool, optional) – Whether to compute the stress of a periodic structure, by default
True.group (torch.distributed.ProcessGroup, optional) – The processes that share the structure, by default all of them.
halo ({"auto", "layer", "field"}, optional) – The ghost shell: one cutoff, with the ghosts’ features refreshed before every layer (
"layer", for models that setrefreshes_ghosts), or the whole receptive field ("field")."auto"(default) takes"layer"when the model supports it.skin (float, optional) – Thickness in Angstrom added to the ghost shell and the neighbor list, so that a plan holds while the atoms move, by default 0 (a plan holds for the positions it was built from only).
- Raises:
ValueError – For a model without a receptive field, an unknown
halo,"layer"for a model that does not refresh its ghosts, or a negativeskin.
- plan(data)[source]#
Partition the structure and build this process’s ghosts and neighbor list.
- Parameters:
data (AtomicGraph) – One structure, periodic along all three axes or along none, the same on every process.
- Returns:
The plan of this process.
- Return type:
- Raises:
ValueError – For a batch of several structures, a partially periodic structure or a grid that does not match the number of processes.
- holds(plan, pos, cell=None)[source]#
Whether the plan still holds for new positions and cell.
It holds while
need + 2 d <= (1 - e) (need + skin), withdthe largest displacement of an atom since the plan was built andethe largest relative change of a distance through the deformation of the cell.- Parameters:
pos (Tensor) – Positions of the owned atoms
(n_owned, 3), wrapped into the cell or not.cell (Tensor, optional) – The cell
(3, 3), by default the plan’s.plan (DomainPlan)
- Returns:
The same on every process.
- Return type:
- reshard(plan, pos, *fields, cell=None)[source]#
A new plan for the current positions, with the per-atom rows moved to their new owners.
- Parameters:
plan (DomainPlan) – The plan the rows belong to.
pos (Tensor) – Positions of the owned atoms
(n_owned, 3).*fields (Tensor) – Other rows of the owned atoms (velocities, masses, …),
(n_owned, ...).cell (Tensor, optional) – The cell
(3, 3), by default the plan’s.
- Returns:
The new plan, then
posand every field for the atoms it owns.- Return type:
- evaluate(plan, pos, cell=None)[source]#
Energy, forces of the owned atoms and stress.
- Parameters:
plan (DomainPlan) – This process’s plan, valid for the positions (
holds()).pos (Tensor) – Positions of the owned atoms
(n_owned, 3), wrapped into the cell or not.cell (Tensor, optional) – The cell
(3, 3), by default the plan’s.
- Returns:
"energy"(1,)float64 (the whole structure),"forces"(n_owned, 3)in the dtype of the positions and, for a periodic structure withcompute_stress,"stress"(1, 3, 3).- Return type:
dict of str to Tensor
- forward(data)[source]#
Energy, forces and stress of the whole structure, given on every process.
The plan of the previous call is reused while it holds (
holds()).- Parameters:
data (AtomicGraph) – One structure, the same on every process.
- Returns:
"energy"(1,)float64,"forces"(N, 3)in the dtype of the positions and, for a periodic structure withcompute_stress,"stress"(1, 3, 3).- Return type:
dict of str to Tensor