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

Rename node class for workfunctions #2189

Merged
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
4 changes: 2 additions & 2 deletions aiida/backends/tests/cmdline/commands/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_run_workfunction(self):
"""
import tempfile
from aiida.orm import load_node
from aiida.orm.calculation.function import FunctionCalculation
from aiida.orm.node.process import WorkFunctionNode

script_content = """
#!/usr/bin/env python
Expand Down Expand Up @@ -63,6 +63,6 @@ def wf():
node = load_node(pk)

# Verify that the node has the correct function name and content
self.assertTrue(isinstance(node, FunctionCalculation))
self.assertTrue(isinstance(node, WorkFunctionNode))
self.assertEqual(node.function_name, 'wf')
self.assertEqual(open(node.function_source_file, 'r').read(), script_content)
8 changes: 4 additions & 4 deletions aiida/backends/tests/cmdline/commands/test_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from aiida.cmdline.commands import cmd_work
from aiida.common.links import LinkType
from aiida.common.log import LOG_LEVEL_REPORT
from aiida.orm.calculation.function import FunctionCalculation
from aiida.orm.node.process import WorkFunctionNode
from aiida.orm.calculation.work import WorkCalculation


Expand Down Expand Up @@ -50,13 +50,13 @@ def test_list(self):

calcs = []

# Create 6 FunctionCalculations and WorkCalculations (one for each ProcessState)
# Create 6 WorkFunctionNodes and WorkCalculations (one for each ProcessState)
for state in ProcessState:

calc = FunctionCalculation()
calc = WorkFunctionNode()
calc._set_process_state(state)

# Set the FunctionCalculation as successful
# Set the WorkFunctionNode as successful
if state == ProcessState.FINISHED:
calc._set_exit_status(0)

Expand Down
5 changes: 3 additions & 2 deletions aiida/backends/tests/cmdline/params/types/test_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.params import options
from aiida.cmdline.params.types import CalculationParamType
from aiida.orm import Calculation, FunctionCalculation, InlineCalculation, JobCalculation, WorkCalculation
from aiida.orm import Calculation, InlineCalculation, JobCalculation, WorkCalculation
from aiida.orm.node.process import WorkFunctionNode
from aiida.orm.utils.loaders import OrmEntityLoader


Expand All @@ -36,7 +37,7 @@ def setUpClass(cls):
cls.entity_01 = Calculation().store()
cls.entity_02 = Calculation().store()
cls.entity_03 = Calculation().store()
cls.entity_04 = FunctionCalculation()
cls.entity_04 = WorkFunctionNode()
cls.entity_05 = InlineCalculation()
cls.entity_06 = JobCalculation()
cls.entity_07 = WorkCalculation()
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/tests/work/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from __future__ import print_function
from __future__ import absolute_import
from aiida.backends.testbase import AiidaTestCase
from aiida.orm.calculation.function import FunctionCalculation
from aiida.orm.node.process import WorkFunctionNode
from aiida.orm.calculation.work import WorkCalculation
from aiida.orm.data.int import Int
from aiida.work import run, run_get_node, run_get_pid, Process, WorkChain, workfunction
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_workfunction_run(self):
def test_workfunction_run_get_node(self):
result, node = run_get_node(add, a=self.a, b=self.b)
self.assertEquals(result, self.result)
self.assertTrue(isinstance(node, FunctionCalculation))
self.assertTrue(isinstance(node, WorkFunctionNode))

def test_workfunction_run_get_pid(self):
result, pid = run_get_pid(add, a=self.a, b=self.b)
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/tests/work/test_workfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from aiida.orm.data.int import Int
from aiida.orm.data.str import Str
from aiida.orm import load_node
from aiida.orm.calculation.function import FunctionCalculation
from aiida.orm.node.process import WorkFunctionNode
from aiida.work import run, run_get_node, submit, workfunction, Process, ExitCode

DEFAULT_INT = 256
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_launchers(self):
result, node = run_get_node(self.wf_return_true)
self.assertTrue(result)
self.assertEqual(result, get_true_node())
self.assertTrue(isinstance(node, FunctionCalculation))
self.assertTrue(isinstance(node, WorkFunctionNode))

