Skip to content

Commit 0aed482

Browse files
Merge pull request #2 from precice/update-enums
change import location of enums
2 parents 9da2b95 + 5dd582d commit 0aed482

File tree

10 files changed

+286
-292
lines changed

10 files changed

+286
-292
lines changed

preciceconfigcheck/rules/compositional_coupling.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from networkx import Graph
33
from precice_config_graph.nodes import (
44
CouplingSchemeNode,
5-
MultiCouplingSchemeNode,
65
ParticipantNode,
7-
CouplingSchemeType,
86
)
7+
import precice_config_graph.enums as e
98
from preciceconfigcheck.rule import Rule
109
from preciceconfigcheck.rule_utils import format_list
1110
from preciceconfigcheck.severity import Severity
@@ -40,8 +39,8 @@ def check(self, graph: Graph) -> list[Violation]:
4039
g1 = nx.subgraph_view(graph, filter_node=filter_coupling_scheme_nodes)
4140
for coupling in g1.nodes():
4241
if (
43-
coupling.type == CouplingSchemeType.SERIAL_EXPLICIT
44-
or coupling.type == CouplingSchemeType.SERIAL_IMPLICIT
42+
coupling.type == e.CouplingSchemeType.SERIAL_EXPLICIT
43+
or coupling.type == e.CouplingSchemeType.SERIAL_IMPLICIT
4544
):
4645
# Directed edge between first and second participant
4746
coupling_edges += [

preciceconfigcheck/rules/coupling_scheme_mapping.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
ExchangeNode,
77
MeshNode,
88
MappingNode,
9-
Direction,
109
DataNode,
1110
)
11+
import precice_config_graph.enums as e
1212

