From 7f94e1b0b3ae61dee05c5623e881c0ce12d93531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3bel?= Date: Fri, 30 Sep 2022 11:53:12 +0200 Subject: [PATCH] #28: - separate the tests - put tests in separated directories - saved tutorials_build.py in scripts --- end-to-end-roms/tests/CMakeLists.txt | 28 +--- end-to-end-roms/tests/test_1/CMakeLists.txt | 16 +++ end-to-end-roms/tests/{ => test_1}/do.py | 0 .../tests/{ => test_1}/fake_affine_shift.txt | 0 .../tests/{ => test_1}/fake_basis.bin | Bin .../{ => test_1}/fake_sample_mesh_gids.txt | 0 .../{ => test_1}/fake_stencil_mesh_gids.txt | 0 end-to-end-roms/tests/{ => test_1}/main.cc | 0 .../test_galerkin_default/CMakeLists.txt | 8 ++ .../test_galerkin_default.py | 127 ++++++++++++++++ .../test_galerkin_hypred_1/CMakeLists.txt | 8 ++ .../test_galerkin_hypred_1.py | 133 +++++++++++++++++ .../tests/test_lspg_default/CMakeLists.txt | 8 ++ .../test_lspg_default/test_lspg_default.py | 132 +++++++++++++++++ .../tests/test_lspg_hypred_1/CMakeLists.txt | 8 ++ .../test_lspg_hypred_1/test_lspg_hypred_1.py | 136 ++++++++++++++++++ scripts/tutorials_build.py | 62 ++++++++ 17 files changed, 643 insertions(+), 23 deletions(-) create mode 100644 end-to-end-roms/tests/test_1/CMakeLists.txt rename end-to-end-roms/tests/{ => test_1}/do.py (100%) rename end-to-end-roms/tests/{ => test_1}/fake_affine_shift.txt (100%) rename end-to-end-roms/tests/{ => test_1}/fake_basis.bin (100%) rename end-to-end-roms/tests/{ => test_1}/fake_sample_mesh_gids.txt (100%) rename end-to-end-roms/tests/{ => test_1}/fake_stencil_mesh_gids.txt (100%) rename end-to-end-roms/tests/{ => test_1}/main.cc (100%) create mode 100644 end-to-end-roms/tests/test_galerkin_default/CMakeLists.txt create mode 100644 end-to-end-roms/tests/test_galerkin_default/test_galerkin_default.py create mode 100644 end-to-end-roms/tests/test_galerkin_hypred_1/CMakeLists.txt create mode 100644 end-to-end-roms/tests/test_galerkin_hypred_1/test_galerkin_hypred_1.py create mode 100644 end-to-end-roms/tests/test_lspg_default/CMakeLists.txt create mode 100644 end-to-end-roms/tests/test_lspg_default/test_lspg_default.py create mode 100644 end-to-end-roms/tests/test_lspg_hypred_1/CMakeLists.txt create mode 100644 end-to-end-roms/tests/test_lspg_hypred_1/test_lspg_hypred_1.py create mode 100644 scripts/tutorials_build.py diff --git a/end-to-end-roms/tests/CMakeLists.txt b/end-to-end-roms/tests/CMakeLists.txt index 84fb5b4..3e22ff1 100644 --- a/end-to-end-roms/tests/CMakeLists.txt +++ b/end-to-end-roms/tests/CMakeLists.txt @@ -1,23 +1,5 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../cpp) - -configure_file(fake_basis.bin ${CMAKE_CURRENT_BINARY_DIR}/fake_basis.bin COPYONLY) -configure_file(fake_affine_shift.txt ${CMAKE_CURRENT_BINARY_DIR}/fake_affine_shift.txt COPYONLY) -configure_file(fake_sample_mesh_gids.txt ${CMAKE_CURRENT_BINARY_DIR}/fake_sample_mesh_gids.txt COPYONLY) -configure_file(fake_stencil_mesh_gids.txt ${CMAKE_CURRENT_BINARY_DIR}/fake_stencil_mesh_gids.txt COPYONLY) - -set(testName endtoend_test1) -add_executable(${testName} main.cc) -add_test(NAME ${testName} COMMAND ${testName}) -set_tests_properties( - ${testName} - PROPERTIES - PASS_REGULAR_EXPRESSION "PASS" - FAIL_REGULAR_EXPRESSION "FAILED" -) - -include(FindPythonInterp) -set (python_file "end2end_test.py") -execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${python_file} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/end2end_dry - ) +add_subdirectory(test_1) +add_subdirectory(test_galerkin_default) +add_subdirectory(test_galerkin_hypred_1) +add_subdirectory(test_lspg_default) +add_subdirectory(test_lspg_hypred_1) diff --git a/end-to-end-roms/tests/test_1/CMakeLists.txt b/end-to-end-roms/tests/test_1/CMakeLists.txt new file mode 100644 index 0000000..9084d81 --- /dev/null +++ b/end-to-end-roms/tests/test_1/CMakeLists.txt @@ -0,0 +1,16 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../cpp) + +configure_file(fake_basis.bin ${CMAKE_CURRENT_BINARY_DIR}/fake_basis.bin COPYONLY) +configure_file(fake_affine_shift.txt ${CMAKE_CURRENT_BINARY_DIR}/fake_affine_shift.txt COPYONLY) +configure_file(fake_sample_mesh_gids.txt ${CMAKE_CURRENT_BINARY_DIR}/fake_sample_mesh_gids.txt COPYONLY) +configure_file(fake_stencil_mesh_gids.txt ${CMAKE_CURRENT_BINARY_DIR}/fake_stencil_mesh_gids.txt COPYONLY) + +set(testName endtoend_test1) +add_executable(${testName} main.cc) +add_test(NAME ${testName} COMMAND ${testName}) +set_tests_properties( + ${testName} + PROPERTIES + PASS_REGULAR_EXPRESSION "PASS" + FAIL_REGULAR_EXPRESSION "FAILED" +) diff --git a/end-to-end-roms/tests/do.py b/end-to-end-roms/tests/test_1/do.py similarity index 100% rename from end-to-end-roms/tests/do.py rename to end-to-end-roms/tests/test_1/do.py diff --git a/end-to-end-roms/tests/fake_affine_shift.txt b/end-to-end-roms/tests/test_1/fake_affine_shift.txt similarity index 100% rename from end-to-end-roms/tests/fake_affine_shift.txt rename to end-to-end-roms/tests/test_1/fake_affine_shift.txt diff --git a/end-to-end-roms/tests/fake_basis.bin b/end-to-end-roms/tests/test_1/fake_basis.bin similarity index 100% rename from end-to-end-roms/tests/fake_basis.bin rename to end-to-end-roms/tests/test_1/fake_basis.bin diff --git a/end-to-end-roms/tests/fake_sample_mesh_gids.txt b/end-to-end-roms/tests/test_1/fake_sample_mesh_gids.txt similarity index 100% rename from end-to-end-roms/tests/fake_sample_mesh_gids.txt rename to end-to-end-roms/tests/test_1/fake_sample_mesh_gids.txt diff --git a/end-to-end-roms/tests/fake_stencil_mesh_gids.txt b/end-to-end-roms/tests/test_1/fake_stencil_mesh_gids.txt similarity index 100% rename from end-to-end-roms/tests/fake_stencil_mesh_gids.txt rename to end-to-end-roms/tests/test_1/fake_stencil_mesh_gids.txt diff --git a/end-to-end-roms/tests/main.cc b/end-to-end-roms/tests/test_1/main.cc similarity index 100% rename from end-to-end-roms/tests/main.cc rename to end-to-end-roms/tests/test_1/main.cc diff --git a/end-to-end-roms/tests/test_galerkin_default/CMakeLists.txt b/end-to-end-roms/tests/test_galerkin_default/CMakeLists.txt new file mode 100644 index 0000000..c1638fb --- /dev/null +++ b/end-to-end-roms/tests/test_galerkin_default/CMakeLists.txt @@ -0,0 +1,8 @@ +include(FindPythonInterp) +set (python_file "test_galerkin_default.py") +set (build_dir "${CMAKE_CURRENT_BINARY_DIR}../../../..") +add_test( + NAME test_galerkin_default + COMMAND ${PYTHON_EXECUTABLE} ${python_file} ${build_dir} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/end-to-end-roms/tests/test_galerkin_default/test_galerkin_default.py b/end-to-end-roms/tests/test_galerkin_default/test_galerkin_default.py new file mode 100644 index 0000000..042ae0a --- /dev/null +++ b/end-to-end-roms/tests/test_galerkin_default/test_galerkin_default.py @@ -0,0 +1,127 @@ +import os +import sys + +try: + tutorials_dir = f'{os.sep}'.join(os.path.abspath(__file__).split(os.sep)[:-4]) + sys.path.append(tutorials_dir) +except Exception as e: + print(f'Can not add project path to system path! Exiting!\nERROR: {e}') + raise SystemExit(1) + +import subprocess +import unittest +import yaml + + +class GalerkinDefault(unittest.TestCase): + BUILD_DIR = "" + + def setUp(self): + self.tutorial_build_dir = os.path.abspath(GalerkinDefault.BUILD_DIR) + self.wf_foms = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_foms.py') + self.wf_offline_rom = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_offline_rom.py') + + def test_2d_swe_galerkin_default(self): + tutorials_build_dir_name = '2d_swe_galerkin_default' + cwd = os.path.join(self.tutorial_build_dir, 'end-to-end-roms', tutorials_build_dir_name) + # Running wf_foms + wf_foms_command = ['python3', self.wf_foms, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_foms_command)}\n==> Working dir: {cwd}') + wf_foms_build = subprocess.run(wf_foms_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_foms_build.stdout) + # Running wf_offline_rom + wf_offline_rom_command = ['python3', self.wf_offline_rom, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_offline_rom_command)}\n==> Working dir: {cwd}') + wf_offline_rom_build = subprocess.run(wf_offline_rom_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_offline_rom_build.stdout) + # Running wf_galerkin + wf_galerkin = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_galerkin.py') + wf_galerkin_command = ['python3', wf_galerkin, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_galerkin_command)}\n==> Working dir: {cwd}') + wf_offline_rom_build = subprocess.run(wf_galerkin_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_offline_rom_build.stdout) + # Assertions + # fom_test_runid_0 + fom_test_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -0.5, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10, 'rhsSamplingFreq': 100} + fom_test_runid_0_input = os.path.join(cwd, 'fom_test_runid_0', 'input.yaml') + with open(fom_test_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_test_runid_0_input}') + self.assertEqual(fom_test_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_0 + fom_train_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -1.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10, 'rhsSamplingFreq': 5} + fom_train_runid_0_input = os.path.join(cwd, 'fom_train_runid_0', 'input.yaml') + with open(fom_train_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_0_input}') + self.assertEqual(fom_train_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_1 + fom_train_runid_1 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, + 'problem': '2d_swe', 'runId': 1, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': 0.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10, 'rhsSamplingFreq': 5} + fom_train_runid_1_input = os.path.join(cwd, 'fom_train_runid_1', 'input.yaml') + with open(fom_train_runid_1_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_1_input}') + self.assertEqual(fom_train_runid_1, input_yaml_dict) + print(f'==> Assertion passed.') + # offline_rom + offline_rom = {'stateData': {'useTrainingRuns': 'all'}, 'rhsData': {'useTrainingRuns': 'all'}} + offline_rom_input = os.path.join(cwd, 'offline_rom', 'pod_input.yaml') + with open(offline_rom_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {offline_rom_input}') + self.assertEqual(offline_rom, input_yaml_dict) + print(f'==> Assertion passed.') + # default_galerkin_99_999 + default_galerkin_99_999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, 'problem': '2d_swe', + 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, 'coriolis': -0.5, 'pulsemag': 0.125, + 'gravity': 9.8, 'finalTime': 5.0, 'stateSamplingFreq': 10, 'rhsSamplingFreq': 100, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/default_galerkin_truncation_energybased_99.999_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'defaultGalerkin', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/default_galerkin_truncation_energybased_99.999_runid_0/rom_initial_state.txt'}} + default_galerkin_99_999_input = os.path.join(cwd, + 'default_galerkin_truncation_energybased_99.999_runid_0', + 'input.yaml') + with open(default_galerkin_99_999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {default_galerkin_99_999_input}') + self.assertEqual(default_galerkin_99_999, input_yaml_dict) + print(f'==> Assertion passed.') + # default_galerkin_99_99999 + default_galerkin_99_99999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, 'problem': '2d_swe', + 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, 'coriolis': -0.5, 'pulsemag': 0.125, + 'gravity': 9.8, 'finalTime': 5.0, 'stateSamplingFreq': 10, 'rhsSamplingFreq': 100, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/default_galerkin_truncation_energybased_99.99999_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'defaultGalerkin', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/default_galerkin_truncation_energybased_99.99999_runid_0/rom_initial_state.txt'}} + default_galerkin_99_99999_input = os.path.join(cwd, + 'default_galerkin_truncation_energybased_99.99999_runid_0', + 'input.yaml') + with open(default_galerkin_99_99999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {default_galerkin_99_99999_input}') + self.assertEqual(default_galerkin_99_99999, input_yaml_dict) + print(f'==> Assertion passed.') + + +if __name__ == "__main__": + if len(sys.argv) > 1: + GalerkinDefault.BUILD_DIR = sys.argv.pop() + unittest.main() diff --git a/end-to-end-roms/tests/test_galerkin_hypred_1/CMakeLists.txt b/end-to-end-roms/tests/test_galerkin_hypred_1/CMakeLists.txt new file mode 100644 index 0000000..32cb26f --- /dev/null +++ b/end-to-end-roms/tests/test_galerkin_hypred_1/CMakeLists.txt @@ -0,0 +1,8 @@ +include(FindPythonInterp) +set (python_file "test_galerkin_hypred_1.py") +set (build_dir "${CMAKE_CURRENT_BINARY_DIR}../../../..") +add_test( + NAME test_galerkin_hypred_1 + COMMAND ${PYTHON_EXECUTABLE} ${python_file} ${build_dir} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/end-to-end-roms/tests/test_galerkin_hypred_1/test_galerkin_hypred_1.py b/end-to-end-roms/tests/test_galerkin_hypred_1/test_galerkin_hypred_1.py new file mode 100644 index 0000000..2e3619b --- /dev/null +++ b/end-to-end-roms/tests/test_galerkin_hypred_1/test_galerkin_hypred_1.py @@ -0,0 +1,133 @@ +import os +import sys + +try: + tutorials_dir = f'{os.sep}'.join(os.path.abspath(__file__).split(os.sep)[:-4]) + sys.path.append(tutorials_dir) +except Exception as e: + print(f'Can not add project path to system path! Exiting!\nERROR: {e}') + raise SystemExit(1) + +import subprocess +import unittest +import yaml + + +class GalerkinHypred(unittest.TestCase): + BUILD_DIR = "" + + def setUp(self): + self.tutorial_build_dir = os.path.abspath(GalerkinHypred.BUILD_DIR) + self.wf_foms = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_foms.py') + self.wf_offline_rom = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_offline_rom.py') + + def test_2d_swe_galerkin_hypred_1(self): + tutorials_build_dir_name = '2d_swe_galerkin_hypred_1' + cwd = os.path.join(self.tutorial_build_dir, 'end-to-end-roms', tutorials_build_dir_name) + # Running wf_foms + wf_foms_command = ['python3', self.wf_foms, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_foms_command)}\n==> Working dir: {cwd}') + wf_foms_build = subprocess.run(wf_foms_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_foms_build.stdout) + # Running wf_offline_rom + wf_offline_rom_command = ['python3', self.wf_offline_rom, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_offline_rom_command)}\n==> Working dir: {cwd}') + wf_offline_rom_build = subprocess.run(wf_offline_rom_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_offline_rom_build.stdout) + # Running wf_galerkin + wf_galerkin = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_galerkin.py') + wf_galerkin_command = ['python3', wf_galerkin, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_galerkin_command)}\n==> Working dir: {cwd}') + wf_offline_rom_build = subprocess.run(wf_galerkin_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_offline_rom_build.stdout) + # Assertions + # fom_test_runid_0 + fom_test_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -0.5, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10, 'rhsSamplingFreq': 100} + fom_test_runid_0_input = os.path.join(cwd, 'fom_test_runid_0', 'input.yaml') + with open(fom_test_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_test_runid_0_input}') + self.assertEqual(fom_test_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_0 + fom_train_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -1.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10, 'rhsSamplingFreq': 10} + fom_train_runid_0_input = os.path.join(cwd, 'fom_train_runid_0', 'input.yaml') + with open(fom_train_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_0_input}') + self.assertEqual(fom_train_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_1 + fom_train_runid_1 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, + 'problem': '2d_swe', 'runId': 1, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': 0.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10, 'rhsSamplingFreq': 10} + fom_train_runid_1_input = os.path.join(cwd, 'fom_train_runid_1', 'input.yaml') + with open(fom_train_runid_1_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_1_input}') + self.assertEqual(fom_train_runid_1, input_yaml_dict) + print(f'==> Assertion passed.') + # offline_rom + offline_rom = {'stateData': {'useTrainingRuns': 'all'}, 'rhsData': {'useTrainingRuns': 'all'}} + offline_rom_input = os.path.join(cwd, 'offline_rom', 'pod_input.yaml') + with open(offline_rom_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {offline_rom_input}') + self.assertEqual(offline_rom, input_yaml_dict) + print(f'==> Assertion passed.') + # hyperreduced_galerkin_99_999 + hyperreduced_galerkin_99_999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, 'problem': '2d_swe', + 'runId': 0, 'meshDir': f'{cwd}/offline_rom/sample_mesh_random_0.100', 'numDofsPerCell': 3, 'coriolis': -0.5, + 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, 'stateSamplingFreq': 10, 'rhsSamplingFreq': 100, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/hyperreduced_galerkin_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'hyperreducedGalerkin', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/hyperreduced_galerkin_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0/rom_initial_state.txt', + 'galerkinHypRedOperatorFile': f'{cwd}/hyperreducer_99.999_sample_mesh_random_0.100/hyperReductionOperator.bin', + 'stencilMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/stencil_mesh_gids.dat', + 'sampleMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/sample_mesh_gids.txt'}} + hyperreduced_galerkin_99_999_input = os.path.join(cwd, + 'hyperreduced_galerkin_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0', + 'input.yaml') + with open(hyperreduced_galerkin_99_999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {hyperreduced_galerkin_99_999_input}') + self.assertEqual(hyperreduced_galerkin_99_999, input_yaml_dict) + print(f'==> Assertion passed.') + # hyperreduced_galerkin_99_99999 + hyperreduced_galerkin_99_99999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'RK4', 'timeStepSize': 0.005, 'problem': '2d_swe', + 'runId': 0, 'meshDir': f'{cwd}/offline_rom/sample_mesh_random_0.100', 'numDofsPerCell': 3, 'coriolis': -0.5, + 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, 'stateSamplingFreq': 10, 'rhsSamplingFreq': 100, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/hyperreduced_galerkin_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'hyperreducedGalerkin', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/hyperreduced_galerkin_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0/rom_initial_state.txt', + 'galerkinHypRedOperatorFile': f'{cwd}/hyperreducer_99.99999_sample_mesh_random_0.100/hyperReductionOperator.bin', + 'stencilMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/stencil_mesh_gids.dat', + 'sampleMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/sample_mesh_gids.txt'}} + hyperreduced_galerkin_99_99999_input = os.path.join(cwd, + 'hyperreduced_galerkin_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0', + 'input.yaml') + with open(hyperreduced_galerkin_99_99999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {hyperreduced_galerkin_99_99999_input}') + self.assertEqual(hyperreduced_galerkin_99_99999, input_yaml_dict) + print(f'==> Assertion passed.') + + +if __name__ == "__main__": + if len(sys.argv) > 1: + GalerkinHypred.BUILD_DIR = sys.argv.pop() + unittest.main() diff --git a/end-to-end-roms/tests/test_lspg_default/CMakeLists.txt b/end-to-end-roms/tests/test_lspg_default/CMakeLists.txt new file mode 100644 index 0000000..f5685aa --- /dev/null +++ b/end-to-end-roms/tests/test_lspg_default/CMakeLists.txt @@ -0,0 +1,8 @@ +include(FindPythonInterp) +set (python_file "test_lspg_default.py") +set (build_dir "${CMAKE_CURRENT_BINARY_DIR}../../../..") +add_test( + NAME test_lspg_default + COMMAND ${PYTHON_EXECUTABLE} ${python_file} ${build_dir} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/end-to-end-roms/tests/test_lspg_default/test_lspg_default.py b/end-to-end-roms/tests/test_lspg_default/test_lspg_default.py new file mode 100644 index 0000000..f2def23 --- /dev/null +++ b/end-to-end-roms/tests/test_lspg_default/test_lspg_default.py @@ -0,0 +1,132 @@ +import os +import sys + +try: + tutorials_dir = f'{os.sep}'.join(os.path.abspath(__file__).split(os.sep)[:-4]) + sys.path.append(tutorials_dir) +except Exception as e: + print(f'Can not add project path to system path! Exiting!\nERROR: {e}') + raise SystemExit(1) + +import subprocess +import unittest +import yaml + + +class LspgDefault(unittest.TestCase): + BUILD_DIR = "" + + def setUp(self): + self.tutorial_build_dir = os.path.abspath(LspgDefault.BUILD_DIR) + self.wf_foms = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_foms.py') + self.wf_offline_rom = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_offline_rom.py') + + def test_2d_swe_lspg_default(self): + tutorials_build_dir_name = '2d_swe_lspg_default' + cwd = os.path.join(self.tutorial_build_dir, 'end-to-end-roms', tutorials_build_dir_name) + # Running wf_foms + wf_foms_command = ['python3', self.wf_foms, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_foms_command)}\n==> Working dir: {cwd}') + wf_foms_build = subprocess.run(wf_foms_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_foms_build.stdout) + # Running wf_offline_rom + wf_offline_rom_command = ['python3', self.wf_offline_rom, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_offline_rom_command)}\n==> Working dir: {cwd}') + wf_offline_rom_build = subprocess.run(wf_offline_rom_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_offline_rom_build.stdout) + # Running wf_lspg + wf_lspg = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_lspg.py') + wf_lspg_command = ['python3', wf_lspg, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_lspg_command)}\n==> Working dir: {cwd}') + wf_lspg_build = subprocess.run(wf_lspg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_lspg_build.stdout) + # Assertions + # fom_test_runid_0 + fom_test_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'NewtonRaphson', 'nonlinearSolverTolerance': '1e-6', + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -0.5, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10} + fom_test_runid_0_input = os.path.join(cwd, 'fom_test_runid_0', 'input.yaml') + with open(fom_test_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_test_runid_0_input}') + self.assertEqual(fom_test_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_0 + fom_train_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'NewtonRaphson', 'nonlinearSolverTolerance': '1e-6', + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -1.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10} + fom_train_runid_0_input = os.path.join(cwd, 'fom_train_runid_0', 'input.yaml') + with open(fom_train_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_0_input}') + self.assertEqual(fom_train_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_1 + fom_train_runid_1 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'NewtonRaphson', 'nonlinearSolverTolerance': '1e-6', + 'problem': '2d_swe', 'runId': 1, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': 0.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10} + fom_train_runid_1_input = os.path.join(cwd, 'fom_train_runid_1', 'input.yaml') + with open(fom_train_runid_1_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_1_input}') + self.assertEqual(fom_train_runid_1, input_yaml_dict) + print(f'==> Assertion passed.') + # offline_rom + offline_rom = {'stateData': {'useTrainingRuns': 'all'}} + offline_rom_input = os.path.join(cwd, 'offline_rom', 'pod_input.yaml') + with open(offline_rom_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {offline_rom_input}') + self.assertEqual(offline_rom, input_yaml_dict) + print(f'==> Assertion passed.') + # default_lspg_99_999 + default_lspg_99_999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'GaussNewton', 'nonlinearSolverTolerance': '1e-6', 'problem': '2d_swe', 'runId': 0, + 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, 'coriolis': -0.5, 'pulsemag': 0.125, 'gravity': 9.8, + 'finalTime': 5.0, 'stateSamplingFreq': 10, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/default_lspg_truncation_energybased_99.999_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'defaultLspg', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/default_lspg_truncation_energybased_99.999_runid_0/rom_initial_state.txt'}} + default_lspg_99_999_input = os.path.join(cwd, + 'default_lspg_truncation_energybased_99.999_runid_0', + 'input.yaml') + with open(default_lspg_99_999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {default_lspg_99_999_input}') + self.assertEqual(default_lspg_99_999, input_yaml_dict) + print(f'==> Assertion passed.') + # default_lspg_99_99999 + default_lspg_99_99999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'GaussNewton', 'nonlinearSolverTolerance': '1e-6', 'problem': '2d_swe', 'runId': 0, + 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, 'coriolis': -0.5, 'pulsemag': 0.125, 'gravity': 9.8, + 'finalTime': 5.0, 'stateSamplingFreq': 10, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/default_lspg_truncation_energybased_99.99999_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'defaultLspg', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/default_lspg_truncation_energybased_99.99999_runid_0/rom_initial_state.txt'}} + default_lspg_99_99999_input = os.path.join(cwd, + 'default_lspg_truncation_energybased_99.99999_runid_0', + 'input.yaml') + with open(default_lspg_99_99999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {default_lspg_99_99999_input}') + self.assertEqual(default_lspg_99_99999, input_yaml_dict) + print(f'==> Assertion passed.') + + +if __name__ == "__main__": + if len(sys.argv) > 1: + LspgDefault.BUILD_DIR = sys.argv.pop() + unittest.main() diff --git a/end-to-end-roms/tests/test_lspg_hypred_1/CMakeLists.txt b/end-to-end-roms/tests/test_lspg_hypred_1/CMakeLists.txt new file mode 100644 index 0000000..cbce97c --- /dev/null +++ b/end-to-end-roms/tests/test_lspg_hypred_1/CMakeLists.txt @@ -0,0 +1,8 @@ +include(FindPythonInterp) +set (python_file "test_lspg_hypred_1.py") +set (build_dir "${CMAKE_CURRENT_BINARY_DIR}../../../..") +add_test( + NAME test_lspg_hypred_1 + COMMAND ${PYTHON_EXECUTABLE} ${python_file} ${build_dir} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/end-to-end-roms/tests/test_lspg_hypred_1/test_lspg_hypred_1.py b/end-to-end-roms/tests/test_lspg_hypred_1/test_lspg_hypred_1.py new file mode 100644 index 0000000..11f90bf --- /dev/null +++ b/end-to-end-roms/tests/test_lspg_hypred_1/test_lspg_hypred_1.py @@ -0,0 +1,136 @@ +import os +import sys + +try: + tutorials_dir = f'{os.sep}'.join(os.path.abspath(__file__).split(os.sep)[:-4]) + sys.path.append(tutorials_dir) +except Exception as e: + print(f'Can not add project path to system path! Exiting!\nERROR: {e}') + raise SystemExit(1) + +import subprocess +import unittest +import yaml + + +class LspgHypred(unittest.TestCase): + BUILD_DIR = "" + + def setUp(self): + self.tutorial_build_dir = os.path.abspath(LspgHypred.BUILD_DIR) + self.wf_foms = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_foms.py') + self.wf_offline_rom = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_offline_rom.py') + + def test_2d_swe_lspg_hypred_1(self): + tutorials_build_dir_name = '2d_swe_lspg_hypred_1' + cwd = os.path.join(self.tutorial_build_dir, 'end-to-end-roms', tutorials_build_dir_name) + # Running wf_foms + wf_foms_command = ['python3', self.wf_foms, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_foms_command)}\n==> Working dir: {cwd}') + wf_foms_build = subprocess.run(wf_foms_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_foms_build.stdout) + # Running wf_offline_rom + wf_offline_rom_command = ['python3', self.wf_offline_rom, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_offline_rom_command)}\n==> Working dir: {cwd}') + wf_offline_rom_build = subprocess.run(wf_offline_rom_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_offline_rom_build.stdout) + # Running wf_lspg + wf_lspg = os.path.join(tutorials_dir, 'end-to-end-roms', 'wf_lspg.py') + wf_lspg_command = ['python3', wf_lspg, '--wf', 'wf.yaml', '--dryrun', 'True'] + print(f'===> Running...\n==> Command: {" ".join(wf_lspg_command)}\n==> Working dir: {cwd}') + wf_lspg_build = subprocess.run(wf_lspg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding='utf-8', cwd=cwd) + print(wf_lspg_build.stdout) + # Assertions + # fom_test_runid_0 + fom_test_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'NewtonRaphson', 'nonlinearSolverTolerance': '1e-6', + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', + 'numDofsPerCell': 3, 'coriolis': -0.5, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10} + fom_test_runid_0_input = os.path.join(cwd, 'fom_test_runid_0', 'input.yaml') + with open(fom_test_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_test_runid_0_input}') + self.assertEqual(fom_test_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_0 + fom_train_runid_0 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'NewtonRaphson', 'nonlinearSolverTolerance': '1e-6', + 'problem': '2d_swe', 'runId': 0, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': -1.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10} + fom_train_runid_0_input = os.path.join(cwd, 'fom_train_runid_0', 'input.yaml') + with open(fom_train_runid_0_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_0_input}') + self.assertEqual(fom_train_runid_0, input_yaml_dict) + print(f'==> Assertion passed.') + # fom_train_runid_1 + fom_train_runid_1 = {'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'NewtonRaphson', 'nonlinearSolverTolerance': '1e-6', + 'problem': '2d_swe', 'runId': 1, 'meshDir': f'{cwd}/fom_mesh', 'numDofsPerCell': 3, + 'coriolis': 0.0, 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, + 'stateSamplingFreq': 10} + fom_train_runid_1_input = os.path.join(cwd, 'fom_train_runid_1', 'input.yaml') + with open(fom_train_runid_1_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {fom_train_runid_1_input}') + self.assertEqual(fom_train_runid_1, input_yaml_dict) + print(f'==> Assertion passed.') + # offline_rom + offline_rom = {'stateData': {'useTrainingRuns': 'all'}} + offline_rom_input = os.path.join(cwd, 'offline_rom', 'pod_input.yaml') + with open(offline_rom_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {offline_rom_input}') + self.assertEqual(offline_rom, input_yaml_dict) + print(f'==> Assertion passed.') + # default_lspg_99_999 + default_lspg_99_999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'GaussNewton', 'nonlinearSolverTolerance': '1e-6', 'problem': '2d_swe', 'runId': 0, + 'meshDir': f'{cwd}/offline_rom/sample_mesh_random_0.100', 'numDofsPerCell': 3, 'coriolis': -0.5, + 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, 'stateSamplingFreq': 10, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/hyperreduced_lspg_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'hyperreducedLspg', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/hyperreduced_lspg_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0/rom_initial_state.txt', + 'stencilMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/stencil_mesh_gids.dat', + 'sampleMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/sample_mesh_gids.txt'}} + default_lspg_99_999_input = os.path.join(cwd, + 'hyperreduced_lspg_truncation_energybased_99.999_sample_mesh_random_0.100_runid_0', + 'input.yaml') + with open(default_lspg_99_999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {default_lspg_99_999_input}') + self.assertEqual(default_lspg_99_999, input_yaml_dict) + print(f'==> Assertion passed.') + # default_lspg_99_99999 + default_lspg_99_99999 = { + 'inviscidFluxReconstruction': 'Weno3', 'odeScheme': 'BDF1', 'timeStepSize': 0.01, + 'nonlinearSolverName': 'GaussNewton', 'nonlinearSolverTolerance': '1e-6', 'problem': '2d_swe', 'runId': 0, + 'meshDir': f'{cwd}/offline_rom/sample_mesh_random_0.100', 'numDofsPerCell': 3, 'coriolis': -0.5, + 'pulsemag': 0.125, 'gravity': 9.8, 'finalTime': 5.0, 'stateSamplingFreq': 10, + 'rom': {'fullMeshPodFile': f'{cwd}/offline_rom/state_left_singular_vectors.bin', + 'affineShiftFile': f'{cwd}/hyperreduced_lspg_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0/optional_affine_shift.txt', + 'isAffine': False, 'algorithm': 'hyperreducedLspg', 'numModes': 22, + 'romInitialStateFile': f'{cwd}/hyperreduced_lspg_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0/rom_initial_state.txt', + 'stencilMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/stencil_mesh_gids.dat', + 'sampleMeshGidsFile': f'{cwd}/offline_rom/sample_mesh_random_0.100/sample_mesh_gids.txt'}} + default_lspg_99_99999_input = os.path.join(cwd, + 'hyperreduced_lspg_truncation_energybased_99.99999_sample_mesh_random_0.100_runid_0', + 'input.yaml') + with open(default_lspg_99_99999_input, 'rt') as input_yaml: + input_yaml_dict = yaml.safe_load(input_yaml) + print(f'===> Asserting...\n==> File: {default_lspg_99_99999_input}') + self.assertEqual(default_lspg_99_99999, input_yaml_dict) + print(f'==> Assertion passed.') + + +if __name__ == "__main__": + if len(sys.argv) > 1: + LspgHypred.BUILD_DIR = sys.argv.pop() + unittest.main() diff --git a/scripts/tutorials_build.py b/scripts/tutorials_build.py new file mode 100644 index 0000000..830fa6b --- /dev/null +++ b/scripts/tutorials_build.py @@ -0,0 +1,62 @@ +import os +import sys + +try: + tutorials_dir = f'{os.sep}'.join(os.path.abspath(__file__).split(os.sep)[:-4]) + sys.path.append(tutorials_dir) +except Exception as e: + print(f'Can not add project path to system path! Exiting!\nERROR: {e}') + raise SystemExit(1) + +import subprocess + + +def build_tutorials() -> None: + """ Build Pressio-tutorials before the tests. """ + # Finding compiler + print(f'==================================================\n===> Finding compiler...') + cxx = subprocess.run(['which', 'g++'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding='utf-8').stdout.replace('\n', '') + if cxx: + print(f'===> Found cpp compiler: {cxx}') + os.environ['CXX'] = cxx + else: + raise FileNotFoundError('=> Can not find a cpp compiler. Exiting.') + + # Setting tutorials build directory + print(f'--------------------------------------------------\n===> Setting tutorials build directory...') + up_tutorials_dir = f'{os.sep}'.join(os.path.abspath(__file__).split(os.sep)[:-5]) + tutorial_build_dir = os.path.join(up_tutorials_dir, 'pressio-tutorials-build') + if not os.path.exists(tutorial_build_dir): + os.makedirs(tutorial_build_dir) + print(f'===> Created tutorials build directory: {tutorial_build_dir}') + else: + raise FileExistsError(f'=> Directory already exists: {tutorial_build_dir}') + os.environ['BUILDDIR'] = tutorial_build_dir + + # Setting CMake build + print(f'--------------------------------------------------\n===> Setting CMake build...') + cmake_args = ['cmake', '-DCMAKE_BUILD_TYPE=Release', '-S', tutorials_dir, '-B', tutorial_build_dir] + print(f'===> Running command: {" ".join(cmake_args)}') + cmake_build = subprocess.run(cmake_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') + print(cmake_build.stdout) + + # Building tutorials + print(f'--------------------------------------------------\n===> Building tutorials') + num_of_proc = os.cpu_count() + print(f'===> Found: {num_of_proc} CPU\'s') + make_args = ['make', f'-j{num_of_proc}'] + print(f'===> Running command: {" ".join(make_args)}') + make_build = subprocess.run(make_args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding='utf-8', + cwd=tutorial_build_dir) + print(make_build.stdout) + print(f'===> Build finished.\n==================================================') + + +if __name__ == "__main__": + build_tutorials()