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

Support of generic aiida plugins #20

Closed
wants to merge 4 commits into from
Closed
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ To manage the repo we use [hatch]{.title-ref} please install it

``` bash
pip install hatch
hatch shell # activate shell as dev environment
hatch test # run tests
hatch fmt # run formatting
hatch run docs:build # build docs
hatch run docs:serve # live preview of doc for development
```

### Tests
``` bash
pip install hatch
verdi devel launch-add # creates required codes
verdi presto
hatch test
```

## Resources

- <https://aiida-workgraph.readthedocs.io/en/latest/>
Expand Down
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ classifiers = [
'Topic :: Scientific/Engineering :: Atmospheric Science',
]
keywords = ["wc", "workflow"," icon", "aiida", "aiida-workgraph"]
requires-python = '>=3.12'
requires-python = '~=3.12'
dependencies = [
"isoduration",
"pydantic",
"pydantic-yaml",
"aiida-core>=2.5"
"aiida-core>=2.5",
'aiida-workgraph[widget]==0.3.14',
'node_graph==0.0.11',
]

[tool.pytest.ini_options]
Expand All @@ -55,7 +57,11 @@ ignore = [
[tool.hatch.version]
path = "src/wcflow/__init__.py"

[project.optional-dependencies]
tests = ["pytest"]

[tool.hatch.envs.hatch-test]
extras = ["tests"]
extra-dependencies = [
"ipdb"
]
Expand Down
19 changes: 19 additions & 0 deletions src/wcflow/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import aiida.orm


class OrmUtils:
@staticmethod
def convert_to_class(type_: str) -> aiida.orm.utils.node.AbstractNodeMeta:
if type_ == "file":
return aiida.orm.SinglefileData
elif type_ == "dir":
return aiida.orm.FolderData
elif type_ == "int":
return aiida.orm.Int
elif type_ == "float":
return aiida.orm.Float
elif type_ == "remote":
return aiida.orm.RemoteData
else:
raise ValueError(f"Type {type_} is unknown.")

76 changes: 55 additions & 21 deletions src/wcflow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from datetime import datetime
from itertools import chain
from os.path import expandvars
from pathlib import Path
from typing import TYPE_CHECKING

Expand All @@ -24,20 +23,25 @@ def __init__(
lag: list[Duration],
date: list[datetime],
arg_option: str | None,
port_name: str | None,
):
self._name = name

self._src = src
self._path = Path(expandvars(self._src))

self._type = type
if self._type not in ["file", "dir"]:
msg = f"Data type {self._type!r} not supported. Please use 'file' or 'dir'."
raise ValueError(msg)

if len(lag) > 0 and len(date) > 0:
msg = "Either 'lag' or 'date' can be nonempty. Not both."
raise ValueError(msg)
# type probably not needed
#if self._type not in ["file", "dir", ""]:
# msg = f"Data type {self._type!r} not supported. Please use 'file' or 'dir'."
# raise ValueError(msg)

# check if not already done by parsing? best inherit these
#if len(lag) > 0 and len(date) > 0:
# msg = "Either 'lag' or 'date' can be nonempty. Not both."
# raise ValueError(msg)

self._port_name = self._name if port_name is None else port_name

# COMMENT I think we should just disallow multiple lags, and enforce the user to write multiple lags
# I am not sure how this work with icon as it does not need positional arguments
Expand Down Expand Up @@ -67,10 +71,6 @@ def type(self) -> str:
def src(self) -> str:
return self._src

@property
def path(self) -> Path:
return self._path

@property
def lag(self) -> list[Duration]:
return self._lag
Expand All @@ -83,6 +83,10 @@ def date(self) -> list[datetime]:
def arg_option(self) -> str | None:
return self._arg_option

@property
def port_name(self) -> str:
return self._port_name


class Data(_DataBase):
def __init__(
Expand All @@ -93,8 +97,9 @@ def __init__(
lag: list[Duration],
date: list[datetime],
arg_option: str | None,
port_name: str | None
):
super().__init__(name, type, src, lag, date, arg_option)
super().__init__(name, type, src, lag, date, arg_option, port_name)
self._task: Task | None = None

def unroll(self, unrolled_task: UnrolledTask) -> Generator[UnrolledData, None, None]:
Expand Down Expand Up @@ -130,7 +135,6 @@ def task(self, task: Task):
raise ValueError(msg)
self._task = task


class UnrolledData(_DataBase):
"""
Data that are created during the unrolling of a cycle.
Expand All @@ -139,7 +143,7 @@ class UnrolledData(_DataBase):

@classmethod
def from_data(cls, data: Data, unrolled_task: UnrolledTask, unrolled_date: datetime):
return cls(unrolled_task, unrolled_date, data.name, data.type, data.src, data.lag, data.date, data.arg_option)
return cls(unrolled_task, unrolled_date, data.name, data.type, data.src, data.lag, data.date, data.arg_option, data.port_name)

def __init__(
self,
Expand All @@ -151,8 +155,9 @@ def __init__(
lag: list[Duration],
date: list[datetime],
arg_option: str | None,
port_name: str
):
super().__init__(name, type, src, lag, date, arg_option)
super().__init__(name, type, src, lag, date, arg_option, port_name)
self._unrolled_task = unrolled_task
self._unrolled_date = unrolled_date

Expand Down Expand Up @@ -323,13 +328,19 @@ def __init__(
outputs: list[Data],
depends: list[Dependency],
command_option: str | None,
plugin: str,
code: str,
computer: str,
):
self._name = name
self._command = expandvars(command)
self._command = command
self._inputs = inputs
self._outputs = outputs
self._depends = depends
self._command_option = command_option
self._plugin = plugin
self._code = code
self._computer = computer

@property
def name(self) -> str:
Expand All @@ -355,6 +366,18 @@ def command_option(self) -> str | None:
def depends(self) -> list[Dependency]:
return self._depends

@property
def plugin(self):
return self._plugin

@property
def code(self):
return self._code

@property
def computer(self):
return self._computer


class Task(_TaskBase):
"""A task that is created during the unrolling of a cycle."""
Expand All @@ -367,8 +390,11 @@ def __init__(
outputs: list[Data],
depends: list[Dependency],
command_option: str | None,
plugin: str,
code: str,
computer: str,
):
super().__init__(name, command, inputs, outputs, depends, command_option)
super().__init__(name, command, inputs, outputs, depends, command_option, plugin, code, computer)
for input_ in inputs:
input_.task = self
for output in outputs:
Expand Down Expand Up @@ -409,7 +435,7 @@ class UnrolledTask(_TaskBase):
@classmethod
def from_task(cls, task: Task, unrolled_cycle: UnrolledCycle):
return cls(
unrolled_cycle, task.name, task.command, task.inputs, task.outputs, task.depends, task.command_option
unrolled_cycle, task.name, task.command, task.inputs, task.outputs, task.depends, task.command_option, task.plugin, task.code, task.computer
)

def __init__(
Expand All @@ -421,8 +447,11 @@ def __init__(
outputs: list[Data],
depends: list[Dependency],
command_option: str | None,
plugin: str,
code: str,
computer: str,
):
super().__init__(name, command, inputs, outputs, depends, command_option)
super().__init__(name, command, inputs, outputs, depends, command_option, plugin, code, computer)
self._unrolled_cycle = unrolled_cycle
self._unrolled_inputs = list(self.unroll_inputs())
self._unrolled_outputs = list(self.unroll_outputs())
Expand Down Expand Up @@ -624,9 +653,10 @@ def workflow(self) -> Workflow:


class Workflow:
def __init__(self, name: str, cycles: list[Cycle]):
def __init__(self, name: str, cycles: list[Cycle], computer: str):
self._name = name
self._cycles = cycles
self._computer = computer
for cycle in self._cycles:
cycle.workflow = self
self._validate_cycles()
Expand Down Expand Up @@ -659,6 +689,10 @@ def name(self) -> str:
def cycles(self) -> list[Cycle]:
return self._cycles

@property
def computer(self) -> str:
return self._computer

def is_available_on_init(self, data: UnrolledData) -> bool:
"""Determines if the data is available on init of the workflow."""

Expand Down
Loading