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

Fix minor bug in delete_nodes utility due to typo #1564

Merged
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
64 changes: 41 additions & 23 deletions aiida/backends/tests/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from aiida.orm.data import Data
from aiida.orm.node import Node
from aiida.orm.utils import load_node
from aiida.utils.capturing import Capturing
from aiida.utils.delete_nodes import delete_nodes


class TestNodeHashing(AiidaTestCase):
Expand Down Expand Up @@ -2243,8 +2245,6 @@ def _create_calls_n_returns_graph(self):
Master also creates one nodes. This allows to check whether the delete_nodes
command works as anticipated.
"""
from aiida.common.links import LinkType

in1, in2, wf, slave1, outp1, outp2, slave2, outp3, outp4 = [Node().store() for i in range(9)]
wf.add_link_from(in1, link_type=LinkType.INPUT)
slave1.add_link_from(in1, link_type=LinkType.INPUT)
Expand All @@ -2264,9 +2264,6 @@ def test_deletion_simple(self):
I'm setting up a sequence of nodes connected by data provenance links.
Testing whether I will delete the right ones.
"""
from aiida.common.links import LinkType
from aiida.utils.delete_nodes import delete_nodes

nodes = [Node().store() for i in range(15)]
uuids_check_existence = [n.uuid for n in nodes[:3]]
uuids_check_deleted = [n.uuid for n in nodes[3:]]
Expand All @@ -2286,75 +2283,78 @@ def test_deletion_simple(self):
nodes[i].add_link_from(nodes[5], link_type=LinkType.INPUT)
for i in range(10, 14):
nodes[i + 1].add_link_from(nodes[i], link_type=LinkType.INPUT)
delete_nodes((nodes[3].pk, nodes[10].pk), force=True, verbosity=0)

with Capturing():
delete_nodes((nodes[3].pk, nodes[10].pk), force=True, verbosity=2)

self._check_existence(uuids_check_existence, uuids_check_deleted)

def test_deletion_with_calls_with_returns(self):
"""
Checking the case where I follow calls and return links for deletion
"""
from aiida.utils.delete_nodes import delete_nodes
in1, in2, wf, slave1, outp1, outp2, slave2, outp3, outp4 = self._create_calls_n_returns_graph()
# The inputs are not harmed.
uuids_check_existence = (in1.uuid, in2.uuid)
# the slaves and their outputs have to disappear since calls are followed!
uuids_check_deleted = [n.uuid for n in (wf, slave1, outp1, outp2, outp3, slave2, outp4)]
delete_nodes([wf.pk], verbosity=0, force=True, follow_calls=True, follow_returns=True)

with Capturing():
delete_nodes([wf.pk], verbosity=2, force=True, follow_calls=True, follow_returns=True)

self._check_existence(uuids_check_existence, uuids_check_deleted)

def test_deletion_with_calls_no_returns(self):
"""
Checking the case where I follow calls and not return links for deletion
"""

from aiida.utils.delete_nodes import delete_nodes
in1, in2, wf, slave1, outp1, outp2, slave2, outp3, outp4 = self._create_calls_n_returns_graph()
# The inputs are not harmed.
uuids_check_existence = (in1.uuid, in2.uuid, outp4.uuid)
# the slaves and their outputs have to disappear since calls are followed!
uuids_check_deleted = [n.uuid for n in (wf, slave1, outp1, outp2, outp3, slave2)]
delete_nodes([wf.pk], verbosity=0, force=True, follow_calls=True, follow_returns=False)

with Capturing():
delete_nodes([wf.pk], verbosity=2, force=True, follow_calls=True, follow_returns=False)

self._check_existence(uuids_check_existence, uuids_check_deleted)

def test_deletion_no_calls_no_returns(self):
"""
Checking the case where I don't follow calls and also not return links for deletion
"""

from aiida.utils.delete_nodes import delete_nodes

in1, in2, wf, slave1, outp1, outp2, slave2, outp3, outp4 = self._create_calls_n_returns_graph()
# I don't follow calls, so the slaves and their output are unharmed, as well as input
uuids_check_existence = [n.uuid for n in (in1, in2, slave1, outp1, outp2, slave2, outp4)]
# the wf and it's direct output
uuids_check_deleted = [n.uuid for n in (wf, outp3)]
delete_nodes([wf.pk], verbosity=0, force=True, follow_calls=False, follow_returns=False)

with Capturing():
delete_nodes([wf.pk], verbosity=2, force=True, follow_calls=False, follow_returns=False)

self._check_existence(uuids_check_existence, uuids_check_deleted)
self._check_existence(uuids_check_existence, uuids_check_deleted)

def test_deletion_no_calls_with_returns(self):
"""
Checking the case where I follow returns and not calls for deletion
"""

from aiida.utils.delete_nodes import delete_nodes

in1, in2, wf, slave1, outp1, outp2, slave2, outp3, outp4 = self._create_calls_n_returns_graph()
# I don't follow calls, so the slaves and their output are unharmed, as well as input
uuids_check_existence = [n.uuid for n in (in1, in2, slave1, outp1, slave2)]
# the wf and it's direct output and what it returned
uuids_check_deleted = [n.uuid for n in (wf, outp3, outp2, outp4)]
delete_nodes([wf.pk], verbosity=0, force=True, follow_calls=False, follow_returns=True)

with Capturing():
delete_nodes([wf.pk], verbosity=2, force=True, follow_calls=False, follow_returns=True)

self._check_existence(uuids_check_existence, uuids_check_deleted)
self._check_existence(uuids_check_existence, uuids_check_deleted)

def test_deletion_with_returns_n_loops(self):
"""
Setting up a simple loop, to check that the following doesn't go bananas.
"""
from aiida.common.links import LinkType
from aiida.utils.delete_nodes import delete_nodes

in1, in2, wf = [Node().store() for i in range(3)]
wf.add_link_from(in1, link_type=LinkType.INPUT)
wf.add_link_from(in2, link_type=LinkType.INPUT)
Expand All @@ -2363,5 +2363,23 @@ def test_deletion_with_returns_n_loops(self):
uuids_check_existence = (in1.uuid,)
uuids_check_deleted = [n.uuid for n in (wf, in2)]

delete_nodes([wf.pk], verbosity=0, force=True, follow_returns=True)
with Capturing():
delete_nodes([wf.pk], verbosity=2, force=True, follow_returns=True)

self._check_existence(uuids_check_existence, uuids_check_deleted)

def test_delete_called_but_not_caller(self):
"""
Check that deleting a Calculation that was called by another Calculation which won't be
deleted works, even though it will raise a warning
"""
caller, called = [Calculation().store() for i in range(2)]
called.add_link_from(caller, link_type=LinkType.CALL)

uuids_check_existence = (caller.uuid, )
uuids_check_deleted = [n.uuid for n in (called, )]

with Capturing():
delete_nodes([called.pk], verbosity=2, force=True, follow_returns=True)

self._check_existence(uuids_check_existence, uuids_check_deleted)
12 changes: 6 additions & 6 deletions aiida/utils/delete_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,27 @@ def delete_nodes(pks, follow_calls=False, follow_returns=False,

if not disable_checks:
called_qb = QueryBuilder()
called_qb.append(Calculation, filters={'id':{'!in':pks_set_to_delete}}, project='id')
called_qb.append(Calculation, filters={'id': {'!in': pks_set_to_delete}}, project='id')
called_qb.append(Calculation, project='type', edge_project='label',
filters={'id':{'in':pks_set_to_delete}},
edge_filters={'type':{'==': LinkType.CALL.value}})
filters={'id': {'in': pks_set_to_delete}},
edge_filters={'type': {'==': LinkType.CALL.value}})
caller_to_called2delete = called_qb.all()

if verbosity > 0 and caller_to_called2delete:
calculation_pks_losing_called = set(zip(*caller_to_called2delete)[0])
print "\n{} calculation{} {} lose at least one called instance".format(
len(calculation_pks_losing_called),
's' if len(calculation_pks_losing_created) > 1 else '',
's' if len(calculation_pks_losing_called) > 1 else '',
'would' if dry_run else 'will')
if verbosity > 1:
print "These are the calculations that {} lose a called instance:".format('would' if dry_run else 'will')
for calc_losing_called_pk in calculation_pks_losing_called:
print ' ', load_node(calc_losing_called_pk)

created_qb = QueryBuilder()
created_qb.append(Calculation, filters={'id':{'!in':pks_set_to_delete}}, project='id')
created_qb.append(Calculation, filters={'id':{'!in': pks_set_to_delete}}, project='id')
created_qb.append(Data, project='type', edge_project='label',
filters={'id':{'in':pks_set_to_delete}},
filters={'id':{'in': pks_set_to_delete}},
edge_filters={'type':{'==':LinkType.CREATE.value}})

creator_to_created2delete = created_qb.all()
Expand Down