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

Plugin task sublcasses #59

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Plugin task sublcasses #59

wants to merge 3 commits into from

Conversation

leclairm
Copy link
Contributor

@leclairm leclairm commented Dec 3, 2024

Host plugin specific behavior/logic in subclasses of core.Task

- add a Plugin metaclass to register Task subclasses
- make core a folder
- add core._tasks folder to host all plugin tasks
- split core.py into graph_items.py and workflow.py
  to solve cyclic import issues
@leclairm leclairm marked this pull request as draft December 3, 2024 14:34
Copy link
Collaborator

@GeigerJ2 GeigerJ2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the nice work @leclairm. I think subclassing into IconTask and ShellTask is also the route I would have taken for #49 (while for the ConfigTask, we probably can keep just one). Looking forward to the discussion tomorrow!

Comment on lines +5 to +7
__all__ = [
p.name[:-3] for p in Path(__file__).parent.glob("*.py") if p.is_file() and not p.name.endswith("__init__.py")
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't do this. Shouldn't be too much effort to just write the actual list here, and update it when needed. (as written in the comment above)

Comment on lines +14 to +15
command_option: str | None = None
input_arg_options: dict[str, str] | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find this nomenclature very intuitive. I'd vouch for (in YAML format):

      cli_arguments:
        positional: [data1, data2]
        keyword:
          --input: obs_data
        flags:
          - --restart

In addition, having a source_file key that allows sourcing a file to load environment variables, should cover the vast majority of executables that anyone would ever want to call, e.g. preproc, postproc, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was the conclusion from the in person meeting

space = ({} if date is None else {"date": [date]}) | {k: parameters[k] for k in param_refs}
yield from (dict(zip(space.keys(), x)) for x in product(*space.values()))

class Plugin(type):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I hear Plugin, I typically think of AiiDA plugins, such as aiida-icon, but I see the wording here refers to specific derived classes from core Tasks ^^
Actually, just learned about this use case of metaclasses to register specific subclasses, interesting! Not sure how many plugins we will have an actual need (and time and effort) for, to be discussed tomorrow.

Comment on lines +65 to +79
) -> Task:
inputs = list(
chain(*(datastore.iter_from_cycle_spec(input_spec, coordinates) for input_spec in graph_spec.inputs))
)
outputs = [datastore[output_spec.name, coordinates] for output_spec in graph_spec.outputs]
# use the fact that pydantic models can be turned into dicts easily
cls_config = dict(config)
del cls_config["parameters"]
del cls_config["plugin"]
new = Plugin.classes[config.plugin](
coordinates=coordinates,
inputs=inputs,
outputs=outputs,
**cls_config,
) # this works because dataclass has generated this init for us
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I fully understand the changes here. Possibly the change of behavior of the from_config method could be a separate PR?

@@ -186,7 +171,7 @@ def iter_from_cycle_spec(self, spec: TargetNodesBaseModel, reference: dict) -> I
if "date" not in self._dims and (spec.lag or spec.date):
msg = f"Array {self._name} has no date dimension, cannot be referenced by dates"
raise ValueError(msg)
if "date" in self._dims and reference.get("date") is None and spec.date is []:
if "date" in self._dims and reference.get("date") is None and spec.date == []:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if "date" in self._dims and reference.get("date") is None and spec.date == []:
if "date" in self._dims and reference.get("date") is None and len(spec.date) == 0:

?

@@ -61,27 +61,25 @@ tasks:
host: santis
account: g110
- extpar:
plugin: extpar
plugin: shell # no extpar plugin available yet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are talking about AiiDA plugins, writing an aiida-extpar plugin will be too much work, I think, for some time to come. I expect us to handle other executables with aiida-shell in the same manner for quite a while, as aiida-shell can be used to run any executable (not just shell scripts), and we have enough work here and in aiida-icon ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants