1414
1515
1616class ResourceDictValidation (BaseModel ):
17+ """
18+ Pydantic (or dataclass fallback) model for validating resource dictionaries passed to task submissions.
19+
20+ Attributes:
21+ cores (int, optional): Number of MPI cores to be used for each function call.
22+ threads_per_core (int, optional): Number of OpenMP threads to be used for each function call.
23+ gpus_per_core (int, optional): Number of GPUs per worker.
24+ cwd (str, optional): Current working directory where the parallel python task is executed.
25+ cache_key (str, optional): External cache key to identify tasks on the file system.
26+ cache_directory (str, optional): The directory to store cache files.
27+ num_nodes (int, optional): Number of compute nodes used for the evaluation.
28+ exclusive (bool, optional): Reserve exclusive access to selected compute nodes.
29+ error_log_file (str, optional): Path to the error log file.
30+ run_time_max (int, optional): Maximum allowed execution time in seconds.
31+ priority (int, optional): Queuing system priority for the task.
32+ slurm_cmd_args (list[str], optional): Additional command line arguments for the srun call.
33+ submission_template (str, optional): Template for queuing system job submission scripts.
34+ """
35+
1736 cores : Optional [int ] = None
1837 threads_per_core : Optional [int ] = None
1938 gpus_per_core : Optional [int ] = None
@@ -39,6 +58,18 @@ class Config:
3958
4059
4160def _get_accepted_keys (class_type ) -> list [str ]:
61+ """
62+ Return a list of accepted field names from a Pydantic model or dataclass.
63+
64+ Args:
65+ class_type: A Pydantic BaseModel subclass or a dataclass.
66+
67+ Returns:
68+ list[str]: Field names declared on the class.
69+
70+ Raises:
71+ TypeError: If the class type is neither a Pydantic model nor a dataclass.
72+ """
4273 if hasattr (class_type , "model_fields" ):
4374 return list (class_type .model_fields .keys ())
4475 elif hasattr (class_type , "__dataclass_fields__" ):
@@ -47,10 +78,32 @@ def _get_accepted_keys(class_type) -> list[str]:
4778
4879
4980def validate_resource_dict (resource_dict : dict ) -> None :
81+ """
82+ Validate a resource dictionary against the declared fields of ResourceDictValidation.
83+
84+ Args:
85+ resource_dict (dict): Dictionary of resource requirements to validate. Unknown keys raise
86+ a validation error when pydantic is available.
87+
88+ Raises:
89+ ValidationError: If any key/value pair violates the ResourceDictValidation schema.
90+ """
5091 _ = ResourceDictValidation (** resource_dict )
5192
5293
5394def validate_resource_dict_with_optional_keys (resource_dict : dict ) -> None :
95+ """
96+ Validate a resource dictionary, allowing unknown keys with a warning instead of an error.
97+
98+ Known keys are validated against ResourceDictValidation. Unknown keys are collected and
99+ emitted as a UserWarning so callers can detect unsupported options without hard failure.
100+
101+ Args:
102+ resource_dict (dict): Dictionary of resource requirements to validate.
103+
104+ Raises:
105+ ValidationError: If any known key/value pair violates the ResourceDictValidation schema.
106+ """
54107 accepted_keys = _get_accepted_keys (class_type = ResourceDictValidation )
55108 optional_lst = [key for key in resource_dict if key not in accepted_keys ]
56109 validate_dict = {
0 commit comments