-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TaskTrigger Refactor #2303
TaskTrigger Refactor #2303
Conversation
Just to record this information. The main memory users in the Before
After
|
lib/cylc/config.py
Outdated
("\+", "_plus_"), | ||
] | ||
# Message trigger offset regex(es). | ||
BCOMPAT_MSG_RE_C5 = re.compile(r'^(.*)\[\s*T\s*(([+-])\s*(\d+))?\s*\](.*)$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for message offsets is impacting validation so we should remove this as soon as we are confident that it is no-longer needed. In the mean time can we remove the cylc5 regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can remove any cylc-5 back compat code now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments.
lib/cylc/conditional_simplifier.py
Outdated
|
||
|
||
class ConditionalSimplifier(object): | ||
"""A class to simplify logical expressions""" | ||
RE_CONDITIONALS = "(&|\||\(|\))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can compile this regular expression?
lib/cylc/config.py
Outdated
for message in outputs.values(): | ||
if regex.match(message): | ||
raise SuiteConfigError( | ||
'ERROR: Message trigger offsets are obsolete.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can avoid looping message twice?
for message in outputs.values():
if BCOMPAT_MSG_RE_C5.match(message) or BCOMPAT_MSG_RE_C6.match(message):
# ...
lib/cylc/prerequisite.py
Outdated
m = re.match(self.__class__.CYCLE_POINT_RE, message) | ||
if m: | ||
self.target_point_strings.append(m.groups()[0]) | ||
match = re.match(self.__class__.CYCLE_POINT_RE, message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can just do:
match = CYCLE_POINT_RE.match(message)
since CYCLE_POINT_RE
is already compiled.
lib/cylc/task_trigger.py
Outdated
|
||
""" | ||
cpre = Prerequisite(point, tdef.start_point) | ||
for task_trigger in self.task_triggers: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block can probably do with some extra comments.
lib/cylc/taskdef.py
Outdated
yield (key, re.sub('\[.*\]', str(new_point), msg)) | ||
"""Yield task message outputs for initialisation of TaskOutputs.""" | ||
for key, msg in self.outputs: | ||
yield (key, re.sub('\[.*\]', str(point), msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this substitution?
Will address the database lock test failures tomorrow. |
lib/cylc/conditional_simplifier.py
Outdated
"""Convert a logical expression in a nested list back to a string""" | ||
flattened = copy.deepcopy(expr) | ||
for i in range(len(flattened)): | ||
if isinstance(flattened[i], list): | ||
flattened[i] = self.flatten_nested_expr(flattened[i]) | ||
flattened[i] = cls.flatten_nested_expr( | ||
flattened[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spurious change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more minor style comments. Change tested as working in my environment.
lib/cylc/config.py
Outdated
if lnode.output: | ||
qualifier = TaskTrigger.get_trigger_name(lnode.output) | ||
else: | ||
qualifier = TASK_OUTPUT_SUCCEEDED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if outputs and lnode.output in outputs:
# Task message.
qualifier = outputs[lnode.output]
elif lnode.output:
# Built-in qualifier.
qualifier = TaskTrigger.get_trigger_name(lnode.output)
else:
qualifier = TASK_OUTPUT_SUCCEEDED
A slightly better style? (This lines up all the assignment statements of qualifier
.)
lib/cylc/conditional_simplifier.py
Outdated
|
||
|
||
class ConditionalSimplifier(object): | ||
"""A class to simplify logical expressions""" | ||
RE_CONDITIONALS = re.compile("(&|\||\(|\))") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The combination backslash escape + pipes (or-logic) + bracket (capture) are making the regular expression very difficult to read. Perhaps better to capture a set in square bracket like this r'([&|()])'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
At the moment taskdefs store triggers in an in-efficient manner:
In this data structure the task names and qualifiers are stored three times:
This pull removes this duplication of information:
TaskTrigger
objects and conditional characters e.g.[<TaskTrigger>, '&', <TaskTrigger>]
For suites with complex conditional dependencies this has a large effect on memory usage. For the suite mentioned in #2291 the
Scheduler
object (post configure) goes from 511Mb down to 146Mb, validation shows a 22% reduction (associated with a 3% rise in CPU)For suites with simple dependencies there is a smaller saving. This pull reduces the memory usage of the complex suite by about 4%. The plot below shows the scaling results for the diamond suite:
Changes:
foo_colon_succeeded
) have been removed. ThePrerequisite
class now uses the task message alone.Prerequisite
class has been stripped of dead weight.TaskTrigger
class has been reduced down to a data object.TaskTrigger
objects are cashed so that no duplicates are created.