1- from collections import defaultdict
21import networkx as nx
32from networkx import Graph
43from precice_config_graph .nodes import (
@@ -73,7 +72,7 @@ class DataUsedNotReadWrittenViolation(Violation):
7372 severity = Severity .WARNING
7473
7574 def __init__ (
76- self , data_node : DataNode , mesh : MeshNode , writers : list [ParticipantNode ]
75+ self , data_node : DataNode , mesh : MeshNode , writers : list [ParticipantNode ]
7776 ):
7877 self .data_node = data_node
7978 self .mesh = mesh
@@ -108,7 +107,7 @@ class DataUsedReadNotWrittenViolation(Violation):
108107 severity = Severity .ERROR
109108
110109 def __init__ (
111- self , data_node : DataNode , mesh : MeshNode , readers : list [ParticipantNode ]
110+ self , data_node : DataNode , mesh : MeshNode , readers : list [ParticipantNode ]
112111 ):
113112 self .data_node = data_node
114113 self .mesh = mesh
@@ -141,7 +140,7 @@ class DataNotExchangedViolation(Violation):
141140 severity = Severity .ERROR
142141
143142 def __init__ (
144- self , data_node : DataNode , writer : ParticipantNode , reader : ParticipantNode
143+ self , data_node : DataNode , writer : ParticipantNode , reader : ParticipantNode
145144 ):
146145 self .data_node = data_node
147146 self .writer = writer
@@ -175,7 +174,7 @@ def check(self, graph: Graph) -> list[Violation]:
175174 meshes : list [MeshNode ] = []
176175 writers : list [ParticipantNode ] = []
177176 readers : list [ParticipantNode ] = []
178- readers_per_writer : dict [ParticipantNode : list [ParticipantNode ]] = {}
177+ readers_per_writer : dict [ParticipantNode : list [ParticipantNode ]] = {}
179178 readers_per_mesh : dict [MeshNode , list [ParticipantNode ]] = {}
180179 writers_per_mesh : dict [MeshNode , list [ParticipantNode ]] = {}
181180
@@ -275,8 +274,8 @@ def check(self, graph: Graph) -> list[Violation]:
275274 for provide_mesh_neighbor in graph .neighbors (provide_mesh ):
276275 # Only use read-data if it reads current data_node
277276 if (
278- isinstance (provide_mesh_neighbor , ReadDataNode )
279- and provide_mesh_neighbor .data == data_node
277+ isinstance (provide_mesh_neighbor , ReadDataNode )
278+ and provide_mesh_neighbor .data == data_node
280279 ):
281280 readers_per_writer [writer ].append (
282281 provide_mesh_neighbor .participant
@@ -307,36 +306,36 @@ def check(self, graph: Graph) -> list[Violation]:
307306 if len (potential_reader .exports ) > 0 :
308307 readers_per_writer [writer ].append (potential_reader )
309308 for potential_reader_neighbor in graph .neighbors (
310- potential_reader
309+ potential_reader
311310 ):
312311 if (
313- isinstance (
314- potential_reader_neighbor , ReadDataNode
315- )
316- and potential_reader_neighbor .data == data_node
312+ isinstance (
313+ potential_reader_neighbor , ReadDataNode
314+ )
315+ and potential_reader_neighbor .data == data_node
317316 ):
318317 readers_per_writer [writer ].append (
319318 potential_reader
320319 )
321320 # Watchpoint, Watch-integral and export do not specify data
322321 elif isinstance (
323- potential_reader_neighbor , WatchPointNode
322+ potential_reader_neighbor , WatchPointNode
324323 ):
325324 readers_per_writer [writer ].append (
326325 potential_reader
327326 )
328327 elif isinstance (
329- potential_reader_neighbor , WatchIntegralNode
328+ potential_reader_neighbor , WatchIntegralNode
330329 ):
331330 readers_per_writer [writer ].append (
332331 potential_reader
333332 )
334333 elif isinstance (
335- potential_reader_neighbor , ActionNode
334+ potential_reader_neighbor , ActionNode
336335 ):
337336 # Actions can have many source data; check for current data_node
338337 for (
339- source
338+ source
340339 ) in potential_reader_neighbor .source_data :
341340 if source == data_node :
342341 readers_per_writer [writer ].append (
@@ -373,8 +372,8 @@ def check(self, graph: Graph) -> list[Violation]:
373372 # Otherwise, there needs to be an exchange of data between them.
374373 else :
375374 if (
376- writer not in data_flow_graph .nodes
377- or reader not in data_flow_graph .nodes
375+ writer not in data_flow_graph .nodes
376+ or reader not in data_flow_graph .nodes
378377 ):
379378 # One of writer/reader is not connected through an exchange involving data_node
380379 violations .append (
@@ -432,7 +431,7 @@ def check(self, graph: Graph) -> list[Violation]:
432431
433432
434433def get_provide_meshes_for_data (
435- participant : ParticipantNode , data : DataNode
434+ participant : ParticipantNode , data : DataNode
436435) -> list [MeshNode ]:
437436 """
438437 This method returns all meshes provided by the given participant that use the given data.
@@ -464,14 +463,14 @@ def filter_use_read_write_data(node) -> bool:
464463 True, if the node is a data-, read-/write-, action- or mesh node.
465464 """
466465 return (
467- isinstance (node , DataNode )
468- or isinstance (node , MeshNode )
469- or isinstance (node , ReadDataNode )
470- or isinstance (node , ExportNode )
471- or isinstance (node , WatchPointNode )
472- or isinstance (node , WatchIntegralNode )
473- or isinstance (node , WriteDataNode )
474- or isinstance (node , ActionNode )
466+ isinstance (node , DataNode )
467+ or isinstance (node , MeshNode )
468+ or isinstance (node , ReadDataNode )
469+ or isinstance (node , ExportNode )
470+ or isinstance (node , WatchPointNode )
471+ or isinstance (node , WatchIntegralNode )
472+ or isinstance (node , WriteDataNode )
473+ or isinstance (node , ActionNode )
475474 )
476475
477476
@@ -485,7 +484,7 @@ def filter_data_exchange(node) -> bool:
485484
486485
487486def append_participant_to_map (
488- dictionary : dict [MeshNode : list [ParticipantNode ]], mesh , participant
487+ dictionary : dict [MeshNode : list [ParticipantNode ]], mesh , participant
489488):
490489 """
491490 This method appends the given participant to the given map for an entry 'mesh'.
0 commit comments