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 reference of schedule #79

Merged
merged 1 commit into from
Sep 23, 2024
Merged

Fix reference of schedule #79

merged 1 commit into from
Sep 23, 2024

Conversation

Sbozzolo
Copy link
Member

Schedules have to be unique objects because they store information about they were last called. The constructor of ScheduledDiagnostics was using a reference instead of a copy, which led to incorrect scheduling.

@@ -158,7 +158,7 @@ function ScheduledDiagnostic(;
reduction_time_func = nothing,
compute_schedule_func = EveryStepSchedule(),
output_schedule_func = isnothing(reduction_time_func) ?
compute_schedule_func : EveryStepSchedule(),
deepcopy(compute_schedule_func) : EveryStepSchedule(),
Copy link
Member

Choose a reason for hiding this comment

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

Why would this need a deep copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because in general compute_schedule_func contains a mutable object that is used to track when the it was last called

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't that mean that the deep copy can become out of sync from what is passed in (if the input has any mutable data)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's exactly the problem being fixed here.

Suppose you have a struct that holds the last time the callback was called: if you use this struct for both compute and output, calling compute will update the last time the callback was called, so that output will never happen.

With a deepcopy, we allow them to be out of sync, so that they can happen independently.

Let me also note this only changes the default constructor that is currently never used.

Schedules have to be unique objects because they store information about
they were last called. The constructor of `ScheduledDiagnostics` was
using a reference instead of a copy, which led to incorrect scheduling.
@Sbozzolo Sbozzolo merged commit c186428 into main Sep 23, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants