diff --git a/aiida_workgraph/executors/qe.py b/aiida_workgraph/executors/qe.py deleted file mode 100644 index e803ba17..00000000 --- a/aiida_workgraph/executors/qe.py +++ /dev/null @@ -1,28 +0,0 @@ -from typing import Dict -from aiida_workgraph import task -from aiida.orm import StructureData, UpfData - - -@task( - inputs=[ - {"identifier": "workgraph.string", "name": "pseudo_family"}, - {"identifier": StructureData, "name": "structure"}, - ], - outputs=[{"identifier": UpfData, "name": "Pseudo"}], -) -def get_pseudo_from_structure( - pseudo_family: str, structure: StructureData -) -> Dict[str, UpfData]: - """for input_namespace""" - from aiida.orm import Group, QueryBuilder - - pseudo_group = ( - QueryBuilder().append(Group, filters={"label": pseudo_family}).one()[0] - ) - elements = [kind.name for kind in structure.kinds] - pseudos = {} - for ele in elements: - for n in pseudo_group.nodes: - if ele == n.element: - pseudos[ele] = n - return {"Pseudo": pseudos} diff --git a/aiida_workgraph/web/frontend/src/rete/customization.ts b/aiida_workgraph/web/frontend/src/rete/customization.ts deleted file mode 100644 index aec6f6ed..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { NodeEditor, GetSchemes, ClassicPreset } from 'rete'; - -import { AreaExtensions, AreaPlugin } from 'rete-area-plugin'; -import { - ConnectionPlugin, - Presets as ConnectionPresets, -} from 'rete-connection-plugin'; -import { - ReactPlugin, - ReactArea2D, - Presets as ReactPresets, -} from 'rete-react-plugin'; -import { createRoot } from 'react-dom/client'; - -import { CustomNode } from './customization/CustomNode'; -import { StyledNode } from './customization/StyledNode'; -import { CustomSocket } from './customization/CustomSocket'; -import { CustomConnection } from './customization/CustomConnection'; - -import { addCustomBackground } from './customization/custom-background'; - -type Schemes = GetSchemes< - ClassicPreset.Node, - ClassicPreset.Connection ->; -type AreaExtra = ReactArea2D; - -const socket = new ClassicPreset.Socket('socket'); - -export async function createEditor(container: HTMLElement) { - const editor = new NodeEditor(); - const area = new AreaPlugin(container); - const connection = new ConnectionPlugin(); - const reactRender = new ReactPlugin({ createRoot }); - - AreaExtensions.selectableNodes(area, AreaExtensions.selector(), { - accumulating: AreaExtensions.accumulateOnCtrl(), - }); - - reactRender.addPreset( - ReactPresets.classic.setup({ - customize: { - node(context) { - if (context.payload.label === 'Fully customized') { - return CustomNode; - } - if (context.payload.label === 'Override styles') { - return StyledNode; - } - return ReactPresets.classic.Node; - }, - socket() { - return CustomSocket; - }, - connection() { - return CustomConnection; - }, - }, - }) - ); - - connection.addPreset(ConnectionPresets.classic.setup()); - - addCustomBackground(area); - - editor.use(area); - area.use(connection); - area.use(reactRender); - - // AreaExtensions.simpleNodesOrder(area); - - const aLabel = 'Override styles'; - const bLabel = 'Fully customized'; - - const a = new ClassicPreset.Node(aLabel); - a.addOutput('a', new ClassicPreset.Output(socket)); - a.addInput('a', new ClassicPreset.Input(socket)); - await editor.addNode(a); - - const b = new ClassicPreset.Node(bLabel); - b.addOutput('a', new ClassicPreset.Output(socket)); - b.addInput('a', new ClassicPreset.Input(socket)); - await editor.addNode(b); - - await area.translate(a.id, { x: 0, y: 0 }); - await area.translate(b.id, { x: 300, y: 0 }); - - await editor.addConnection(new ClassicPreset.Connection(a, 'a', b, 'a')); - - setTimeout(() => { - AreaExtensions.zoomAt(area, editor.getNodes()); - }, 300); - - return { - destroy: () => area.destroy(), - }; -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/CustomConnection.tsx b/aiida_workgraph/web/frontend/src/rete/customization/CustomConnection.tsx deleted file mode 100644 index a5696af2..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/CustomConnection.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import * as React from "react"; -import styled from "styled-components"; -import { ClassicScheme, Presets } from "rete-react-plugin"; - -const { useConnection } = Presets.classic; - -const Svg = styled.svg` - overflow: visible !important; - position: absolute; - pointer-events: none; - width: 9999px; - height: 9999px; -`; - -const Path = styled.path<{ styles?: (props: any) => any }>` - fill: none; - stroke-width: 5px; - stroke: black; - pointer-events: auto; - ${(props) => props.styles && props.styles(props)} -`; - -export function CustomConnection(props: { - data: ClassicScheme["Connection"] & { isLoop?: boolean }; - styles?: () => any; -}) { - const { path } = useConnection(); - - if (!path) return null; - - return ( - - - - ); -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/CustomNode.tsx b/aiida_workgraph/web/frontend/src/rete/customization/CustomNode.tsx deleted file mode 100644 index 49c4901f..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/CustomNode.tsx +++ /dev/null @@ -1,187 +0,0 @@ -import * as React from "react"; -import { ClassicScheme, RenderEmit, Presets } from "rete-react-plugin"; -import styled, { css } from "styled-components"; -import { $nodewidth, $socketmargin, $socketsize } from "./vars"; - -const { RefSocket, RefControl } = Presets.classic; - -type NodeExtraData = { width?: number; height?: number }; - -export const NodeStyles = styled.div< - NodeExtraData & { selected: boolean; styles?: (props: any) => any } ->` - background: black; - border: 2px solid grey; - border-radius: 10px; - cursor: pointer; - box-sizing: border-box; - width: ${(props) => - Number.isFinite(props.width) ? `${props.width}px` : `${$nodewidth}px`}; - height: ${(props) => - Number.isFinite(props.height) ? `${props.height}px` : "auto"}; - padding-bottom: 6px; - position: relative; - user-select: none; - &:hover { - background: #333; - } - ${(props) => - props.selected && - css` - border-color: red; - `} - .title { - color: white; - font-family: sans-serif; - font-size: 18px; - padding: 8px; - } - .output { - text-align: right; - } - .input { - text-align: left; - } - .output-socket { - text-align: right; - margin-right: -1px; - display: inline-block; - } - .input-socket { - text-align: left; - margin-left: -1px; - display: inline-block; - } - .input-title, - .output-title { - vertical-align: middle; - color: white; - display: inline-block; - font-family: sans-serif; - font-size: 14px; - margin: ${$socketmargin}px; - line-height: ${$socketsize}px; - } - .input-control { - z-index: 1; - width: calc(100% - ${$socketsize + 2 * $socketmargin}px); - vertical-align: middle; - display: inline-block; - } - .control { - display: block; - padding: ${$socketmargin}px ${$socketsize / 2 + $socketmargin}px; - } - ${(props) => props.styles && props.styles(props)} -`; - -function sortByIndex( - entries: T -) { - entries.sort((a, b) => { - const ai = a[1]?.index || 0; - const bi = b[1]?.index || 0; - - return ai - bi; - }); -} - -type Props = { - data: S["Node"] & NodeExtraData; - styles?: () => any; - emit: RenderEmit; -}; -export type NodeComponent = ( - props: Props -) => JSX.Element; - -export function CustomNode(props: Props) { - const inputs = Object.entries(props.data.inputs); - const outputs = Object.entries(props.data.outputs); - const controls = Object.entries(props.data.controls); - const selected = props.data.selected || false; - const { id, label, width, height } = props.data; - - sortByIndex(inputs); - sortByIndex(outputs); - sortByIndex(controls); - - return ( - -
- {label} -
- {/* Outputs */} - {outputs.map( - ([key, output]) => - output && ( -
-
- {output?.label} -
- -
- ) - )} - {/* Controls */} - {controls.map(([key, control]) => { - return control ? ( - - ) : null; - })} - {/* Inputs */} - {inputs.map( - ([key, input]) => - input && ( -
- - {input && (!input.control || !input.showControl) && ( -
- {input?.label} -
- )} - {input?.control && input?.showControl && ( - - - - )} -
- ) - )} -
- ); -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/CustomSocket.tsx b/aiida_workgraph/web/frontend/src/rete/customization/CustomSocket.tsx deleted file mode 100644 index d4f7c83d..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/CustomSocket.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import * as React from "react"; -import { ClassicPreset } from "rete"; -import styled from "styled-components"; -import { $socketsize } from "./vars"; - -const Styles = styled.div` - display: inline-block; - cursor: pointer; - border: 1px solid grey; - width: ${$socketsize}px; - height: ${$socketsize * 2}px; - vertical-align: middle; - background: #fff; - z-index: 2; - box-sizing: border-box; - &:hover { - background: #ddd; - } -`; - -export function CustomSocket(props: { - data: T; -}) { - return ; -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/StyledNode.tsx b/aiida_workgraph/web/frontend/src/rete/customization/StyledNode.tsx deleted file mode 100644 index cf4e836a..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/StyledNode.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { Presets } from "rete-react-plugin"; -import { css } from "styled-components"; - -const styles = css<{ selected?: boolean }>` - background: #ebebeb; - border-color: #646464; - .title { - color: #646464; - } - &:hover { - background: #f2f2f2; - } - .output-socket { - margin-right: -1px; - } - .input-socket { - margin-left: -1px; - } - ${(props) => - props.selected && - css` - border-color: red; - `} -`; - -export function StyledNode(props: any) { - return styles} {...props} />; -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/background.css b/aiida_workgraph/web/frontend/src/rete/customization/background.css deleted file mode 100644 index ff1181f4..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/background.css +++ /dev/null @@ -1,21 +0,0 @@ -.fill-area { - display: table; - z-index: -1; - position: absolute; - top: -320000px; - left: -320000px; - width: 640000px; - height: 640000px; -} - -.background { - background-color: #ffffff; - opacity: 1; - background-image: linear-gradient(#f1f1f1 3.2px, transparent 3.2px), - linear-gradient(90deg, #f1f1f1 3.2px, transparent 3.2px), - linear-gradient(#f1f1f1 1.6px, transparent 1.6px), - linear-gradient(90deg, #f1f1f1 1.6px, #ffffff 1.6px); - background-size: 80px 80px, 80px 80px, 16px 16px, 16px 16px; - background-position: -3.2px -3.2px, -3.2px -3.2px, -1.6px -1.6px, - -1.6px -1.6px; -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/custom-background.ts b/aiida_workgraph/web/frontend/src/rete/customization/custom-background.ts deleted file mode 100644 index 13861856..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/custom-background.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseSchemes } from "rete"; -import { AreaPlugin } from "rete-area-plugin"; -import './background.css' - -export function addCustomBackground( - area: AreaPlugin -) { - const background = document.createElement("div"); - - background.classList.add("background"); - background.classList.add("fill-area"); - - area.area.content.add(background); -} diff --git a/aiida_workgraph/web/frontend/src/rete/customization/vars.ts b/aiida_workgraph/web/frontend/src/rete/customization/vars.ts deleted file mode 100644 index c79b882e..00000000 --- a/aiida_workgraph/web/frontend/src/rete/customization/vars.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const $nodewidth = 200; -export const $socketmargin = 6; -export const $socketsize = 16; diff --git a/aiida_workgraph/web/frontend/src/rete/index.ts b/aiida_workgraph/web/frontend/src/rete/index.ts deleted file mode 100644 index ba4ed726..00000000 --- a/aiida_workgraph/web/frontend/src/rete/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { createEditor as createDefaultEditor } from './default' -import { createEditor as createCustomEditor } from './customization' - -const factory = { - 'default': createDefaultEditor, - 'customization': createCustomEditor, -} -// eslint-disable-next-line no-restricted-globals, no-undef -const query = typeof location !== 'undefined' && new URLSearchParams(location.search) -const name = ((query && query.get('template')) || 'default') as keyof typeof factory - -const createEditor = factory[name] - -if (!createEditor) { - throw new Error(`template with name ${name} not found`) -} - -export { - createEditor -} diff --git a/examples/example.ipynb b/examples/example.ipynb deleted file mode 100644 index 41318e31..00000000 --- a/examples/example.ipynb +++ /dev/null @@ -1,109 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Example\n", - "\n", - "## Node from WorkGraph\n", - "Create a node from a WorkGraph" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['parameters']\n", - "['parameters', 'output_parameters']\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "a40ea66c06b14a798590cce3071ee554", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "NodeGraphWidget(settings={'minimap': True}, style={'width': '90%', 'height': '600px'}, value={'name': 'WorkGra…" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from workgraph_collections.qe.bands import bands_workgraph\n", - "from aiida import load_profile\n", - "load_profile()\n", - "\n", - "bands_wg = bands_workgraph(run_relax=True)\n", - "bands_wg" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "2ce656b7e3da43a6952bca4c95afa3eb", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "NodeGraphWidget(settings={'minmap': False}, style={'width': '40%', 'height': '600px'}, value={'nodes': {'PdosW…" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from aiida_quantumespresso.workflows.pdos import PdosWorkChain\n", - "from aiida_workgraph import WorkGraph\n", - "wg = WorkGraph()\n", - "wg.add_task(PdosWorkChain)\n", - "wg.tasks[0]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "aiida", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/examples_widget.ipynb b/examples/examples_widget.ipynb deleted file mode 100644 index 019d8d4c..00000000 --- a/examples/examples_widget.ipynb +++ /dev/null @@ -1,179 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## WorkGraph example" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "from aiida.engine import calcfunction\n", - "from aiida_workgraph import WorkGraph\n", - "\n", - "# define add calcfunction task\n", - "@calcfunction\n", - "def add(x, y):\n", - " return x + y\n", - "\n", - "# define multiply calcfunction task\n", - "@calcfunction\n", - "def multiply(x, y):\n", - " return x*y\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create WorkGraph in one shot" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg = WorkGraph(\"test_add_multiply\")\n", - "wg.add_task(add, name=\"add1\")\n", - "wg.add_task(multiply, name=\"multiply1\")\n", - "wg.add_link(wg.tasks[\"add1\"].outputs[0], wg.tasks[\"multiply1\"].inputs[\"x\"])\n", - "wg" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.tasks[\"multiply1\"].position\n", - "from aiida import load_profile, orm\n", - "load_profile()\n", - "wg.submit(wait=True, inputs = {\"add1\": {\"x\": 1, \"y\": 2}, \"multiply1\": {\"y\": 3}})\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create the workgraph step by step\n", - "First, create a empty workgraph:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "from aiida_workgraph import WorkGraph\n", - "wg = WorkGraph(\"test_add_multiply\")\n", - "wg" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.add_task(add, name=\"add1\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.add_task(multiply, name=\"multiply1\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.add_link(wg.tasks[\"add1\"].outputs[0], wg.tasks[\"multiply1\"].inputs[\"x\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.tasks.delete(\"add1\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.add_task(add, name=\"add1\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.add_link(wg.tasks[\"add1\"].outputs[0], wg.tasks[\"multiply1\"].inputs[\"x\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.links.delete(\"add1.result -> multiply1.x\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "wg.add_link(wg.tasks[\"add1\"].outputs[0], wg.tasks[\"multiply1\"].inputs[\"x\"])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.0" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}