Skip to content

Commit

Permalink
Remove property type from node-graph (aiidateam#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeigerJ2 committed Sep 13, 2024
1 parent 6d30057 commit 36a0456
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
32 changes: 30 additions & 2 deletions aiida_workgraph/properties/builtins.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from typing import Dict, List, Union, Callable
from aiida_workgraph.property import TaskProperty
from node_graph.serializer import SerializeJson
from node_graph.properties.builtins import PropertyVector, PropertyAny
from node_graph.serializer import SerializeJson, SerializePickle
from aiida import orm


class PropertyAny(TaskProperty, SerializePickle):
"""A new class for Any type."""

identifier: str = "workgraph.any"
data_type = "Any"

def __init__(self, name, description="", default=None, update=None) -> None:
super().__init__(name, description, default, update)


class PropertyInt(TaskProperty, SerializeJson):
"""A new class for integer type."""

Expand Down Expand Up @@ -278,6 +287,25 @@ def set_value(self, value: Union[Dict, orm.Dict, str]) -> None:
raise Exception("{} is not a dict.".format(value))


# ====================================
class PropertyVector(TaskProperty, SerializePickle):
"""Vector property"""

identifier: str = "workgraph.vector"
data_type = "Vector"

def __init__(self, name, description="", size=3, default=[], update=None) -> None:
super().__init__(name, description, default, update)
self.size = size

def copy(self):
p = self.__class__(
self.name, self.description, self.size, self.value, self.update
)
p.value = self.value
return p


class PropertyAiiDAIntVector(PropertyVector):
"""A new class for integer vector type."""

Expand Down
9 changes: 6 additions & 3 deletions tests/test_socket.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pytest
from aiida_workgraph import WorkGraph, task
from aiida import orm
from typing import Any


@pytest.mark.parametrize(
"data_type, socket_type",
"data_type, identifier",
(
(Any, "workgraph.any"),
(int, "workgraph.int"),
(float, "workgraph.float"),
(bool, "workgraph.bool"),
Expand All @@ -16,14 +18,15 @@
(orm.Bool, "workgraph.aiida_bool"),
),
)
def test_type_mapping(data_type, socket_type) -> None:
def test_type_mapping(data_type, identifier) -> None:
"""Test the mapping of data types to socket types."""

@task()
def add(x: data_type):
pass

assert add.task().inputs["x"].identifier == socket_type
assert add.task().inputs["x"].identifier == identifier
assert add.task().inputs["x"].property.identifier == identifier


def test_socket(decorated_multiply) -> None:
Expand Down

0 comments on commit 36a0456

Please sign in to comment.