Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify the computer for a task #78

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/sirocco/parsing/_yaml_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def check_period_is_not_negative_or_zero(self) -> ConfigCycle:

@dataclass
class ConfigBaseTaskSpecs:
computer: str | None = None
host: str | None = None
account: str | None = None
uenv: dict | None = None
Expand Down
16 changes: 14 additions & 2 deletions src/sirocco/workgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import aiida.common
import aiida.orm
import aiida_workgraph.engine.utils # type: ignore[import-untyped]
from aiida.common.exceptions import NotExistent
from aiida_workgraph import WorkGraph

from sirocco.core._tasks.icon_task import IconTask
Expand Down Expand Up @@ -179,14 +180,25 @@ def _create_task_node(self, task: graph_items.Task):
command_full_path = task.command if command_path.is_absolute() else task.config_rootdir / command_path
command = str(command_full_path)

# Source file
# metadata
metadata = {}
## Source file
env_source_paths = [
env_source_path
if (env_source_path := Path(env_source_file)).is_absolute()
else (task.config_rootdir / env_source_path)
for env_source_file in task.env_source_files
]
prepend_text = "\n".join([f"source {env_source_path}" for env_source_path in env_source_paths])
metadata["options"] = {"prepend_text": prepend_text}

## computer
if task.computer is not None:
try:
metadata["computer"] = aiida.orm.load_computer(task.computer)
except NotExistent as err:
msg = f"Could not find computer {task.computer} for task {task}."
raise ValueError(msg) from err

# NOTE: We don't pass the `nodes` dictionary here, as then we would need to have the sockets available when
# we create the task. Instead, they are being updated via the WG internals when linking inputs/outputs to
Expand All @@ -197,7 +209,7 @@ def _create_task_node(self, task: graph_items.Task):
command=command,
arguments=[],
outputs=[],
metadata={"options": {"prepend_text": prepend_text}},
metadata=metadata,
)

self._aiida_task_nodes[label] = workgraph_task
Expand Down
2 changes: 2 additions & 0 deletions tests/cases/small/config/test_config_small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ cycles:
date: 2026-05-01T00:00
tasks:
- icon:
computer: localhost
plugin: shell
command: scripts/icon.py
cli_arguments: "{--restart icon_restart} {--init initial_conditions}"
env_source_files: data/dummy_source_file.sh
- cleanup:
computer: localhost
plugin: shell
command: scripts/cleanup.py
data:
Expand Down
4 changes: 4 additions & 0 deletions tests/cases/small/data/test_config_small.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cycles:
- icon_restart [date: 2026-01-01 00:00:00]
name: 'icon'
coordinates: {'date': datetime.datetime(2026, 1, 1, 0, 0)}
computer: 'localhost'
start date: 2026-01-01 00:00:00
end date: 2026-06-01 00:00:00
plugin: 'shell'
Expand All @@ -27,6 +28,7 @@ cycles:
- icon_restart [date: 2026-03-01 00:00:00]
name: 'icon'
coordinates: {'date': datetime.datetime(2026, 3, 1, 0, 0)}
computer: 'localhost'
start date: 2026-01-01 00:00:00
end date: 2026-06-01 00:00:00
plugin: 'shell'
Expand All @@ -44,6 +46,7 @@ cycles:
- icon_restart [date: 2026-05-01 00:00:00]
name: 'icon'
coordinates: {'date': datetime.datetime(2026, 5, 1, 0, 0)}
computer: 'localhost'
start date: 2026-01-01 00:00:00
end date: 2026-06-01 00:00:00
plugin: 'shell'
Expand All @@ -57,6 +60,7 @@ cycles:
- icon [date: 2026-05-01 00:00:00]
name: 'cleanup'
coordinates: {}
computer: 'localhost'
plugin: 'shell'
command: 'scripts/cleanup.py'
cli arguments: []
Expand Down
5 changes: 4 additions & 1 deletion tests/test_wc_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ def test_vizgraph(config_paths):
"tests/cases/parameters/config/test_config_parameters.yml",
],
)
def test_run_workgraph(config_path):
def test_run_workgraph(config_path, aiida_computer):
"""Tests end-to-end the parsing from file up to running the workgraph.

Automatically uses the aiida_profile fixture to create a new profile. Note to debug the test with your profile
please run this in a separate file as the profile is deleted after test finishes.
"""
# some configs reference computer "localhost" which we need to create beforehand
aiida_computer("localhost").store()

core_workflow = Workflow.from_yaml(config_path)
aiida_workflow = AiidaWorkGraph(core_workflow)
out = aiida_workflow.run()
Expand Down
Loading