with self.assertRaises(AssertionError):
submit(self.wf_return_true)
Expand Down
4 changes: 2 additions & 2 deletions aiida/cmdline/commands/cmd_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def work_list(all_entries, process_state, exit_status, failed, past_days, limit,
"""Show a list of work calculations that are still running."""
from tabulate import tabulate
from aiida.cmdline.utils.common import print_last_process_state_change
from aiida.orm.calculation.function import FunctionCalculation
from aiida.orm.node.process import WorkFunctionNode
from aiida.orm.calculation.work import WorkCalculation

node_types = (WorkCalculation, FunctionCalculation)
node_types = (WorkCalculation, WorkFunctionNode)

builder = CalculationQueryBuilder()
filters = builder.get_filters(all_entries, process_state, exit_status, failed, node_types=node_types)
Expand Down
3 changes: 2 additions & 1 deletion aiida/cmdline/utils/query/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def get_query_set(self, filters=None, order_by=None, past_days=None, limit=None)
import datetime

from aiida.orm.calculation import Calculation
from aiida.orm.node.process import ProcessNode
from aiida.orm.querybuilder import QueryBuilder
from aiida.utils import timezone

Expand All @@ -101,7 +102,7 @@ def get_query_set(self, filters=None, order_by=None, past_days=None, limit=None)
filters['ctime'] = {'>': timezone.now() - datetime.timedelta(days=past_days)}

builder = QueryBuilder()
builder.append(cls=Calculation, filters=filters, project=projected_attributes, tag='calculation')
builder.append(cls=(Calculation, ProcessNode), filters=filters, project=projected_attributes, tag='calculation')

if order_by is not None:
builder.order_by({'calculation': order_by})
Expand Down
3 changes: 1 addition & 2 deletions aiida/orm/calculation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
from aiida.orm.implementation.calculation import Calculation, JobCalculation
from .inline import *
from .work import WorkCalculation
from .function import FunctionCalculation

__all__ = ['Calculation', 'JobCalculation', 'WorkCalculation', 'FunctionCalculation'] + inline.__all__
__all__ = ['Calculation', 'JobCalculation', 'WorkCalculation'] + inline.__all__
6 changes: 4 additions & 2 deletions aiida/orm/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ def created_by(self):
@override
def add_link_from(self, src, label=None, link_type=LinkType.UNSPECIFIED):
from aiida.orm.calculation import Calculation
from aiida.orm.node.process import ProcessNode

if link_type is LinkType.CREATE and \
len(self.get_inputs(link_type=LinkType.CREATE)) > 0:
raise ValueError("At most one CREATE node can enter a data node")

if not isinstance(src, Calculation):
if not isinstance(src, (Calculation, ProcessNode)):
raise ValueError("Links entering a data object can only be of type calculation")

return super(Data, self).add_link_from(src, label, link_type)
Expand All @@ -168,7 +169,8 @@ def _linking_as_output(self, dest, link_type):
An output of a data can only be a calculation
"""
from aiida.orm.calculation import Calculation
if not isinstance(dest, Calculation):
from aiida.orm.node.process import ProcessNode
if not isinstance(dest, (Calculation, ProcessNode)):
raise ValueError("The output of a data node can only be a calculation")

return super(Data, self)._linking_as_output(dest, link_type)
Expand Down
6 changes: 4 additions & 2 deletions aiida/orm/implementation/general/calculation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,13 @@ def _linking_as_output(self, dest, link_type):
:raise: ValueError if a link from self to dest is not allowed.
"""
from aiida.orm.data import Data
from aiida.orm.node.process import ProcessNode

if link_type is LinkType.CREATE or link_type is LinkType.RETURN:
if not isinstance(dest, Data):
raise ValueError('The output of a calculation node can only be a data node')
elif link_type is LinkType.CALL:
if not isinstance(dest, AbstractCalculation):
if not isinstance(dest, (AbstractCalculation, ProcessNode)):
raise ValueError('Call links can only link two calculations')
else:
raise ValueError('Calculation cannot have links of type {} as output'.format(link_type))
Expand All @@ -569,12 +570,13 @@ def add_link_from(self, src, label=None, link_type=LinkType.INPUT):
"""
from aiida.orm.code import Code
from aiida.orm.data import Data
from aiida.orm.node.process import ProcessNode

if link_type is LinkType.INPUT:
if not isinstance(src, (Data, Code)):
raise ValueError('Nodes entering calculation as input link can only be of type data or code')
elif link_type is LinkType.CALL:
if not isinstance(src, AbstractCalculation):
if not isinstance(src, (AbstractCalculation, ProcessNode)):
raise ValueError('Call links can only link two calculations')
else:
raise ValueError('Calculation cannot have links of type {} as input'.format(link_type))
Expand Down
Loading