Skip to content

Cluster_setup

Overview

The cluster_setup model defines how a computing cluster is configured for automated workflows. It encapsulates detail required for remote job execution, including project identifiers, executable commands, execution environment, and computational resource definitions. It supports flexible configuration through dictionaries or structured modes, allowing compatibility with external libraries such as jobflow_remote and qtoolkit.

from DeWorks.clusters import cluster_setup

Attributes

Field Type Description
project str Name of the project used to group and identify related jobs.
Defaults to "automation".
exec_config dict |ExecutionConfig |None Defines remote job execution setup. Accepts either a raw dictionary or a structured ExecutionConfig object.
resources dict |slurm_resource |None Specifies computational resource. Automatically converted to internal model compatible with qtoolkit
vasp_cmd str | Callable[[int], str] |None Specifies the command used to launch VASP. Can be a plain string or a lambda-style function depending on the number of tasks.
Defaults to "vasp_std"
vasp_gamma str | Callable[[int], str] |None Optional. Alternate command for gamma-point-only calculations
Defaults to "vasp_gam"
vasp_par dict |None Optional. Parallelised version of the VASP
saved_json str |None Optional. Stores path to a saved JSON file representing the configuration

Validation

check_resources(cls, resources)

Checks if the resources parsed have the correct format. Validation is performed directly by pydantic, with the definition given in HECAS.Schema.slurm_resource

cluster = cluster_setup(resources={"ntask":16})
cluster.check_resources()
# Validates presence of expected resource fields

check_exec_config(cls, exec_config)

Ensures that exec_config is properly configured. Raises an error if essential fields such as host, user, or remote_dir are not set.

cluster = cluster_setup(exec_config={"host":"user_cluster", "user": "user1", "remote_dir": "/jobs"})
#Validates essential execution configuration structure

Serialization/De-Serialization

write_vasp_cmd(self)

Constructs and returns the command string for launching VASP, substituting values like {ntask} as needed. Typically used internally, but can be accessed directly.

cluster = cluster_setup(vasp_cmd="mpirun -np {ntask} vasp_std", resources={"ntask": 24})
command = cluster.write_vasp_cmd()
#Returns: 'mpirun -np 24 vasp_std'

to_json(self, dir: str = ".", name: str = "cluster_SETUP"):

Saves the cluster configuration as a JSON file to the specified path. dir: str and name: str defaults to current working directory and "cluster_SETUP", respectively

cluster.to_json("cluster_config.json")

from_json(cls, path: str)

Loads a cluster_setup object from a JSON file

cluster = cluster_setup.from_json("cluster_config.json")