62 lines
2.1 KiB
Julia
62 lines
2.1 KiB
Julia
|
# functions to throw assertion errors for inconsistent or wrong node operations
|
||
|
# should be called with @assert
|
||
|
# the functions throw their own errors though, to still have helpful error messages
|
||
|
|
||
|
function is_valid_node_fusion_input(graph::DAG, n1::ComputeTaskNode, n2::DataTaskNode, n3::ComputeTaskNode)
|
||
|
if !(n1 in graph) || !(n2 in graph) || !(n3 in graph)
|
||
|
throw(AssertionError("[Node Fusion] The given nodes are not part of the given graph"))
|
||
|
end
|
||
|
|
||
|
if !is_child(n1, n2) || !is_child(n2, n3) || !is_parent(n3, n2) || !is_parent(n2, n1)
|
||
|
throw(AssertionError("[Node Fusion] The given nodes are not connected by edges which is required for node fusion"))
|
||
|
end
|
||
|
|
||
|
if length(n2.parents) > 1
|
||
|
throw(AssertionError("[Node Fusion] The given data node has more than one parent"))
|
||
|
end
|
||
|
if length(n2.children) > 1
|
||
|
throw(AssertionError("[Node Fusion] The given data node has more than one child"))
|
||
|
end
|
||
|
if length(n1.parents) > 1
|
||
|
throw(AssertionError("[Node Fusion] The given n1 has more than one parent"))
|
||
|
end
|
||
|
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
function is_valid_node_reduction_input(graph::DAG, nodes::Vector{Node})
|
||
|
for n in nodes
|
||
|
if n ∉ graph
|
||
|
throw(AssertionError("[Node Reduction] The given nodes are not part of the given graph"))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
t = typeof(nodes[1].task)
|
||
|
for n in nodes
|
||
|
if typeof(n.task) != t
|
||
|
throw(AssertionError("[Node Reduction] The given nodes are not of the same type"))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
n1_children = nodes[1].children
|
||
|
for n in nodes
|
||
|
if Set(n1_children) != Set(n.children)
|
||
|
throw(AssertionError("[Node Reduction] The given nodes do not have equal prerequisite nodes which is required for node reduction"))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
function is_valid_node_split_input(graph::DAG, n1::Node)
|
||
|
if n1 ∉ graph
|
||
|
throw(AssertionError("[Node Split] The given node is not part of the given graph"))
|
||
|
end
|
||
|
|
||
|
if length(n1.parents) <= 1
|
||
|
throw(AssertionError("[Node Split] The given node does not have multiple parents which is required for node split"))
|
||
|
end
|
||
|
|
||
|
return true
|
||
|
end
|