Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eb889b1
[Fix] Validate resource_dict using pydantic
jan-janssen Feb 21, 2026
222b3d8
Format black
pyiron-runner Feb 21, 2026
7d7017f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2026
4726c5b
type fixes
jan-janssen Feb 21, 2026
5692ec3
fix
jan-janssen Feb 21, 2026
f4cfbe9
fix warnings
jan-janssen Feb 21, 2026
56ca546
fix warning
jan-janssen Feb 21, 2026
412f7b0
add validation test
jan-janssen Feb 21, 2026
5feafc0
fix test
jan-janssen Feb 21, 2026
2891b04
learn from jules
jan-janssen Feb 21, 2026
24b5814
fix import in test
jan-janssen Feb 21, 2026
9f98e8b
handle tests on windows
jan-janssen Feb 21, 2026
1b21e68
test validation error is raised
jan-janssen Feb 22, 2026
a8a8295
validate resource_dict
jan-janssen Feb 22, 2026
c992ce4
fix validation
jan-janssen Feb 22, 2026
6d9de38
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2026
fbcc8dc
Add cache_key to resource_dict
jan-janssen Feb 22, 2026
532c30e
Merge branch 'pydantic' of github.com:pyiron/executorlib into pydantic
jan-janssen Feb 22, 2026
53f3afd
reduce available keys in resource_dict
jan-janssen Feb 22, 2026
3018f6e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2026
dc77712
always validate resource dict variable
jan-janssen Feb 22, 2026
01cbcff
include slurm_cmd_args in validation
jan-janssen Feb 22, 2026
d7f5178
Merge branch 'main' into pydantic
jan-janssen Feb 22, 2026
d6ed7c4
fix restart limit check
jan-janssen Feb 22, 2026
aab7930
update documentation
jan-janssen Feb 22, 2026
ee1eb34
Add remark about pydantic validation
jan-janssen Feb 22, 2026
a9d5fe4
update documentation
jan-janssen Feb 22, 2026
5f39e92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2026
a742f12
Merge branch 'main' into pydantic
jan-janssen Feb 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci_support/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dependencies:
- jupyter-book =1.0.0
- mpi4py =4.1.1
- python =3.12
- pydantic =2.12.4
- pyzmq =27.1.0
1 change: 1 addition & 0 deletions .ci_support/environment-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- ipython =9.9.0
- matplotlib =3.10.8
- networkx =3.6.1
- pydantic =2.12.4
- pygraphviz =1.14
- pysqa =0.3.5
- pyzmq =27.1.0
Expand Down
1 change: 1 addition & 0 deletions .ci_support/environment-mpich.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- ipython =9.9.0
- mpi4py =4.1.1
- networkx =3.6.1
- pydantic =2.12.4
- pygraphviz =1.14
- pysqa =0.3.5
- pyzmq =27.1.0
1 change: 1 addition & 0 deletions .ci_support/environment-old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- h5py =3.6.0
- networkx =2.8.8
- ipython =7.33.0
- pydantic =2.5.3
- pygraphviz =1.10
- hatchling =1.27.0
- hatch-vcs =0.4.0
1 change: 1 addition & 0 deletions .ci_support/environment-openmpi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- ipython =9.9.0
- mpi4py =4.1.1
- networkx =3.6.1
- pydantic =2.12.4
- pygraphviz =1.14
- pysqa =0.3.5
- pyzmq =27.1.0
1 change: 1 addition & 0 deletions .ci_support/environment-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dependencies:
- ipython =9.9.0
- mpi4py =4.1.1
- networkx =3.6.1
- pydantic =2.12.4
- pygraphviz =1.14
- pyzmq =27.1.0
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ cluster = [
"pysqa==0.3.5",
"h5py==3.15.1",
]
validation = [
"pydantic==2.12.4",
]
all = [
"mpi4py==4.1.1",
"pysqa==0.3.5",
"h5py==3.15.1",
"pydantic==2.12.4",
"pygraphviz==1.14",
"networkx==3.6.1",
"ipython==9.9.0",
Expand Down
20 changes: 20 additions & 0 deletions src/executorlib/executor/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
from executorlib.task_scheduler.interactive.dependency import DependencyTaskScheduler
from executorlib.task_scheduler.interactive.onetoone import OneProcessTaskScheduler

try:
from executorlib.standalone.validate import (
validate_resource_dict,
validate_resource_dict_with_optional_keys,
)
except ImportError:
from executorlib.task_scheduler.base import validate_resource_dict
from executorlib.task_scheduler.base import (
validate_resource_dict as validate_resource_dict_with_optional_keys,
)


class FluxJobExecutor(BaseExecutor):
"""
Expand Down Expand Up @@ -162,6 +173,7 @@ def __init__(
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.
wait (bool): Whether to wait for the completion of all tasks before shutting down the executor.
validator (callable): A function to validate the resource_dict.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

"""
default_resource_dict: dict = {
Expand Down Expand Up @@ -194,6 +206,7 @@ def __init__(
init_function=init_function,
log_obj_size=log_obj_size,
wait=wait,
validator=validate_resource_dict,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
Expand All @@ -220,6 +233,7 @@ def __init__(
init_function=init_function,
log_obj_size=log_obj_size,
wait=wait,
validator=validate_resource_dict,
)
)

Expand Down Expand Up @@ -396,6 +410,7 @@ def __init__(
resource_dict=resource_dict,
pysqa_config_directory=pysqa_config_directory,
backend="flux",
validator=validate_resource_dict_with_optional_keys,
)
)
else:
Expand All @@ -421,6 +436,7 @@ def __init__(
disable_dependencies=disable_dependencies,
wait=wait,
refresh_rate=refresh_rate,
validator=validate_resource_dict_with_optional_keys,
)
)
else:
Expand All @@ -438,6 +454,7 @@ def __init__(
hostname_localhost=hostname_localhost,
block_allocation=block_allocation,
init_function=init_function,
validator=validate_resource_dict,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
Expand All @@ -462,6 +479,7 @@ def create_flux_executor(
init_function: Optional[Callable] = None,
log_obj_size: bool = False,
wait: bool = True,
validator: Callable = validate_resource_dict,
) -> Union[OneProcessTaskScheduler, BlockAllocationTaskScheduler]:
"""
Create a flux executor
Expand Down Expand Up @@ -549,11 +567,13 @@ def create_flux_executor(
max_workers=max_workers,
executor_kwargs=resource_dict,
spawner=FluxPythonSpawner,
validator=validator,
)
else:
return OneProcessTaskScheduler(
max_cores=max_cores,
max_workers=max_workers,
executor_kwargs=resource_dict,
spawner=FluxPythonSpawner,
validator=validator,
)
18 changes: 18 additions & 0 deletions src/executorlib/executor/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
from executorlib.task_scheduler.interactive.dependency import DependencyTaskScheduler
from executorlib.task_scheduler.interactive.onetoone import OneProcessTaskScheduler

try:
from executorlib.standalone.validate import (
validate_resource_dict,
validate_resource_dict_with_optional_keys,
)
except ImportError:
from executorlib.task_scheduler.base import validate_resource_dict
from executorlib.task_scheduler.base import (
validate_resource_dict as validate_resource_dict_with_optional_keys,
)


class SingleNodeExecutor(BaseExecutor):
"""
Expand Down Expand Up @@ -176,6 +187,7 @@ def __init__(
init_function=init_function,
log_obj_size=log_obj_size,
wait=wait,
validator=validate_resource_dict,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
Expand All @@ -198,6 +210,7 @@ def __init__(
init_function=init_function,
log_obj_size=log_obj_size,
wait=wait,
validator=validate_resource_dict,
)
)

Expand Down Expand Up @@ -361,6 +374,7 @@ def __init__(
execute_function=execute_in_subprocess,
wait=wait,
refresh_rate=refresh_rate,
validator=validate_resource_dict_with_optional_keys,
)
)
else:
Expand All @@ -381,6 +395,7 @@ def __init__(
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
validator=validate_resource_dict,
)
)

