Skip to content

Commit

Permalink
Cleaning up some very old and now obsolete infrastructure (#8113)
Browse files Browse the repository at this point in the history
### Description

This removes some functions which aren't needed any more. These related
to an early idea for doing importation to avoid defining `__all__`
components to modules, but this is being done instead as it is more
standard.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 27, 2024
1 parent acfc508 commit cac21f6
Show file tree
Hide file tree
Showing 45 changed files with 90 additions and 307 deletions.
5 changes: 0 additions & 5 deletions docs/source/networks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,9 @@ Nets
.. autoclass:: VoxelMorphUNet
:members:

.. autoclass:: voxelmorphunet
:members:

.. autoclass:: VoxelMorph
:members:

.. autoclass:: voxelmorph

Utilities
---------
.. automodule:: monai.networks.utils
Expand Down
6 changes: 0 additions & 6 deletions docs/source/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ Module utils
:members:


Aliases
-------
.. automodule:: monai.utils.aliases
:members:


Misc
----
.. automodule:: monai.utils.misc
Expand Down
39 changes: 18 additions & 21 deletions monai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,25 @@ def filter(self, record):
category=RuntimeWarning,
)

from .utils.module import load_submodules # noqa: E402

# handlers_* have some external decorators the users may not have installed
# *.so files and folder "_C" may not exist when the cpp extensions are not compiled
excludes = "|".join(
[
"(^(monai.handlers))",
"(^(monai.bundle))",
"(^(monai.fl))",
"((\\.so)$)",
"(^(monai._C))",
"(.*(__main__)$)",
"(.*(video_dataset)$)",
"(.*(nnunet).*$)",
]
)

# load directory modules only, skip loading individual files
load_submodules(sys.modules[__name__], False, exclude_pattern=excludes)

# load all modules, this will trigger all export decorations
load_submodules(sys.modules[__name__], True, exclude_pattern=excludes)
from . import ( # noqa: E402
apps,
auto3dseg,
bundle,
config,
data,
engines,
fl,
handlers,
inferers,
losses,
metrics,
networks,
optimizers,
transforms,
utils,
visualize,
)

