Skip to content

Commit

Permalink
Use node-graph-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Dec 3, 2024
1 parent 3db9082 commit 4bc1fd6
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 5,214 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ jobs:
- name: Create AiiDA profile
run: verdi setup -n --config .github/config/profile.yaml

- name: Install Dependencies for widget
working-directory: aiida_workgraph/widget
run: |
npm install
npm run build
- name: Install Dependencies, Start React Application
working-directory: aiida_workgraph/web/frontend
run: |
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install build
- name: Build widget
working-directory: aiida_workgraph/widget/
run: |
npm install
npm run build
- name: Build web frontend package
working-directory: aiida_workgraph/web/frontend/
run: |
Expand Down
2 changes: 0 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ build:
nodejs: "20" # maybe need to be also miniconda
jobs:
post_create_environment:
- npm --prefix aiida_workgraph/widget install
- npm --prefix aiida_workgraph/widget run build
- python -m pip install --no-cache-dir .[docs]
- python -m pip install --exists-action=w --no-cache-dir -r docs/requirements.txt
- rabbitmq-server -detached
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Efficiently design and manage flexible workflows with AiiDA, featuring an intera
## Installation

```console
pip install aiida-workgraph[widget]
pip install aiida-workgraph
```

To install the latest version from source, first clone the repository and then install using `pip`:
Expand All @@ -22,14 +22,10 @@ cd aiida-workgraph
pip install -e .
```

To install the jupyter widget support you need to in addition build the JavaScript packages:
To install the web app you need to in addition build the JavaScript packages:

```console
pip install .[widget]
# build widget
cd aiida_workgraph/widget/
npm install
npm run build
pip install .
# build web frontend
cd ../../aiida_workgraph/web/frontend/
npm install
Expand Down Expand Up @@ -104,9 +100,6 @@ pip install -e .[tests,pre-commit]
pre-commit install
```

### Widget
See the [README.md](https://github.com/aiidateam/aiida-workgraph/blob/main/aiida_workgraph/widget/README.md)

### Web app
See the [README.md](https://github.com/aiidateam/aiida-workgraph/blob/main/aiida_workgraph/web/README.md)

Expand Down
7 changes: 0 additions & 7 deletions aiida_workgraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
try:
import anywidget # noqa: F401

USE_WIDGET = True
except ImportError:
USE_WIDGET = False

from .workgraph import WorkGraph
from .task import Task
from .decorator import task, build_task
Expand Down
50 changes: 29 additions & 21 deletions aiida_workgraph/task.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from __future__ import annotations

from node_graph.node import Node as GraphNode
from aiida_workgraph import USE_WIDGET

from aiida_workgraph.properties import property_pool
from aiida_workgraph.sockets import socket_pool

if USE_WIDGET:
from aiida_workgraph.widget import NodeGraphWidget
from node_graph_widget import NodeGraphWidget
from aiida_workgraph.collection import (
WorkGraphPropertyCollection,
WorkGraphInputSocketCollection,
WorkGraphOutputSocketCollection,
)
import aiida
from typing import Any, Dict, Optional, Union, Callable, List, Set, Iterable
from aiida_workgraph.utils.message import WIDGET_INSTALLATION_MESSAGE


class Task(GraphNode):
Expand Down Expand Up @@ -49,13 +46,10 @@ def __init__(
self.waiting_on = TaskCollection(parent=self)
self.process = process
self.pk = pk
if USE_WIDGET:
self._widget = NodeGraphWidget(
settings={"minmap": False},
style={"width": "80%", "height": "600px"},
)
else:
self._widget = None
self._widget = NodeGraphWidget(
settings={"minmap": False},
style={"width": "80%", "height": "600px"},
)
self.state = "PLANNED"
self.action = ""
self.show_socket_depth = 0
Expand Down Expand Up @@ -171,13 +165,30 @@ def get_error_handlers(self) -> list:
handler["exit_codes"] = exit_codes
return handlers

def _repr_mimebundle_(self, *args: Any, **kwargs: Any) -> any:
def to_widget_value(self):
from aiida_workgraph.utils import filter_keys_namespace_depth

tdata = self.to_dict()

if self._widget is None:
print(WIDGET_INSTALLATION_MESSAGE)
return
# Remove certain elements of the dict-representation of the Node that we don't want to show
for key in ("properties", "executor", "node_class", "process"):
tdata.pop(key, None)
for input in tdata["inputs"].values():
input.pop("property")

tdata["label"] = tdata["identifier"]

filtered_inputs = filter_keys_namespace_depth(
dict_=tdata["inputs"], max_depth=self.show_socket_depth
)
tdata["inputs"] = list(filtered_inputs.values())
tdata["outputs"] = list(tdata["outputs"].values())
wgdata = {"name": self.name, "nodes": {self.name: tdata}, "links": []}
return wgdata

def _repr_mimebundle_(self, *args: Any, **kwargs: Any) -> any:
# if ipywdigets > 8.0.0, use _repr_mimebundle_ instead of _ipython_display_
self._widget.from_node(self, show_socket_depth=self.show_socket_depth)
self._widget.value = self.to_widget_value()
if hasattr(self._widget, "_repr_mimebundle_"):
return self._widget._repr_mimebundle_(*args, **kwargs)
else:
Expand All @@ -189,10 +200,7 @@ def to_html(
"""Write a standalone html file to visualize the task."""
if show_socket_depth is None:
show_socket_depth = self.show_socket_depth
if self._widget is None:
print(WIDGET_INSTALLATION_MESSAGE)
return
self._widget.from_node(node=self, show_socket_depth=show_socket_depth)
self._widget.value = self.to_widget_value()
return self._widget.to_html(output=output, **kwargs)


Expand Down
15 changes: 15 additions & 0 deletions aiida_workgraph/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,18 @@ def filter_keys_namespace_depth(
result[key] = value

return result


def wait_to_link(wgdata: Dict[str, Any]) -> None:
"""Convert wait attribute to link."""
for name, task in wgdata["tasks"].items():
for wait_task in task["wait"]:
if wait_task in wgdata["tasks"]:
wgdata["links"].append(
{
"from_node": wait_task,
"from_socket": "_wait",
"to_node": name,
"to_socket": "_wait",
}
)
6 changes: 0 additions & 6 deletions aiida_workgraph/utils/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
WIDGET_INSTALLATION_MESSAGE = (
"Widget dependency not found. To visualize the workgraph, please install the widget dependency. "
"Use 'pip install aiida-workgraph[widget]' if installing from PyPI. "
"For local source installations, use 'pip install .[widget]' and then build the JavaScript library. "
"Refer to the documentation for more details."
)
10 changes: 0 additions & 10 deletions aiida_workgraph/widget/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions aiida_workgraph/widget/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions aiida_workgraph/widget/__init__.py

This file was deleted.

Loading

0 comments on commit 4bc1fd6

Please sign in to comment.