From 4281c73a96a9b6188059e1285421202bc5f979e1 Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Tue, 28 May 2024 10:42:45 +0200 Subject: [PATCH 1/9] add simulate-gpu option --- tests/conftest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 7251b5b8f..3a603f44f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,10 +14,19 @@ def pytest_addoption(parser): action="store", help="Directory for (only-read) inputs for tests", ) + parser.addoption( + "--simulate-gpu", + action="store_true", + help="""To simulate the presence of a gpu on a cpu-only device. Default is False. + To use carefully, only to run tests locally. Should not be used in final CI tests. + Concretely, the tests won't fail if gpu option if false in the output MAPS whereas + it should be true.""", + ) @pytest.fixture def cmdopt(request): config_param = {} config_param["input"] = request.config.getoption("--input_data_directory") + config_param["simulate gpu"] = request.config.getoption("--simulate-gpu") return config_param From effeee2c97a82fb8de462e7cee61b18e5c40bf7c Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Tue, 28 May 2024 14:52:35 +0200 Subject: [PATCH 2/9] add flags to run functional tests locally --- tests/conftest.py | 9 +++++++++ tests/test_train_ae.py | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3a603f44f..ed7990a31 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,6 +22,14 @@ def pytest_addoption(parser): Concretely, the tests won't fail if gpu option if false in the output MAPS whereas it should be true.""", ) + parser.addoption( + "--adapt-base-dir", + action="store_true", + help="""To virtually change the base directory in the paths stored in MAPS. Default is False. + To use carefully, only to run tests locally. Should not be used in final CI tests. + Concretely, the tests won't fail if only the base directory differs in the paths stored + in the MAPS.""", + ) @pytest.fixture @@ -29,4 +37,5 @@ def cmdopt(request): config_param = {} config_param["input"] = request.config.getoption("--input_data_directory") config_param["simulate gpu"] = request.config.getoption("--simulate-gpu") + config_param["adapt base dir"] = request.config.getoption("--adapt-base-dir") return config_param diff --git a/tests/test_train_ae.py b/tests/test_train_ae.py index ab9c057ff..778ee7f9d 100644 --- a/tests/test_train_ae.py +++ b/tests/test_train_ae.py @@ -24,7 +24,7 @@ def test_name(request): def test_train_ae(cmdopt, tmp_path, test_name): - base_dir = Path(cmdopt["input"]) + base_dir = Path(cmdopt["input"]).resolve() input_dir = base_dir / "train" / "in" ref_dir = base_dir / "train" / "ref" tmp_out_dir = base_dir / "train" / "out" @@ -88,6 +88,9 @@ def test_train_ae(cmdopt, tmp_path, test_name): else: raise NotImplementedError(f"Test {test_name} is not implemented.") + if cmdopt["simulate gpu"]: + test_input.append("--no-gpu") + if tmp_out_dir.is_dir(): shutil.rmtree(tmp_out_dir) @@ -101,6 +104,16 @@ def test_train_ae(cmdopt, tmp_path, test_name): if test_name == "patch_multi_ae": json_data_out["multi_network"] = True + if cmdopt["simulate gpu"]: + json_data_out["gpu"] = True + if cmdopt["adapt base dir"]: + ref_base_dir = Path(json_data_ref["caps_directory"]).parents[2] + json_data_out["caps_directory"] = str( + ref_base_dir / Path(json_data_out["caps_directory"]).relative_to(base_dir) + ) + json_data_out["tsv_path"] = str( + ref_base_dir / Path(json_data_out["tsv_path"]).relative_to(base_dir) + ) assert json_data_out == json_data_ref # ["mode"] == mode assert compare_folders( From d3428efd15855eb23647c70869f6eda1037c0c51 Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Wed, 29 May 2024 09:43:42 +0200 Subject: [PATCH 3/9] fix bug --- tests/test_train_ae.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_train_ae.py b/tests/test_train_ae.py index 778ee7f9d..ed727610b 100644 --- a/tests/test_train_ae.py +++ b/tests/test_train_ae.py @@ -24,7 +24,7 @@ def test_name(request): def test_train_ae(cmdopt, tmp_path, test_name): - base_dir = Path(cmdopt["input"]).resolve() + base_dir = Path(cmdopt["input"]) input_dir = base_dir / "train" / "in" ref_dir = base_dir / "train" / "ref" tmp_out_dir = base_dir / "train" / "out" @@ -107,6 +107,7 @@ def test_train_ae(cmdopt, tmp_path, test_name): if cmdopt["simulate gpu"]: json_data_out["gpu"] = True if cmdopt["adapt base dir"]: + base_dir = base_dir.resolve() ref_base_dir = Path(json_data_ref["caps_directory"]).parents[2] json_data_out["caps_directory"] = str( ref_base_dir / Path(json_data_out["caps_directory"]).relative_to(base_dir) From 72fe5580032ef42012ee2bd38351a7cafa2ef34b Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Wed, 29 May 2024 18:46:02 +0200 Subject: [PATCH 4/9] modify ref instead of output --- tests/conftest.py | 19 ++++++++++--------- tests/test_train_ae.py | 16 ++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ed7990a31..e5a4a7302 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,20 +15,21 @@ def pytest_addoption(parser): help="Directory for (only-read) inputs for tests", ) parser.addoption( - "--simulate-gpu", + "--no-gpu", action="store_true", - help="""To simulate the presence of a gpu on a cpu-only device. Default is False. + help="""To run tests on cpu. Default is False. To use carefully, only to run tests locally. Should not be used in final CI tests. - Concretely, the tests won't fail if gpu option if false in the output MAPS whereas - it should be true.""", + Concretely, the tests won't fail if gpu option is false in the output MAPS whereas + it is true in the reference MAPS.""", ) parser.addoption( "--adapt-base-dir", action="store_true", - help="""To virtually change the base directory in the paths stored in MAPS. Default is False. + help="""To virtually change the base directory in the paths stored in the MAPS of the CI data. + Default is False. To use carefully, only to run tests locally. Should not be used in final CI tests. - Concretely, the tests won't fail if only the base directory differs in the paths stored - in the MAPS.""", + Concretely, the tests won't fail if only the base directories differ in the paths stored + in the output and reference MAPS.""", ) @@ -36,6 +37,6 @@ def pytest_addoption(parser): def cmdopt(request): config_param = {} config_param["input"] = request.config.getoption("--input_data_directory") - config_param["simulate gpu"] = request.config.getoption("--simulate-gpu") - config_param["adapt base dir"] = request.config.getoption("--adapt-base-dir") + config_param["no-gpu"] = request.config.getoption("--no-gpu") + config_param["adapt-base-dir"] = request.config.getoption("--adapt-base-dir") return config_param diff --git a/tests/test_train_ae.py b/tests/test_train_ae.py index ed727610b..311e145d0 100644 --- a/tests/test_train_ae.py +++ b/tests/test_train_ae.py @@ -88,7 +88,7 @@ def test_train_ae(cmdopt, tmp_path, test_name): else: raise NotImplementedError(f"Test {test_name} is not implemented.") - if cmdopt["simulate gpu"]: + if cmdopt["no-gpu"]: test_input.append("--no-gpu") if tmp_out_dir.is_dir(): @@ -104,16 +104,16 @@ def test_train_ae(cmdopt, tmp_path, test_name): if test_name == "patch_multi_ae": json_data_out["multi_network"] = True - if cmdopt["simulate gpu"]: - json_data_out["gpu"] = True - if cmdopt["adapt base dir"]: + if cmdopt["no-gpu"]: + json_data_ref["gpu"] = False + if cmdopt["adapt-base-dir"]: base_dir = base_dir.resolve() ref_base_dir = Path(json_data_ref["caps_directory"]).parents[2] - json_data_out["caps_directory"] = str( - ref_base_dir / Path(json_data_out["caps_directory"]).relative_to(base_dir) + json_data_ref["caps_directory"] = str( + base_dir / Path(json_data_ref["caps_directory"]).relative_to(ref_base_dir) ) - json_data_out["tsv_path"] = str( - ref_base_dir / Path(json_data_out["tsv_path"]).relative_to(base_dir) + json_data_ref["tsv_path"] = str( + base_dir / Path(json_data_ref["tsv_path"]).relative_to(ref_base_dir) ) assert json_data_out == json_data_ref # ["mode"] == mode From 6081a7b79a8da09363f116438b5b1a0c0f6311c6 Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Thu, 30 May 2024 18:13:08 +0200 Subject: [PATCH 5/9] add flags in all training tests --- tests/test_random_search.py | 12 ++++--- tests/test_resume.py | 26 ++++++++++++-- tests/test_train_ae.py | 21 ++++------- tests/test_train_cnn.py | 13 +++++-- tests/test_train_from_json.py | 28 ++++++++++----- tests/test_transfer_learning.py | 40 +++++++++++++-------- tests/testing_tools.py | 62 ++++++++++++++++++++++++++++++++- 7 files changed, 156 insertions(+), 46 deletions(-) diff --git a/tests/test_random_search.py b/tests/test_random_search.py index e1c530513..5b68787e8 100644 --- a/tests/test_random_search.py +++ b/tests/test_random_search.py @@ -1,6 +1,5 @@ # coding: utf8 -import json import os import shutil from os.path import join @@ -8,7 +7,7 @@ import pytest -from tests.testing_tools import compare_folders +from .testing_tools import change_gpu_in_toml, compare_folders # random searxh for ROI with CNN @@ -34,10 +33,12 @@ def test_random_search(cmdopt, tmp_path, test_name): else: raise NotImplementedError(f"Test {test_name} is not implemented.") - run_test_random_search(toml_path, generate_input, tmp_out_dir, ref_dir) + run_test_random_search( + toml_path, generate_input, tmp_out_dir, ref_dir, cmdopt["no-gpu"] + ) -def run_test_random_search(toml_path, generate_input, tmp_out_dir, ref_dir): +def run_test_random_search(toml_path, generate_input, tmp_out_dir, ref_dir, no_gpu): if os.path.exists(tmp_out_dir): shutil.rmtree(tmp_out_dir) @@ -45,6 +46,9 @@ def run_test_random_search(toml_path, generate_input, tmp_out_dir, ref_dir): os.makedirs(tmp_out_dir, exist_ok=True) shutil.copy(toml_path, tmp_out_dir) + if no_gpu: + change_gpu_in_toml(tmp_out_dir / "random_search.toml") + flag_error_generate = not os.system("clinicadl " + " ".join(generate_input)) performances_flag = os.path.exists( tmp_out_dir / "job-1" / "split-0" / "best-loss" / "train" diff --git a/tests/test_resume.py b/tests/test_resume.py index 3cf883c32..cdf6031ee 100644 --- a/tests/test_resume.py +++ b/tests/test_resume.py @@ -1,15 +1,14 @@ # coding: utf8 import json -import os import shutil from os import system -from os.path import join from pathlib import Path import pytest from clinicadl import MapsManager -from tests.testing_tools import compare_folders + +from .testing_tools import modify_maps @pytest.fixture( @@ -33,6 +32,18 @@ def test_resume(cmdopt, tmp_path, test_name): shutil.copytree(input_dir / test_name, tmp_out_dir / test_name) maps_stopped = tmp_out_dir / test_name + if cmdopt["no-gpu"] or cmdopt["adapt-base-dir"]: # modify the input MAPS + with open(maps_stopped / "maps.json", "r") as f: + config = json.load(f) + config = modify_maps( + maps=config, + base_dir=base_dir, + no_gpu=cmdopt["no-gpu"], + adapt_base_dir=cmdopt["adapt-base-dir"], + ) + with open(maps_stopped / "maps.json", "w") as f: + json.dump(config, f) + flag_error = not system(f"clinicadl -vv train resume {maps_stopped}") assert flag_error @@ -48,4 +59,13 @@ def test_resume(cmdopt, tmp_path, test_name): json_data_out = json.load(out) with open(ref_dir / "maps_image_cnn" / "maps.json", "r") as ref: json_data_ref = json.load(ref) + + if cmdopt["no-gpu"] or cmdopt["adapt-base-dir"]: + json_data_ref = modify_maps( + maps=json_data_ref, + base_dir=base_dir, + no_gpu=cmdopt["no-gpu"], + adapt_base_dir=cmdopt["adapt-base-dir"], + ) + assert json_data_ref == json_data_out diff --git a/tests/test_train_ae.py b/tests/test_train_ae.py index 311e145d0..5e30cf934 100644 --- a/tests/test_train_ae.py +++ b/tests/test_train_ae.py @@ -3,12 +3,11 @@ import json import os import shutil -from os.path import join from pathlib import Path import pytest -from tests.testing_tools import clean_folder, compare_folders +from .testing_tools import clean_folder, compare_folders, modify_maps @pytest.fixture( @@ -102,18 +101,12 @@ def test_train_ae(cmdopt, tmp_path, test_name): with open(ref_dir / ("maps_" + test_name) / "maps.json", "r") as ref: json_data_ref = json.load(ref) - if test_name == "patch_multi_ae": - json_data_out["multi_network"] = True - if cmdopt["no-gpu"]: - json_data_ref["gpu"] = False - if cmdopt["adapt-base-dir"]: - base_dir = base_dir.resolve() - ref_base_dir = Path(json_data_ref["caps_directory"]).parents[2] - json_data_ref["caps_directory"] = str( - base_dir / Path(json_data_ref["caps_directory"]).relative_to(ref_base_dir) - ) - json_data_ref["tsv_path"] = str( - base_dir / Path(json_data_ref["tsv_path"]).relative_to(ref_base_dir) + if cmdopt["no-gpu"] or cmdopt["adapt-base-dir"]: + json_data_ref = modify_maps( + maps=json_data_ref, + base_dir=base_dir, + no_gpu=cmdopt["no-gpu"], + adapt_base_dir=cmdopt["adapt-base-dir"], ) assert json_data_out == json_data_ref # ["mode"] == mode diff --git a/tests/test_train_cnn.py b/tests/test_train_cnn.py index da5b3a3f1..761fedbee 100644 --- a/tests/test_train_cnn.py +++ b/tests/test_train_cnn.py @@ -3,12 +3,11 @@ import json import os import shutil -from os.path import join from pathlib import Path import pytest -from tests.testing_tools import compare_folders +from .testing_tools import compare_folders, modify_maps @pytest.fixture( @@ -101,6 +100,9 @@ def test_train_cnn(cmdopt, tmp_path, test_name): else: raise NotImplementedError(f"Test {test_name} is not implemented.") + if cmdopt["no-gpu"]: + test_input.append("--no-gpu") + if tmp_out_dir.is_dir(): shutil.rmtree(tmp_out_dir) @@ -117,6 +119,13 @@ def test_train_cnn(cmdopt, tmp_path, test_name): with open(ref_dir / ("maps_" + test_name) / "maps.json", "r") as ref: json_data_ref = json.load(ref) + if cmdopt["no-gpu"] or cmdopt["adapt-base-dir"]: + json_data_ref = modify_maps( + maps=json_data_ref, + base_dir=base_dir, + no_gpu=cmdopt["no-gpu"], + adapt_base_dir=cmdopt["adapt-base-dir"], + ) assert json_data_out == json_data_ref # ["mode"] == mode assert compare_folders( diff --git a/tests/test_train_from_json.py b/tests/test_train_from_json.py index f48791d31..363af9aff 100644 --- a/tests/test_train_from_json.py +++ b/tests/test_train_from_json.py @@ -1,17 +1,14 @@ -import os -import pathlib +import json import shutil -from os import path, system -from os.path import join +from os import system from pathlib import Path -from .testing_tools import compare_folders_with_hashes, create_hashes_dict, models_equal +from .testing_tools import compare_folders_with_hashes, create_hashes_dict, modify_maps def test_json_compatibility(cmdopt, tmp_path): base_dir = Path(cmdopt["input"]) input_dir = base_dir / "train_from_json" / "in" - ref_dir = base_dir / "train_from_json" / "ref" tmp_out_dir = tmp_path / "train_from_json" / "out" tmp_out_dir.mkdir(parents=True) @@ -22,6 +19,19 @@ def test_json_compatibility(cmdopt, tmp_path): if reproduced_maps_dir.exists(): shutil.rmtree(reproduced_maps_dir) + if cmdopt["no-gpu"] or cmdopt["adapt-base-dir"]: # virtually modify the input MAPS + with open(config_json, "r") as f: + config = json.load(f) + config_json = tmp_out_dir / "modified_maps.json" + config = modify_maps( + maps=config, + base_dir=base_dir, + no_gpu=cmdopt["no-gpu"], + adapt_base_dir=cmdopt["adapt-base-dir"], + ) + with open(config_json, "w+") as f: + json.dump(config, f) + flag_error = not system( f"clinicadl train from_json {str(config_json)} {str(reproduced_maps_dir)} -s {split}" ) @@ -31,7 +41,6 @@ def test_json_compatibility(cmdopt, tmp_path): def test_determinism(cmdopt, tmp_path): base_dir = Path(cmdopt["input"]) input_dir = base_dir / "train_from_json" / "in" - ref_dir = base_dir / "train_from_json" / "ref" tmp_out_dir = tmp_path / "train_from_json" / "out" tmp_out_dir.mkdir(parents=True) @@ -50,8 +59,11 @@ def test_determinism(cmdopt, tmp_path): str(maps_dir), "-c", str(input_dir / "reproducibility_config.toml"), - "--no-gpu", ] + + if cmdopt["no-gpu"]: + test_input.append("--no-gpu") + # Run first experiment flag_error = not system("clinicadl " + " ".join(test_input)) assert flag_error diff --git a/tests/test_transfer_learning.py b/tests/test_transfer_learning.py index 95713d7ad..072fef849 100644 --- a/tests/test_transfer_learning.py +++ b/tests/test_transfer_learning.py @@ -1,12 +1,11 @@ import json import os import shutil -from os.path import join from pathlib import Path import pytest -from tests.testing_tools import compare_folders +from .testing_tools import compare_folders, modify_maps # Everything is tested on roi except for cnn --> multicnn (patch) as multicnn is not implemented for roi. @@ -41,7 +40,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): str(caps_roi_path), extract_roi_str, str(labels_path), - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_ae"), "-c", str(config_path), ] @@ -55,7 +54,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): "-c", str(config_path), "--transfer_path", - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_ae"), ] name = "aeTOae" elif test_name == "transfer_ae_cnn": @@ -65,7 +64,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): str(caps_roi_path), extract_roi_str, str(labels_path), - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_ae"), "-c", str(config_path), ] @@ -79,7 +78,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): "-c", str(config_path), "--transfer_path", - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_ae"), ] name = "aeTOcnn" elif test_name == "transfer_cnn_cnn": @@ -89,7 +88,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): str(caps_roi_path), extract_roi_str, str(labels_path), - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_cnn"), "-c", str(config_path), ] @@ -103,7 +102,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): "-c", str(config_path), "--transfer_path", - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_cnn"), ] name = "cnnTOcnn" elif test_name == "transfer_cnn_multicnn": @@ -113,7 +112,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): str(caps_roi_path), extract_roi_str, str(labels_path), - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_cnn"), "-c", str(config_path), ] @@ -127,12 +126,17 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): "-c", str(config_path), "--transfer_path", - str(tmp_out_dir), + str(tmp_out_dir / "maps_roi_cnn"), + "--multi_network", ] - name = "cnnTOcnn" + name = "cnnTOmulticnn" else: raise NotImplementedError(f"Test {test_name} is not implemented.") + if cmdopt["no-gpu"]: + source_task.append("--no-gpu") + target_task.append("--no-gpu") + if tmp_out_dir.exists(): shutil.rmtree(tmp_out_dir) if tmp_target_dir.exists(): @@ -148,9 +152,17 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): with open(ref_dir / ("maps_roi_" + name) / "maps.json", "r") as ref: json_data_ref = json.load(ref) - json_data_ref["transfer_path"] = json_data_out["transfer_path"] - json_data_ref["gpu"] = json_data_out["gpu"] - json_data_ref["caps_directory"] = json_data_out["caps_directory"] + ref_source_dir = Path(json_data_ref["transfer_path"]).parent + json_data_ref["transfer_path"] = str( + tmp_out_dir / Path(json_data_ref["transfer_path"]).relative_to(ref_source_dir) + ) + if cmdopt["no-gpu"] or cmdopt["adapt-base-dir"]: + json_data_ref = modify_maps( + maps=json_data_ref, + base_dir=base_dir, + no_gpu=cmdopt["no-gpu"], + adapt_base_dir=cmdopt["adapt-base-dir"], + ) assert json_data_out == json_data_ref # ["mode"] == mode assert compare_folders( diff --git a/tests/testing_tools.py b/tests/testing_tools.py index d4cb29c8a..ff7eb97b1 100644 --- a/tests/testing_tools.py +++ b/tests/testing_tools.py @@ -1,7 +1,7 @@ import pathlib from os import PathLike from pathlib import Path -from typing import Dict, List +from typing import Any, Dict, List def ignore_pattern(file_path: pathlib.Path, ignore_pattern_list: List[str]) -> bool: @@ -166,3 +166,63 @@ def clean_folder(path, recreate=True): rmtree(abs_path) if recreate: makedirs(abs_path) + + +def modify_maps( + maps: Dict[str, Any], + base_dir: Path, + no_gpu: bool = False, + adapt_base_dir: bool = False, +) -> Dict[str, Any]: + """ + Modifies a MAPS dictionary if the user passed --no-gpu or --adapt-base-dir flags. + + Parameters + ---------- + maps : Dict[str, Any] + The MAPS dictionary. + base_dir : Path + The base directory, where CI data are stored. + no_gpu : bool (optional, default=False) + Whether the user activated the --no-gpu flag. + adapt_base_dir : bool (optional, default=False) + Whether the user activated the --adapt-base-dir flag. + + Returns + ------- + Dict[str, Any] + The modified MAPS dictionary. + """ + if no_gpu: + maps["gpu"] = False + if adapt_base_dir: + base_dir = base_dir.resolve() + ref_base_dir = Path(maps["caps_directory"]).parents[2] + maps["caps_directory"] = str( + base_dir / Path(maps["caps_directory"]).relative_to(ref_base_dir) + ) + maps["tsv_path"] = str( + base_dir / Path(maps["tsv_path"]).relative_to(ref_base_dir) + ) + return maps + + +def change_gpu_in_toml(toml_path: Path) -> None: + """ + Changes GPU to false in a TOML config file. + + Parameters + ---------- + toml_path : Path + The TOML file. + """ + import toml + + config = toml.load(toml_path) + try: + config["Computational"]["gpu"] = False + except KeyError: + config["Computational"] = {"gpu": False} + f = open(toml_path, "w") + toml.dump(config, f) + f.close() From 58da8bc17d2bf0d2631720a77a7b534dc5a5ba59 Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Fri, 31 May 2024 10:14:57 +0200 Subject: [PATCH 6/9] fix transfer learning --- tests/test_transfer_learning.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_transfer_learning.py b/tests/test_transfer_learning.py index 072fef849..5b4f888f2 100644 --- a/tests/test_transfer_learning.py +++ b/tests/test_transfer_learning.py @@ -163,6 +163,9 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): no_gpu=cmdopt["no-gpu"], adapt_base_dir=cmdopt["adapt-base-dir"], ) + # TODO: remove and update data + json_data_ref["gpu"] = json_data_out["gpu"] + ### assert json_data_out == json_data_ref # ["mode"] == mode assert compare_folders( From 993f1ea5344516dbf372ac88190a18907007c348 Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Fri, 31 May 2024 10:36:10 +0200 Subject: [PATCH 7/9] fix transfer learning test issue --- tests/test_transfer_learning.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_transfer_learning.py b/tests/test_transfer_learning.py index 5b4f888f2..b9c3f999b 100644 --- a/tests/test_transfer_learning.py +++ b/tests/test_transfer_learning.py @@ -164,6 +164,7 @@ def test_transfer_learning(cmdopt, tmp_path, test_name): adapt_base_dir=cmdopt["adapt-base-dir"], ) # TODO: remove and update data + json_data_ref["caps_directory"] = json_data_out["caps_directory"] json_data_ref["gpu"] = json_data_out["gpu"] ### assert json_data_out == json_data_ref # ["mode"] == mode From e6ad6fa27ed1b4d8f2056071df2f21e05b01a74e Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Fri, 31 May 2024 11:06:13 +0200 Subject: [PATCH 8/9] add interpret test --- tests/test_interpret.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_interpret.py b/tests/test_interpret.py index 8030e4c98..d84147e97 100644 --- a/tests/test_interpret.py +++ b/tests/test_interpret.py @@ -61,6 +61,9 @@ def test_interpret(cmdopt, tmp_path, test_name): else: raise NotImplementedError(f"Test {test_name} is not implemented.") + if cmdopt["no-gpu"]: + cnn_input.append("--no-gpu") + run_interpret(cnn_input, tmp_out_dir, ref_dir) From ea7f0b2fc75d2116c89e686ea89d35b758395db5 Mon Sep 17 00:00:00 2001 From: thibaultdvx <154365476+thibaultdvx@users.noreply.github.com> Date: Fri, 31 May 2024 11:17:29 +0200 Subject: [PATCH 9/9] change temporary folder in train_ae --- tests/test_train_ae.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_train_ae.py b/tests/test_train_ae.py index 5e30cf934..b20749258 100644 --- a/tests/test_train_ae.py +++ b/tests/test_train_ae.py @@ -26,8 +26,8 @@ def test_train_ae(cmdopt, tmp_path, test_name): base_dir = Path(cmdopt["input"]) input_dir = base_dir / "train" / "in" ref_dir = base_dir / "train" / "ref" - tmp_out_dir = base_dir / "train" / "out" - # tmp_out_dir.mkdir(parents=True) + tmp_out_dir = tmp_path / "train" / "out" + tmp_out_dir.mkdir(parents=True) clean_folder(tmp_out_dir, recreate=True)