Skip to content

Commit d396411

Browse files
committed
Fix duplicate task triggers
1 parent 03b6e2e commit d396411

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

changes.d/6625.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Efficiency improvement: avoid storing duplicate information on graph triggers.

cylc/flow/task_trigger.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
from typing import TYPE_CHECKING, Tuple
17+
from typing import (
18+
TYPE_CHECKING,
19+
Optional,
20+
Tuple,
21+
)
1822

1923
from cylc.flow.cycling.loader import (
2024
get_interval,
@@ -50,9 +54,16 @@ class TaskTrigger:
5054
'offset_is_irregular', 'offset_is_absolute',
5155
'offset_is_from_icp', 'initial_point']
5256

53-
def __init__(self, task_name, cycle_point_offset, output,
54-
offset_is_irregular=False, offset_is_absolute=False,
55-
offset_is_from_icp=False, initial_point=None):
57+
def __init__(
58+
self,
59+
task_name: str,
60+
cycle_point_offset: str,
61+
output: str,
62+
offset_is_irregular: bool = False,
63+
offset_is_absolute: bool = False,
64+
offset_is_from_icp: bool = False,
65+
initial_point: 'Optional[PointBase]' = None,
66+
):
5667
self.task_name = task_name
5768
self.cycle_point_offset = cycle_point_offset
5869
self.output = output
@@ -147,7 +158,24 @@ def __str__(self):
147158
else:
148159
return '%s:%s' % (self.task_name, self.output)
149160

150-
__repr__ = __str__
161+
def __repr__(self) -> str:
162+
return f"<{type(self).__name__} {self}>"
163+
164+
def __hash__(self) -> int:
165+
return hash((
166+
self.task_name,
167+
self.cycle_point_offset,
168+
self.output,
169+
self.offset_is_irregular,
170+
self.offset_is_from_icp,
171+
self.offset_is_absolute,
172+
self.initial_point,
173+
))
174+
175+
def __eq__(self, other: object) -> bool:
176+
if not isinstance(other, TaskTrigger):
177+
return NotImplemented
178+
return hash(self) == hash(other)
151179

152180
@staticmethod
153181
def standardise_name(name):

cylc/flow/taskdef.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(self, name, rtcfg, start_point, initial_point):
183183
self.dependencies: Dict[SequenceBase, List[Dependency]] = {}
184184
self.outputs = {} # {output: (message, is_required)}
185185
self.graph_children: Dict[
186-
SequenceBase, Dict[str, List[Tuple[str, TaskTrigger]]]
186+
SequenceBase, Dict[str, Set[Tuple[str, TaskTrigger]]]
187187
] = {}
188188
self.graph_parents: Dict[
189189
SequenceBase, Set[Tuple[str, TaskTrigger]]
@@ -250,8 +250,8 @@ def add_graph_child(
250250
self.graph_children.setdefault(
251251
sequence, {}
252252
).setdefault(
253-
trigger.output, []
254-
).append((taskname, trigger))
253+
trigger.output, set()
254+
).add((taskname, trigger))
255255

256256
def add_graph_parent(
257257
self, trigger: 'TaskTrigger', parent: str, sequence: 'SequenceBase'

0 commit comments

Comments
 (0)