gnrs.parallel

This module provides parallel processing utilities for Genarris.

This source code is licensed under the BSD-3 license found in the LICENSE file in the root directory of this source tree.

gnrs.parallel.init_parallel(comm_in, seed=42)[source]

Initialize parallel environment with MPI communicator.

Parameters:
  • comm_in (mpi4py.MPI.Comm) – MPI communicator object

  • seed (int) – Random seed

Return type:

None


gnrs.parallel.structs

This module contains the DistributedStructs class, which is used to handle distributed structure dictionaries.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

class gnrs.parallel.structs.DistributedStructs[source]

Bases: object

Contains functions for handling distributed structure dictionaries.

Initialize with a dictionary of structures.

Parameters:

structs – Dictionary mapping structure names to ASE Atoms objects

Raises:

ValueError – If structs is not a dictionary

__init__(structs)[source]

Initialize with a dictionary of structures.

Parameters:

structs (dict) – Dictionary mapping structure names to ASE Atoms objects

Raises:

ValueError – If structs is not a dictionary

get_num_structs()[source]

Get the total number of structures in a distributed structures dictionary.

Returns:

Total number of structures across all ranks

Return type:

int

find_matches(target, settings=None)[source]

Runs pymatgen duplicate checks on a distributed struct dictionary.

Parameters:
  • target (ase.atoms.Atoms) – Target structure to be matched

  • settings (dict | None) – Settings for pymatgen StructureMatcher

Returns:

List of matching structure IDs

Return type:

list

collect_property(prpty, ptype='info')[source]

Collects the property of all the structures into a list.

Parameters:
  • prpty (str) – Property name to collect

  • ptype (str) – Property type, either ‘info’ or ‘method’

Returns:

List of property values on master rank, None on other ranks

Return type:

list

get_statistics(prpty, ptype='info')[source]

Gets the statistics on a property of interest.

Parameters:
  • prpty (str) – Property name to analyze

  • ptype (str) – Get property from either ‘info’ or ‘method’

Returns:

Dictionary with statistics on master rank, None on other ranks

Return type:

dict

find_spg(tol=0.001)[source]

Finds the space group of all structures. Space group number is stored in info[“spg”]

Parameters:

tol (float) – Tolerance for symmetry finding

Return type:

None

property done: set[str]

Names of the structures already completed by the current task, i.e. restored from a checkpoint or checkpointed on this rank.

checkpoint_save(path, name, xtal)[source]

Appends one completed structure to this rank’s checkpoint log. Does not communicate, so ranks can call it independently.

The structure is written as one line in the same form used inside structures.json (see gnrs.parallel.io.encode_struct). A job killed mid-write can therefore damage only the last line.

Parameters:
  • path (str) – Directory for this rank’s checkpoint log

  • name (str) – Structure ID

  • xtal (ase.atoms.Atoms) – The completed structure. Need not belong to this rank’s pool, e.g. in serial DFT mode rank 0 computes copies of every rank’s structures.

Return type:

None

static checkpoint_clear(path)[source]

Removes checkpoint files left under a task’s calc directory. Call on one rank only; does not communicate.

Parameters:

path (str) – Directory containing rank_* checkpoint folders

Returns:

Number of files removed.

Return type:

int

checkpoint_load(path)[source]

Merges checkpoints of an interrupted run into the current structures and spreads the remaining work evenly across ranks. Unlike save, load is a collective and blocking operation.

A checkpointed copy replaces the current copy of the same structure and is marked as done (see done); structures that were never checkpointed (e.g. held by a rank that was killed before it finished its first calculation) are kept as they are. Checkpointed structures that are not in the current pool are ignored. Damaged lines and unreadable files are skipped with a warning; the affected structures are simply recomputed.

Parameters:

path (str) – Directory containing rank_* checkpoint folders

Returns:

Number of distinct structures restored from checkpoints.

Return type:

int

redistribute()[source]

Redistribute structures such that all ranks have almost equal number of structures. Helpful for balancing load across cores

Return type:

None

gnrs.parallel.io

This module provides functionality for reading and writing parallel data.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

gnrs.parallel.io.read_geometry_out(file_path)[source]

Master process reads geometry file and scatters data to other processes.

Parameters:

file_path (str) – Path to the geometry output file

Returns:

Dictionary mapping random IDs to Atoms objects

Return type:

dict

gnrs.parallel.io.str2atoms(geometry_str)[source]

Constructs Atoms object from aims geometry format.

Parameters:
  • geometry_string – List of strings containing geometry data

  • geometry_str (list)

Returns:

ASE Atoms object representing the crystal structure

Return type:

Atoms | None

gnrs.parallel.io.encode_struct(name, xtal)[source]

Serialize one structure as a line of a structures.json file.

Parameters:
  • name (str) – Structure ID

  • xtal (ase.Atoms) – Structure

Returns:

"name": <ase json>, followed by a newline

Return type:

str

gnrs.parallel.io.decode_struct(line)[source]

Parse a line written by encode_struct.

Parameters:

line (str) – One structure line, with or without the trailing comma

Returns:

Structure ID and structure

Return type:

tuple[str, ase.Atoms]

gnrs.parallel.io.write_parallel(file_path, struct_dict, gather=True, mode='w')[source]

Convert structures to JSON strings, gather and store to file.

Parameters:
  • file_path (str) – Path to output file

  • struct_dict (dict) – Dictionary of structures to write

  • gather (bool) – Whether to gather data from all processes

  • mode (str) – File opening mode

Return type:

None

gnrs.parallel.io.read_parallel(file_path, scatter=True)[source]

Reads JSON database of structures.

Parameters:
  • file_path (str) – Path to JSON file

  • scatter (bool) – Whether to scatter data to all processes

Returns:

Dictionary mapping IDs to Atoms objects

Return type:

dict