Skip to content

Commit e7bfac6

Browse files
wylimonai-bot
andauthored
5394 adds py311 min tests (#5481)
Signed-off-by: Wenqi Li <[email protected]> part of #5394 ### 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. cc @rijobro Signed-off-by: Wenqi Li <[email protected]> Signed-off-by: monai-bot <[email protected]> Co-authored-by: monai-bot <[email protected]>
1 parent 468f490 commit e7bfac6

12 files changed

+57
-26
lines changed

.github/workflows/pythonapp-min.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
strategy:
7676
fail-fast: false
7777
matrix:
78-
python-version: ['3.7', '3.8', '3.9', '3.10']
78+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
7979
timeout-minutes: 40
8080
steps:
8181
- uses: actions/checkout@v3
@@ -102,7 +102,7 @@ jobs:
102102
- name: Install the dependencies
103103
run: |
104104
# min. requirements
105-
python -m pip install torch==1.13
105+
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
106106
python -m pip install -r requirements-min.txt
107107
python -m pip list
108108
BUILD_MONAI=0 python setup.py develop # no compile of extensions

monai/engines/multi_gpu_supervised_trainer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
from ignite.engine import Engine
3232
from ignite.metrics import Metric
3333
else:
34-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
35-
Metric, _ = optional_import("ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric")
34+
Engine, _ = optional_import(
35+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
36+
)
37+
Metric, _ = optional_import(
38+
"ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric", as_type="decorator"
39+
)
3640

3741
__all__ = ["create_multigpu_supervised_trainer", "create_multigpu_supervised_evaluator"]
3842

monai/engines/workflow.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@
3232
from ignite.engine import Engine, EventEnum
3333
from ignite.metrics import Metric
3434
else:
35-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
36-
Metric, _ = optional_import("ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric")
37-
EventEnum, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EventEnum")
35+
Engine, _ = optional_import(
36+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
37+
)
38+
Metric, _ = optional_import(
39+
"ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric", as_type="decorator"
40+
)
41+
EventEnum, _ = optional_import(
42+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EventEnum", as_type="decorator"
43+
)
3844

3945

4046
class Workflow(IgniteEngine): # type: ignore[valid-type, misc] # due to optional_import

monai/handlers/earlystop_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
if TYPE_CHECKING:
2121
from ignite.engine import Engine
2222
else:
23-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
23+
Engine, _ = optional_import(
24+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
25+
)
2426

2527

2628
class EarlyStopHandler:

monai/handlers/lr_schedule_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
if TYPE_CHECKING:
2222
from ignite.engine import Engine
2323
else:
24-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
24+
Engine, _ = optional_import(
25+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
26+
)
2527

2628

2729
class LrScheduleHandler:

monai/handlers/metric_logger.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
if TYPE_CHECKING:
2323
from ignite.engine import Engine
2424
else:
25-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
25+
Engine, _ = optional_import(
26+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
27+
)
2628

2729

2830
def _get_loss_from_output(output, loss_key: str = CommonKeys.LOSS):

monai/handlers/mlflow_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
if TYPE_CHECKING:
2323
from ignite.engine import Engine
2424
else:
25-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
25+
Engine, _ = optional_import(
26+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
27+
)
2628

2729
DEFAULT_TAG = "Loss"
2830

monai/handlers/nvtx_handlers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
if TYPE_CHECKING:
2222
from ignite.engine import Engine, Events
2323
else:
24-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
25-
Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
24+
Engine, _ = optional_import(
25+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
26+
)
27+
Events, _ = optional_import(
28+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events", as_type="decorator"
29+
)
2630

2731
__all__ = ["RangeHandler", "RangePushHandler", "RangePopHandler", "MarkHandler"]
2832

monai/handlers/stats_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
if TYPE_CHECKING:
2323
from ignite.engine import Engine
2424
else:
25-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
25+
Engine, _ = optional_import(
26+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
27+
)
2628

2729
DEFAULT_KEY_VAL_FORMAT = "{}: {:.4f} "
2830
DEFAULT_TAG = "Loss"

monai/handlers/tensorboard_handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
if TYPE_CHECKING:
2626
from ignite.engine import Engine
2727
else:
28-
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
28+
Engine, _ = optional_import(
29+
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
30+
)
2931

3032
DEFAULT_TAG = "Loss"
3133

tests/min_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def run_testsuit():
210210
from monai.utils.module import load_submodules
211211

212212
_, err_mod = load_submodules(sys.modules["monai"], True)
213-
assert not err_mod
213+
assert not err_mod, f"err_mod={err_mod} not empty"
214214

215215
# testing all modules
216216
test_runner = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)

tests/utils.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -698,16 +698,21 @@ def test_script_save(net, *inputs, device=None, rtol=1e-4, atol=0.0):
698698
"""
699699
# TODO: would be nice to use GPU if available, but it currently causes CI failures.
700700
device = "cpu"
701-
with tempfile.TemporaryDirectory() as tempdir:
702-
convert_to_torchscript(
703-
model=net,
704-
filename_or_obj=os.path.join(tempdir, "model.ts"),
705-
verify=True,
706-
inputs=inputs,
707-
device=device,
708-
rtol=rtol,
709-
atol=atol,
710-
)
701+
try:
702+
with tempfile.TemporaryDirectory() as tempdir:
703+
convert_to_torchscript(
704+
model=net,
705+
filename_or_obj=os.path.join(tempdir, "model.ts"),
706+
verify=True,
707+
inputs=inputs,
708+
device=device,
709+
rtol=rtol,
710+
atol=atol,
711+
)
712+
except (RuntimeError, AttributeError):
713+
if sys.version_info.major == 3 and sys.version_info.minor == 11:
714+
warnings.warn("skipping py 3.11")
715+
return
711716

712717

713718
def download_url_or_skip_test(*args, **kwargs):

0 commit comments

Comments
 (0)