Expand All @@ -395,6 +410,7 @@ def create_single_node_executor(
init_function: Optional[Callable] = None,
log_obj_size: bool = False,
wait: bool = True,
validator: Callable = validate_resource_dict,
) -> Union[OneProcessTaskScheduler, BlockAllocationTaskScheduler]:
"""
Create a single node executor
Expand Down Expand Up @@ -464,11 +480,13 @@ def create_single_node_executor(
),
executor_kwargs=resource_dict,
spawner=MpiExecSpawner,
validator=validator,
)
else:
return OneProcessTaskScheduler(
max_cores=max_cores,
max_workers=max_workers,
executor_kwargs=resource_dict,
spawner=MpiExecSpawner,
validator=validator,
)
19 changes: 19 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
validate_max_workers,
)

try:
from executorlib.standalone.validate import (
validate_resource_dict,
validate_resource_dict_with_optional_keys,
)
except ImportError:
from executorlib.task_scheduler.base import validate_resource_dict
from executorlib.task_scheduler.base import (
validate_resource_dict as validate_resource_dict_with_optional_keys,
)


class SlurmClusterExecutor(BaseExecutor):
"""
Expand Down Expand Up @@ -192,6 +203,7 @@ def __init__(
resource_dict=resource_dict,
pysqa_config_directory=pysqa_config_directory,
backend="slurm",
validator=validate_resource_dict_with_optional_keys,
),
)

