Skip to content
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

fix CPF wall_clock offset precision constraint #6431

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

dwsutherland
Copy link
Member

@dwsutherland dwsutherland commented Oct 17, 2024

closes #6423

[scheduler]
    cycle point format = CCYYMMDDThh
    allow implicit tasks = True
[scheduling]
    initial cycle point = 20241017T22
    [[xtriggers]]
        clock_PT25M31S = wall_clock(offset=PT25M31S):PT20S
    [[graph]]
        T-00 = """
@clock_PT25M31S => a
"""
[runtime]
    [[root]]
        script = sleep $((1 + $RANDOM % 10))

image

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests added.
  • Changelog entry included if this is a change that can affect users
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@dwsutherland dwsutherland added this to the 8.3.6 milestone Oct 17, 2024
@dwsutherland dwsutherland self-assigned this Oct 17, 2024
@dwsutherland dwsutherland changed the base branch from master to 8.3.x October 17, 2024 23:19
@dwsutherland dwsutherland changed the title Wclock offset cpformat fix CPF wall_clock offset precision constraint Oct 17, 2024
@hjoliver
Copy link
Member

[x] Existing tests cover.

Presumably not, as we've been living with the bug?

@dwsutherland
Copy link
Member Author

[x] Existing tests cover.

Presumably not, as we've been living with the bug?

Well coverage is 100%, and trigger offsets are tested ... But I could add a test that has CPF at lower resolution than offset

@hjoliver
Copy link
Member

Yeah worth doing that I think.

@dwsutherland
Copy link
Member Author

Yeah worth doing that I think.

Good thing I tried.. Found a way to break my solution, and have been working on various solutions all afternoon..
Will have it up by this evening.

@dwsutherland
Copy link
Member Author

Tests added..

The solution had to ensure TimePoint + Duration were added together to make sure years and months were properly calculated before converting to seconds since unix epoc.

@dwsutherland dwsutherland force-pushed the wclock-offset-cpformat branch 2 times, most recently from 806fe1f to 3f009c1 Compare October 18, 2024 07:17
@oliver-sanders oliver-sanders added bug Something is wrong :( priority-1 A top pririty issue, e.g. a severe bug that affects multiple users labels Oct 18, 2024
@@ -0,0 +1 @@
The `cycle point format` was imposing an undesirable constraint on `wall_clock` offsets, this has been fixed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `cycle point format` was imposing an undesirable constraint on `wall_clock` offsets, this has been fixed.
Allowed `wall_clock` offsets to use smaller precision than the `cycle point format` (e.g. `wall_clock(offset="PT1M")` in combination with `cycle point format = CCYY`).

Copy link
Member Author

@dwsutherland dwsutherland Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well technically they were capable of it before (the last 10 years in Cylc7 at least), but some change broke it causing this constraint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but I prefer @oliver-sanders wording here, in terms of clarity for users.

Copy link
Member

@MetRonnie MetRonnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 👍 Can actually be even simpler

Comment on lines 426 to 436
point_time = point_parse(str(point))
if offset_str == 'P0Y':
trigger_time = point
trigger_time = point_time
else:
trigger_time = point + ISO8601Interval(offset_str)

offset = int(
point_parse(str(trigger_time)).seconds_since_unix_epoch)
self.clock_trigger_times[offset_str] = offset
trigger_time = (
point_parse(
point_time.__str__(strftime_format='%Y%m%dT%H%M%S'),
'%Y%m%dT%H%M%S'
)
+ interval_parse(offset_str)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to mess with the strftime_format:

Suggested change
point_time = point_parse(str(point))
if offset_str == 'P0Y':
trigger_time = point
trigger_time = point_time
else:
trigger_time = point + ISO8601Interval(offset_str)
offset = int(
point_parse(str(trigger_time)).seconds_since_unix_epoch)
self.clock_trigger_times[offset_str] = offset
trigger_time = (
point_parse(
point_time.__str__(strftime_format='%Y%m%dT%H%M%S'),
'%Y%m%dT%H%M%S'
)
+ interval_parse(offset_str)
)
# Convert ISO8601Point into metomi-isodatetime TimePoint at full
# second precision (N.B. it still dumps at the same precision
# as workflow cycle point format):
point_time = point_parse(str(point))
if offset_str == 'P0Y':
trigger_time = point_time
else:
trigger_time = point_time + interval_parse(offset_str)

Copy link
Member Author

@dwsutherland dwsutherland Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way! shocking .. Just tested this and it worked..

image

Ah I think I know where my confusion was ... I was originally converting these objects back to ISO8601Point and ISO8601Interval adding them together then parsing them again (with the string of the result) but you get a dump format and epoc seconds the same as the CPF (trimmed to that precision)...

The TimePoint object also has dump format I assumed they behaved the same and/or this was inherited. Which the dump format was the same, but obviously your suggestion shows the epoc seconds aren't truncated... Doh!

Reverting things to this.. Thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(p.s. sorry, should have merged yours in first then rebased)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I stuck a breakpoint in there and got confused by the dump format precision for a while 😄 Hopefully the comment I included makes it clear for people debugging in the future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to change this file actually, see above comment

Copy link
Member Author

@dwsutherland dwsutherland Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted above! thanks again

@MetRonnie MetRonnie merged commit 0a88f7a into cylc:8.3.x Oct 21, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong :( priority-1 A top pririty issue, e.g. a severe bug that affects multiple users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xtrigger wall_clock offset trimmed to cycle point format
4 participants