1313
from preciceconfigcheck.rule import Rule
1414
from preciceconfigcheck.severity import Severity
@@ -41,15 +41,15 @@ def __init__(
4141
self.exchange_mesh = exchange_mesh
4242
if exchange_mesh in from_participant.provide_meshes:
4343
# from_participant writes to own mesh, sends it to to_participant, who maps it to his own mesh, and reads from it
44-
self.direction = Direction.READ
44+
self.direction = e.Direction.READ
4545
self.mapper = to_participant
4646
self.non_mapper = from_participant
4747
self.mesh_owner = from_participant
4848
self.from_string = f"from {self.exchange_mesh.name}"
4949
self.to_string = f"to a mesh provided by {to_participant.name}"
5050
else:
5151
# from_participant writes to own mesh, maps it to to_participants mesh, sends it to to_participant, who reads from it
52-
self.direction = Direction.WRITE
52+
self.direction = e.Direction.WRITE
5353
self.mapper = from_participant
5454
self.non_mapper = to_participant
5555
self.mesh_owner = to_participant
@@ -93,13 +93,13 @@ def __init__(
9393
self.exchange_mesh = exchange_mesh
9494
if exchange_mesh in from_participant.provide_meshes:
9595
# from_participant writes to own mesh, sends it to to_participant, who maps it to his own mesh, and reads from it
96-
self.direction = Direction.READ
96+
self.direction = e.Direction.READ
9797
self.mapper = to_participant
9898
self.non_mapper = from_participant
9999
self.mesh_owner = from_participant
100100
else:
101101
# from_participant writes to own mesh, maps it to to_participants mesh, sends it to to_participant, who reads from it
102-
self.direction = Direction.WRITE
102+
self.direction = e.Direction.WRITE
103103
self.mapper = from_participant
104104
self.non_mapper = to_participant
105105
self.mesh_owner = to_participant
@@ -150,7 +150,7 @@ def check(self, graph: Graph) -> list[Violation]:
150150
has_correct_mapping: bool = any(
151151
mapping_fits_exchange(
152152
mapping,
153-
Direction.READ,
153+
e.Direction.READ,
154154
from_participant,
155155
to_participant,
156156
exchange_mesh,
@@ -184,7 +184,7 @@ def check(self, graph: Graph) -> list[Violation]:
184184
has_correct_mapping: bool = any(
185185
mapping_fits_exchange(
186186
mapping,
187-
Direction.WRITE,
187+
e.Direction.WRITE,
188188
from_participant,
189189
to_participant,
190190
exchange_mesh,
@@ -235,7 +235,7 @@ def filter_coupling_nodes(
235235

236236
def mapping_fits_exchange(
237237
mapping: MappingNode,
238-
direction: Direction,
238+
direction: e.Direction,
239239
from_participant: ParticipantNode,
240240
to_participant: ParticipantNode,
241241
exchange_mesh: MeshNode,
@@ -252,13 +252,13 @@ def mapping_fits_exchange(
252252
"""
253253
if mapping.direction != direction:
254254
return False
255-
if direction == Direction.WRITE:
255+
if direction == e.Direction.WRITE:
256256
# For direction-write, the mesh used in the exchange needs to be by to-participant
257257
if exchange_mesh not in to_participant.provide_meshes:
258258
return False
259259
if exchange_mesh != mapping.to_mesh:
260260
return False
261-
elif direction == Direction.READ:
261+
elif direction == e.Direction.READ:
262262
# For direction-read, the mesh used in the exchange needs to be by from-participant
263263
if exchange_mesh not in from_participant.provide_meshes:
264264
return False

preciceconfigcheck/rules/data_use_read_write.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import defaultdict
21
import networkx as nx
32
from networkx import Graph
43
from 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

434433
def 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

487486
def 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'.

preciceconfigcheck/rules/m2n_exchange.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def check(self, graph: Graph) -> list[Violation]:
8585
k2l_connector: ParticipantNode = k2l.connector
8686
# Duplicates with same connector and same acceptor participants
8787
if (
88-
m2n_acceptor == k2l_acceptor
89-
and m2n_connector == k2l_connector
90-
and not self.contains_violation(
91-
violations, m2n_acceptor, m2n_connector
92-
)
88+
m2n_acceptor == k2l_acceptor
89+
and m2n_connector == k2l_connector
90+
and not self.contains_violation(
91+
violations, m2n_acceptor, m2n_connector
92+
)
9393
):
9494
violations.append(
9595
self.DuplicateM2NExchangeViolation(
@@ -99,11 +99,11 @@ def check(self, graph: Graph) -> list[Violation]:
9999
# Check for duplicates "in the other direction":
100100
# This can be removed if acceptor / connector roles do matter in the future.
101101
elif (
102-
m2n_acceptor == k2l_connector
103-
and m2n_connector == k2l_acceptor
104-
and not self.contains_violation(
105-
violations, m2n_acceptor, m2n_connector
106-
)
102+
m2n_acceptor == k2l_connector
103+
and m2n_connector == k2l_acceptor
104+
and not self.contains_violation(
105+
violations, m2n_acceptor, m2n_connector
106+
)
107107
):
108108
violations.append(
109109
self.DuplicateM2NExchangeViolation(
@@ -115,10 +115,10 @@ def check(self, graph: Graph) -> list[Violation]:
115115

116116
# Helper functions
117117
def contains_violation(
118-
self,
119-
violations: list[Violation],
120-
participant1: ParticipantNode,
121-
participant2: ParticipantNode,
118+
self,
119+
violations: list[Violation],
120+
participant1: ParticipantNode,
121+
participant2: ParticipantNode,
122122
) -> bool:
123123
"""
124124
This function tests whether there already exists a DuplicateM2NExchangeViolation between two participants.
@@ -131,13 +131,13 @@ def contains_violation(
131131
if isinstance(violation, self.DuplicateM2NExchangeViolation):
132132
# Check if any DuplicateM2NExchangeViolation contains these two participants
133133
if (
134-
violation.participant1 == participant1
135-
and violation.participant2 == participant2
134+
violation.participant1 == participant1
135+
and violation.participant2 == participant2
136136
):
137137
return True
138138
elif (
139-
violation.participant1 == participant2
140-
and violation.participant2 == participant1
139+
violation.participant1 == participant2
140+
and violation.participant2 == participant1
141141
):
142142
return True
143143
return False

0 commit comments

Comments
 (0)