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

Add base class for workflows #3445

Merged
merged 9 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/source/engines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Multi-GPU data parallel
Workflows
---------

.. automodule:: monai.engines.workflow
.. currentmodule:: monai.engines.workflow
.. currentmodule:: monai.engines

`BaseWorkflow`
~~~~~~~~~~~~~~
.. autoclass:: BaseWorkflow
:members:

`Workflow`
~~~~~~~~~~
.. autoclass:: Workflow
:members:

.. currentmodule:: monai.engines

`Trainer`
~~~~~~~~~
.. autoclass:: Trainer
Expand Down
1 change: 1 addition & 0 deletions monai/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
engine_apply_transform,
get_devices_spec,
)
from .workflow import BaseWorkflow, Workflow
13 changes: 13 additions & 0 deletions monai/engines/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# limitations under the License.

import warnings
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Optional, Sequence, Union

import torch
Expand Down Expand Up @@ -37,6 +38,18 @@
EventEnum, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EventEnum")


class BaseWorkflow(ABC):
"""
Base class for any MONAI style workflow.
`run()` is designed to execute the train, evaluation or inference logic.

"""

@abstractmethod
def run(self):
raise NotImplementedError(f"Subclass {self.__class__.__name__} must implement this method.")


class Workflow(IgniteEngine): # type: ignore[valid-type, misc] # due to optional_import
"""
Workflow defines the core work process inheriting from Ignite engine.
Expand Down