Skip to content

Commit 8a47227

Browse files
Nic-Mamonai-bot
andauthored
Add base class for workflows (#3445)
* [DLMED] add BaseWorkflow Signed-off-by: Nic Ma <[email protected]> * [DLMED] fix typo Signed-off-by: Nic Ma <[email protected]> * [MONAI] python code formatting Signed-off-by: monai-bot <[email protected]> * [DLMED] add *args, **kwargs Signed-off-by: Nic Ma <[email protected]> Co-authored-by: monai-bot <[email protected]>
1 parent f3e7cc0 commit 8a47227

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docs/source/engines.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ Multi-GPU data parallel
1515
Workflows
1616
---------
1717

18-
.. automodule:: monai.engines.workflow
19-
.. currentmodule:: monai.engines.workflow
18+
.. currentmodule:: monai.engines
19+
20+
`BaseWorkflow`
21+
~~~~~~~~~~~~~~
22+
.. autoclass:: BaseWorkflow
23+
:members:
2024

2125
`Workflow`
2226
~~~~~~~~~~
2327
.. autoclass:: Workflow
2428
:members:
2529

26-
.. currentmodule:: monai.engines
27-
2830
`Trainer`
2931
~~~~~~~~~
3032
.. autoclass:: Trainer

monai/engines/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
engine_apply_transform,
2525
get_devices_spec,
2626
)
27+
from .workflow import BaseWorkflow, Workflow

monai/engines/workflow.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# limitations under the License.
1111

1212
import warnings
13+
from abc import ABC, abstractmethod
1314
from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Optional, Sequence, Union
1415

1516
import torch
@@ -37,6 +38,18 @@
3738
EventEnum, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EventEnum")
3839

3940

41+
class BaseWorkflow(ABC):
42+
"""
43+
Base class for any MONAI style workflow.
44+
`run()` is designed to execute the train, evaluation or inference logic.
45+
46+
"""
47+
48+
@abstractmethod
49+
def run(self, *args, **kwargs):
50+
raise NotImplementedError(f"Subclass {self.__class__.__name__} must implement this method.")
51+
52+
4053
class Workflow(IgniteEngine): # type: ignore[valid-type, misc] # due to optional_import
4154
"""
4255
Workflow defines the core work process inheriting from Ignite engine.

0 commit comments

Comments
 (0)