2023-08-23 19:28:45 +02:00
|
|
|
# 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
|
2023-08-24 14:44:21 +02:00
|
|
|
|
|
|
|
function is_valid(graph::DAG, nr::NodeReduction)
|
|
|
|
@assert is_valid_node_reduction_input(graph, nr.input)
|
|
|
|
@assert nr in graph.possibleOperations.nodeReductions "NodeReduction is not part of the graph's possible operations!"
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function is_valid(graph::DAG, ns::NodeSplit)
|
|
|
|
@assert is_valid_node_split_input(graph, ns.input)
|
|
|
|
@assert ns in graph.possibleOperations.nodeSplits "NodeSplit is not part of the graph's possible operations!"
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function is_valid(graph::DAG, nf::NodeFusion)
|
|
|
|
@assert is_valid_node_fusion_input(graph, nf.input[1], nf.input[2], nf.input[3])
|
|
|
|
@assert nf in graph.possibleOperations.nodeFusions "NodeFusion is not part of the graph's possible operations!"
|
|
|
|
return true
|
|
|
|
end
|