Skip to content

Commit

Permalink
Merge pull request #12 from ml-evs/ml-evs/fix
Browse files Browse the repository at this point in the history
Fix handling of null worker in `submit_flow`
  • Loading branch information
gpetretto authored Aug 14, 2023
2 parents c1d0b96 + 52eb795 commit 593224a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/jobflow_remote/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,15 @@ def remove_worker(self, worker_name: str, project_name: str | None = None):
self.dump_project(project_data)

def get_worker(
self, worker_name: str | None = None, project_name: str | None = None
self, worker_name: str, project_name: str | None = None
) -> WorkerBase:
"""
Return the worker object based on the name.
Parameters
----------
worker_name
Name of the worker to retrieve, or None to use the first one listed in the
project.
Name of the worker to retrieve.
project_name
Name of the project from which the Worker should be retrieved, or None to
use the one from the settings.
Expand All @@ -348,9 +347,6 @@ def get_worker(
The selected Worker.
"""
project = self.get_project(project_name)
if not worker_name:
worker_name = next(iter(project.workers.keys()))

if worker_name not in project.workers:
raise ConfigError(f"Worker with name {worker_name} is not defined")
return project.workers[worker_name]
Expand Down
5 changes: 4 additions & 1 deletion src/jobflow_remote/fireworks/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fireworks import Firework, Workflow
from qtoolkit.core.data_objects import QResources

from jobflow_remote.config.base import ExecutionConfig
from jobflow_remote.config.base import ConfigError, ExecutionConfig
from jobflow_remote.fireworks.tasks import RemoteJobFiretask

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -66,6 +66,9 @@ def flow_to_workflow(
parent_mapping: dict[str, Firework] = {}
fireworks = []

if not worker:
raise ConfigError("Worker name must be set.")

flow = get_flow(flow)

for job, parents in flow.iterflow():
Expand Down
9 changes: 7 additions & 2 deletions src/jobflow_remote/jobs/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jobflow
from qtoolkit.core.data_objects import QResources

from jobflow_remote.config.base import ExecutionConfig
from jobflow_remote.config.base import ConfigError, ExecutionConfig
from jobflow_remote.config.manager import ConfigManager
from jobflow_remote.fireworks.convert import flow_to_workflow

Expand All @@ -27,7 +27,8 @@ def submit_flow(
flow
A flow or job.
worker
The name of the Worker where the calculation will be submitted
The name of the Worker where the calculation will be submitted. If None, use the
first configured worker for this project.
store
A job store. Alternatively, if set to None, :obj:`JobflowSettings.JOB_STORE`
will be used. Note, this could be different on the computer that submits the
Expand All @@ -46,6 +47,10 @@ def submit_flow(
config_manager = ConfigManager()

proj_obj = config_manager.get_project(project)
if worker is None:
if not proj_obj.workers:
raise ConfigError("No workers configured for this project.")
worker = next(iter(proj_obj.workers.keys()))

# try to load the worker and exec_config to check that the values are well defined
config_manager.get_worker(worker_name=worker, project_name=project)
Expand Down

0 comments on commit 593224a

Please sign in to comment.