__all__ = [
"apps",
Expand Down
3 changes: 2 additions & 1 deletion monai/bundle/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from monai.bundle.config_parser import ConfigParser
from monai.bundle.utils import DEFAULT_INFERENCE, DEFAULT_METADATA, merge_kv
from monai.bundle.workflows import BundleWorkflow, ConfigWorkflow
from monai.config import IgniteInfo, PathLike
from monai.config import PathLike
from monai.data import load_net_with_metadata, save_net_with_metadata
from monai.networks import (
convert_to_onnx,
Expand All @@ -45,6 +45,7 @@
save_state,
)
from monai.utils import (
IgniteInfo,
check_parent_dir,
deprecated_arg,
ensure_tuple,
Expand Down
1 change: 0 additions & 1 deletion monai/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from .deviceconfig import (
USE_COMPILED,
USE_META_DICT,
IgniteInfo,
get_config_values,
get_gpu_info,
get_optional_config_values,
Expand Down
10 changes: 0 additions & 10 deletions monai/config/deviceconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"print_debug_info",
"USE_COMPILED",
"USE_META_DICT",
"IgniteInfo",
]


Expand Down Expand Up @@ -261,14 +260,5 @@ def print_debug_info(file: TextIO = sys.stdout) -> None:
print_gpu_info(file)


class IgniteInfo:
"""
Config information of the PyTorch ignite package.
"""

OPT_IMPORT_VERSION = "0.4.4"


if __name__ == "__main__":
print_debug_info()
4 changes: 2 additions & 2 deletions monai/engines/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import torch
from torch.utils.data import DataLoader

from monai.config import IgniteInfo, KeysCollection
from monai.config import KeysCollection
from monai.data import MetaTensor
from monai.engines.utils import IterationEvents, default_metric_cmp_fn, default_prepare_batch
from monai.engines.workflow import Workflow
from monai.inferers import Inferer, SimpleInferer
from monai.networks.utils import eval_mode, train_mode
from monai.transforms import Transform
from monai.utils import ForwardMode, ensure_tuple, min_version, optional_import
from monai.utils import ForwardMode, IgniteInfo, ensure_tuple, min_version, optional_import
from monai.utils.enums import CommonKeys as Keys
from monai.utils.enums import EngineStatsKeys as ESKeys
from monai.utils.module import look_up_option, pytorch_after
Expand Down
3 changes: 1 addition & 2 deletions monai/engines/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
from torch.optim.optimizer import Optimizer
from torch.utils.data import DataLoader

from monai.config import IgniteInfo
from monai.data import MetaTensor
from monai.engines.utils import IterationEvents, default_make_latent, default_metric_cmp_fn, default_prepare_batch
from monai.engines.workflow import Workflow
from monai.inferers import Inferer, SimpleInferer
from monai.transforms import Transform
from monai.utils import AdversarialIterationEvents, AdversarialKeys, GanKeys, min_version, optional_import
from monai.utils import AdversarialIterationEvents, AdversarialKeys, GanKeys, IgniteInfo, min_version, optional_import
from monai.utils.enums import CommonKeys as Keys
from monai.utils.enums import EngineStatsKeys as ESKeys
from monai.utils.module import pytorch_after
Expand Down
3 changes: 1 addition & 2 deletions monai/engines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import torch
import torch.nn as nn

from monai.config import IgniteInfo
from monai.transforms import apply_transform
from monai.utils import ensure_tuple, min_version, optional_import
from monai.utils import IgniteInfo, ensure_tuple, min_version, optional_import
from monai.utils.enums import CommonKeys, GanKeys

if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/engines/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
from torch.utils.data import DataLoader
from torch.utils.data.distributed import DistributedSampler

from monai.config import IgniteInfo
from monai.engines.utils import IterationEvents, default_metric_cmp_fn, default_prepare_batch
from monai.transforms import Decollated
from monai.utils import ensure_tuple, is_scalar, min_version, optional_import
from monai.utils import IgniteInfo, ensure_tuple, is_scalar, min_version, optional_import

from .utils import engine_apply_transform

Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/checkpoint_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

import torch

from monai.config import IgniteInfo
from monai.networks.utils import copy_model_state
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
Checkpoint, _ = optional_import("ignite.handlers", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Checkpoint")
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/checkpoint_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any

from monai.config import IgniteInfo
from monai.utils import is_scalar, min_version, optional_import
from monai.utils import IgniteInfo, is_scalar, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")

Expand Down
2 changes: 1 addition & 1 deletion monai/handlers/classification_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import torch

from monai.config import IgniteInfo
from monai.data import CSVSaver, decollate_batch
from monai.utils import IgniteInfo
from monai.utils import ImageMetaKey as Key
from monai.utils import evenly_divisible_all_gather, min_version, optional_import, string_list_all_gather

Expand Down
4 changes: 2 additions & 2 deletions monai/handlers/decollate_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

from typing import TYPE_CHECKING

from monai.config import IgniteInfo, KeysCollection
from monai.config import KeysCollection
from monai.engines.utils import IterationEvents
from monai.transforms import Decollated
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/earlystop_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from collections.abc import Callable
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
EarlyStopping, _ = optional_import("ignite.handlers", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EarlyStopping")
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/garbage_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import gc
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

if TYPE_CHECKING:
from ignite.engine import Engine, Events
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/ignite_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import torch
from torch.nn.modules.loss import _Loss

from monai.config import IgniteInfo
from monai.metrics import CumulativeIterationMetric, LossMetric
from monai.utils import MetricReduction, min_version, optional_import
from monai.utils import IgniteInfo, MetricReduction, min_version, optional_import

idist, _ = optional_import("ignite", IgniteInfo.OPT_IMPORT_VERSION, min_version, "distributed")

Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/logfile_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import os
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/lr_schedule_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

from torch.optim.lr_scheduler import ReduceLROnPlateau, _LRScheduler

from monai.config import IgniteInfo
from monai.utils import ensure_tuple, min_version, optional_import
from monai.utils import IgniteInfo, ensure_tuple, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/metric_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from threading import RLock
from typing import TYPE_CHECKING, Any

from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import
from monai.utils.enums import CommonKeys

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
Expand Down
2 changes: 1 addition & 1 deletion monai/handlers/metrics_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.data import decollate_batch
from monai.handlers.utils import write_metrics_reports
from monai.utils import IgniteInfo
from monai.utils import ImageMetaKey as Key
from monai.utils import ensure_tuple, min_version, optional_import, string_list_all_gather

Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/mlflow_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from torch.utils.data import Dataset

from monai.apps.utils import get_logger
from monai.config import IgniteInfo
from monai.utils import CommonKeys, ensure_tuple, min_version, optional_import
from monai.utils import CommonKeys, IgniteInfo, ensure_tuple, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
mlflow, _ = optional_import("mlflow", descriptor="Please install mlflow before using MLFlowHandler.")
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/nvtx_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.utils import ensure_tuple, min_version, optional_import
from monai.utils import IgniteInfo, ensure_tuple, min_version, optional_import

_nvtx, _ = optional_import("torch._C._nvtx", descriptor="NVTX is not installed. Are you sure you have a CUDA build?")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/parameter_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from collections.abc import Callable
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

if TYPE_CHECKING:
from ignite.engine import Engine, Events
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
from collections.abc import Callable
from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.engines.utils import IterationEvents, engine_apply_transform
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions monai/handlers/probability_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import numpy as np

from monai.config import DtypeLike, IgniteInfo
from monai.config import DtypeLike
from monai.data.folder_layout import FolderLayout
from monai.utils import ProbMapKeys, min_version, optional_import
from monai.utils.enums import CommonKeys
from monai.utils.enums import CommonKeys, IgniteInfo

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/smartcache_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.data import SmartCacheDataset
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/stats_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import torch

from monai.apps import get_logger
from monai.config import IgniteInfo
from monai.utils import is_scalar, min_version, optional_import
from monai.utils import IgniteInfo, is_scalar, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/tensorboard_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import numpy as np
import torch

from monai.config import IgniteInfo
from monai.utils import is_scalar, min_version, optional_import
from monai.utils import IgniteInfo, is_scalar, min_version, optional_import
from monai.visualize import plot_2d_or_3d_image

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
Expand Down
3 changes: 1 addition & 2 deletions monai/handlers/trt_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

from typing import TYPE_CHECKING

from monai.config import IgniteInfo
from monai.networks import trt_compile
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
if TYPE_CHECKING:
Expand Down
Loading

0 comments on commit cac21f6

Please sign in to comment.