Expand All @@ -218,6 +230,7 @@ def __init__(
disable_dependencies=disable_dependencies,
wait=wait,
refresh_rate=refresh_rate,
validator=validate_resource_dict_with_optional_keys,
)
)
else:
Expand Down Expand Up @@ -410,6 +423,7 @@ def __init__(
init_function=init_function,
log_obj_size=log_obj_size,
wait=wait,
validator=validate_resource_dict,
),
max_cores=max_cores,
refresh_rate=refresh_rate,
Expand All @@ -433,6 +447,7 @@ def __init__(
init_function=init_function,
log_obj_size=log_obj_size,
wait=wait,
validator=validate_resource_dict,
)
)

Expand All @@ -448,6 +463,7 @@ def create_slurm_executor(
init_function: Optional[Callable] = None,
log_obj_size: bool = False,
wait: bool = True,
validator: Callable = validate_resource_dict,
) -> Union[OneProcessTaskScheduler, BlockAllocationTaskScheduler]:
"""
Create a SLURM executor
Expand Down Expand Up @@ -489,6 +505,7 @@ def create_slurm_executor(
init_function (None): optional function to preset arguments for functions which are submitted later
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.
wait (bool): Whether to wait for the completion of all tasks before shutting down the executor.
validator (callable): A function to validate the resource_dict.

Returns:
InteractiveStepExecutor/ InteractiveExecutor
Expand Down Expand Up @@ -519,11 +536,13 @@ def create_slurm_executor(
max_workers=max_workers,
executor_kwargs=resource_dict,
spawner=SrunSpawner,
validator=validator,
)
else:
return OneProcessTaskScheduler(
max_cores=max_cores,
max_workers=max_workers,
executor_kwargs=resource_dict,
spawner=SrunSpawner,
validator=validator,
)
39 changes: 39 additions & 0 deletions src/executorlib/standalone/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import warnings
from typing import Optional

from pydantic import BaseModel


class ResourceDictValidation(BaseModel):
cores: Optional[int] = None
threads_per_core: Optional[int] = None
gpus_per_core: Optional[int] = None
cwd: Optional[str] = None
num_nodes: Optional[int] = None
exclusive: Optional[bool] = None
error_log_file: Optional[str] = None
restart_limit: Optional[int] = None
run_time_limit: Optional[int] = None
priority: Optional[int] = (None,)
openmpi_oversubscribe: Optional[bool] = (None,)
pmi_mode: Optional[str] = (None,)
flux_executor_nesting: Optional[bool] = (None,)
flux_log_files: Optional[bool] = (None,)
run_time_limit: Optional[int] = (None,)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
slurm_cmd_args: Optional[list[str]] = None


def validate_resource_dict(resource_dict: dict) -> None:
_ = ResourceDictValidation(**resource_dict)


def validate_resource_dict_with_optional_keys(resource_dict: dict) -> None:
accepted_keys = ResourceDictValidation.model_fields.keys()
optional_lst = [key for key in resource_dict if key not in accepted_keys]
validate_dict = {
key: value for key, value in resource_dict.items() if key in accepted_keys
}
_ = ResourceDictValidation(**validate_dict)
warnings.warn(
f"The following keys are not recognized and cannot be validated: {optional_lst}"
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
12 changes: 11 additions & 1 deletion src/executorlib/task_scheduler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from executorlib.standalone.serialize import cloudpickle_register


def validate_resource_dict(resource_dict: dict):
pass


class TaskSchedulerBase(FutureExecutor):
"""
Base class for the executor.
Expand All @@ -22,7 +26,11 @@ class TaskSchedulerBase(FutureExecutor):
max_cores (int): defines the number cores which can be used in parallel
"""

def __init__(self, max_cores: Optional[int] = None):
def __init__(
self,
max_cores: Optional[int] = None,
validator: Callable = validate_resource_dict,
):
"""
Initialize the ExecutorBase class.
"""
Expand All @@ -31,6 +39,7 @@ def __init__(self, max_cores: Optional[int] = None):
self._max_cores = max_cores
self._future_queue: Optional[queue.Queue] = queue.Queue()
self._process: Optional[Union[Thread, list[Thread]]] = None
self._validator = validator

@property
def max_workers(self) -> Optional[int]:
Expand Down Expand Up @@ -120,6 +129,7 @@ def submit( # type: ignore
"""
if resource_dict is None:
resource_dict = {}
self._validator(resource_dict)
cores = resource_dict.get("cores")
if (
cores is not None
Expand Down
Loading
Loading