Skip to content

Transition table as a ClassVar#6331

Merged
crusaderky merged 2 commits intodask:mainfrom
crusaderky:transition_table
May 13, 2022
Merged

Transition table as a ClassVar#6331
crusaderky merged 2 commits intodask:mainfrom
crusaderky:transition_table

Conversation

@crusaderky
Copy link
Copy Markdown
Collaborator

@crusaderky crusaderky commented May 12, 2022

  1. Declutter the __init__ method
  2. Emphasize that the table is immutable
  3. Remove a wealth of circular references to the Scheduler and Worker instances

CC @hendrikmakait

@crusaderky crusaderky self-assigned this May 12, 2022
Comment thread distributed/scheduler.py

return ws

def set_duration_estimate(self, ts: TaskState, ws: WorkerState) -> float:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is just a cut-paste out of the transitions section, as this is not a transition-specific method

Comment thread distributed/worker.py
("ready", "released"): transition_generic_released,
("released", "error"): transition_generic_error,
("released", "fetch"): transition_released_fetch,
("released", "missing"): transition_generic_missing,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Includes one-liner fix from #6327

Copy link
Copy Markdown
Member

@hendrikmakait hendrikmakait left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread distributed/worker.py
Comment on lines +2601 to +2606
# {
# (start, finish):
# transition_<start>_<finish>(
# self, ts: TaskState, *args, stimulus_id: str
# ) -> (recommendations, instructions)
# }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🙌

Comment thread distributed/worker.py Outdated

start = ts.state
func = self._transitions_table.get((start, cast(str, finish)))
func = self.TRANSITIONS_TABLE.get((start, cast(TaskStateState, finish)))
Copy link
Copy Markdown
Member

@hendrikmakait hendrikmakait May 13, 2022

Choose a reason for hiding this comment

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

nit: Should we generally keep the _ around to mark the transitions table as internal use only, i.e. use _TRANSITIONS_TABLE in both Scheduler and Worker?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sure

Comment thread distributed/worker.py Outdated
# self, ts: TaskState, *args, stimulus_id: str
# ) -> (recommendations, instructions)
# }
TRANSITIONS_TABLE: ClassVar[
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Meta question: Do we have any conventions on the ordering of class variable definitions, instance variable declarations, class/instance method definitions, etc?

Copy link
Copy Markdown
Collaborator Author

@crusaderky crusaderky May 13, 2022

Choose a reason for hiding this comment

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

Typically class variables -> instance variables -> methods. In this case however the class variable MUST be after the transitions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense, I was just wondering how strict we'd be here, also when it comes to ordering of public/private, class/instance methods. It looks like the rule there is "whatever seems to be a reasonable order/grouping".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We don't group public and private separately. e.g. typically we put private helper methods next to their public parent methods.

@crusaderky crusaderky merged commit 77cfc73 into dask:main May 13, 2022
@crusaderky crusaderky deleted the transition_table branch May 13, 2022 10:16
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