diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5e640a73..5827b487 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,2 +1,2 @@ # Contributing -Please see [Contributing section from PyTwin documentation](https://twin.docs.pyansys.com/contributing.html). +Please see [Contributing section from PyTwin documentation](https://twin.docs.pyansys.com/dev/contributing.html). diff --git a/doc/source/api/index.rst b/doc/source/api/index.rst index e89ac61f..45c4ba44 100644 --- a/doc/source/api/index.rst +++ b/doc/source/api/index.rst @@ -24,8 +24,8 @@ to facilitate the manipulation and execution of Twin Runtimes. Global Settings --------------- -:ref:`ref_index_api_logging` describe the global settings available from PyTwin package and how to -change them from their default values +:ref:`ref_index_api_logging` describe the global settings (e.g. logging and working directory options) available from +PyTwin package and how to change them from their default values .. currentmodule:: pytwin @@ -39,4 +39,4 @@ change them from their default values sdk/index evaluate/index - logging/index \ No newline at end of file + logging/index diff --git a/doc/source/conf.py b/doc/source/conf.py index b49954cb..bb7a64b5 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -3,11 +3,10 @@ import os from ansys_sphinx_theme import ansys_favicon, get_version_match, pyansys_logo_black +from pytwin import __version__ import pyvista from sphinx_gallery.sorting import FileNameSortKey -from pytwin import __version__ - # -- Project information ----------------------------------------------------- project = "pytwin" copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved" diff --git a/doc/source/getting_started/index.rst b/doc/source/getting_started/index.rst index e13e1903..303aa05e 100644 --- a/doc/source/getting_started/index.rst +++ b/doc/source/getting_started/index.rst @@ -43,7 +43,6 @@ the latest release with: cd pytwin pip install pip -U pip install -e . - python codegen/allapigen.py # Generates the API files Any changes that you make locally are reflected in your setup after you restart diff --git a/doc/source/index.rst b/doc/source/index.rst index 0ca050b6..623f3787 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -17,9 +17,9 @@ Introduction An analytics-driven, simulation-based digital twin is a connected, virtual replica of an in-service physical asset, in the form of an integrated multi-domain system simulation, that mirrors the life and experience of the asset. Ansys Digital Twins enable system design and -optimization and predictive maintenance, and they optimize industrial asset management. +optimization as well as predictive maintenance, to optimize industrial asset management. By implementing Ansys Digital Twins, you can improve top-line revenue, manage bottom-line -costs and both gain and retain a competitive advantage. +costs and both gain and retain competitive advantages. .. image:: _static/ansys_dt.png :width: 800 @@ -42,7 +42,7 @@ to programmatically interact with, and control the execution of Twin Runtimes. Features -------- -Some of the many features in this primary PyTwin package, ``pytwin``, +Some of the many features in the PyTwin package,, ``pytwin``, allow you to: - Use the Twin Runtimes Core SDK to build your own consumption workflows based on atomic API calls, see :ref:`ref_index_api_sdk` @@ -51,7 +51,7 @@ allow you to: Documentation and issues ------------------------ -In addition to installation and usage information, the PyTwin +In addition to :ref:`getting_started` and :ref:`ref_user_guide`, the PyTwin documentation provides :ref:`ref_index_api`, :ref:`ref_example_gallery`, and :ref:`ref_contributing` sections. @@ -70,7 +70,7 @@ to the Digital Twins Runtimes SDK without changing the core behavior or license software's. The use of the interactive control of Ansys Digital Twins Runtimes through PyTwin requires a license of Twin Deployer. -For more information, see the `Ansys Twin Builder and Twin Deployer `_. +For more information, see `Ansys Twin Builder and Twin Deployer `_ on the Ansys website. Project index diff --git a/examples/evaluate/00-coupledClutches.py b/examples/evaluate/00-coupledClutches.py index a6734c93..d8df1ceb 100644 --- a/examples/evaluate/00-coupledClutches.py +++ b/examples/evaluate/00-coupledClutches.py @@ -22,12 +22,11 @@ import matplotlib.pyplot as plt import pandas as pd +from pytwin import TwinModel, download_file, load_data -from pytwin import TwinModel, examples - -twin_file = examples.download_file("CoupledClutches_23R1_other.twin", "twin_files") -csv_input = examples.download_file("CoupledClutches_input.csv", "twin_input_files") -twin_config = examples.download_file("CoupledClutches_config.json", "twin_input_files") +twin_file = download_file("CoupledClutches_23R1_other.twin", "twin_files") +csv_input = download_file("CoupledClutches_input.csv", "twin_input_files") +twin_config = download_file("CoupledClutches_config.json", "twin_input_files") ############################################################################### @@ -85,22 +84,16 @@ def plot_result_comparison(step_by_step_results: pd.DataFrame, batch_results: pd ############################################################################### -# Defining external files path -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Defining the runtime log path as well as loading the input data - -twin_model_input_df = examples.load_data(csv_input) -data_dimensions = twin_model_input_df.shape -number_of_datapoints = data_dimensions[0] - 1 - -############################################################################### -# Loading the Twin Runtime and instantiating it -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Loading the Twin Runtime and external CSV file +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Loading the Twin Runtime and instantiating it. print("Loading model: {}".format(twin_file)) twin_model = TwinModel(twin_file) +twin_model_input_df = load_data(csv_input) +data_dimensions = twin_model_input_df.shape +number_of_datapoints = data_dimensions[0] - 1 ############################################################################### # Setting up the initial settings of the Twin and initializing it diff --git a/examples/evaluate/01-electricRange.py b/examples/evaluate/01-electricRange.py index 7b0b282c..f6bd9a11 100644 --- a/examples/evaluate/01-electricRange.py +++ b/examples/evaluate/01-electricRange.py @@ -27,10 +27,9 @@ import matplotlib.pyplot as plt import pandas as pd +from pytwin import TwinModel, download_file -from pytwin import TwinModel, examples - -twin_file = examples.download_file("ElectricRange_23R1_other.twin", "twin_files") +twin_file = download_file("ElectricRange_23R1_other.twin", "twin_files") ############################################################################### # User inputs diff --git a/examples/evaluate/02-heatExchangerRS.py b/examples/evaluate/02-heatExchangerRS.py index f31c9ce2..8a82a106 100644 --- a/examples/evaluate/02-heatExchangerRS.py +++ b/examples/evaluate/02-heatExchangerRS.py @@ -26,10 +26,9 @@ import matplotlib.pyplot as plt import numpy import pandas as pd +from pytwin import TwinModel, download_file -from pytwin import TwinModel, examples - -twin_file = examples.download_file("HeatExchangerRS_23R1_other.twin", "twin_files") +twin_file = download_file("HeatExchangerRS_23R1_other.twin", "twin_files") ############################################################################### # User inputs diff --git a/examples/evaluate/03-scalarDROM.py b/examples/evaluate/03-scalarDROM.py index c96a8f51..39a6c7c2 100644 --- a/examples/evaluate/03-scalarDROM.py +++ b/examples/evaluate/03-scalarDROM.py @@ -29,11 +29,10 @@ import matplotlib.pyplot as plt import pandas as pd +from pytwin import TwinModel, download_file, load_data, modify_pytwin_working_dir -from pytwin import TwinModel, examples, modify_pytwin_working_dir - -twin_file = examples.download_file("HX_scalarDRB_23R1_other.twin", "twin_files") -csv_input = examples.download_file("HX_scalarDRB_input.csv", "twin_input_files") +twin_file = download_file("HX_scalarDRB_23R1_other.twin", "twin_files") +csv_input = download_file("HX_scalarDRB_input.csv", "twin_input_files") ############################################################################### @@ -88,7 +87,7 @@ def plot_result_comparison(step_by_step_results: pd.DataFrame, what_if: pd.DataF modify_pytwin_working_dir(os.path.join(os.path.dirname(twin_file), "pyTwinWorkingDir")) -twin_model_input_df = examples.load_data(csv_input) +twin_model_input_df = load_data(csv_input) data_dimensions = twin_model_input_df.shape number_of_datapoints = data_dimensions[0] - 1 diff --git a/examples/evaluate/04-TBROM_images.py b/examples/evaluate/04-TBROM_images.py index fe7f75fc..fa8028d2 100644 --- a/examples/evaluate/04-TBROM_images.py +++ b/examples/evaluate/04-TBROM_images.py @@ -38,11 +38,10 @@ from ansys.fluent.visualization.pyvista import Graphics import matplotlib.image as img import matplotlib.pyplot as plt +from pytwin import TwinModel, download_file -from pytwin import TwinModel, examples - -twin_file = examples.download_file("ThermalTBROM_23R1_other.twin", "twin_files") -cfd_file = examples.download_file("T_Junction.cas.h5", "other_files") +twin_file = download_file("ThermalTBROM_23R1_other.twin", "twin_files") +cfd_file = download_file("T_Junction.cas.h5", "other_files") set_config(blocking=True, set_view_on_display="isometric") diff --git a/examples/evaluate/05-TBROM_coSimulation_pyMAPDL.py b/examples/evaluate/05-TBROM_coSimulation_pyMAPDL.py index 700cbef1..659920a1 100644 --- a/examples/evaluate/05-TBROM_coSimulation_pyMAPDL.py +++ b/examples/evaluate/05-TBROM_coSimulation_pyMAPDL.py @@ -36,12 +36,11 @@ from ansys.mapdl.core import launch_mapdl import numpy as np import pandas as pd +from pytwin import TwinModel, download_file import pyvista as pv -from pytwin import TwinModel, examples - -twin_file = examples.download_file("ThermalTBROM_23R1_other.twin", "twin_files") -fea_file = examples.download_file("ThermalTBROM.dat", "other_files") +twin_file = download_file("ThermalTBROM_23R1_other.twin", "twin_files") +fea_file = download_file("ThermalTBROM.dat", "other_files") # start mapdl mapdl = launch_mapdl() diff --git a/pyproject.toml b/pyproject.toml index c278ee68..4880fdea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ authors = ["ANSYS, Inc. "] maintainers = ["PyAnsys developers "] readme = "README.rst" repository = "https://github.com/pyansys/pytwin" +documentation = "https://twin.docs.pyansys.com/" classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python :: 3", @@ -18,7 +19,7 @@ classifiers = [ "Operating System :: OS Independent", ] packages = [ - { include = "pytwin" }, + { include = "pytwin", from = "src/ansys" }, ] [tool.poetry.dependencies] @@ -57,7 +58,7 @@ profile = "black" force_sort_within_sections = true line_length = 120 default_section = "THIRDPARTY" -src_paths = ["doc", "pytwin", "tests"] +src_paths = ["doc", "src", "tests"] [tool.coverage.run] source = ["pytwin"] diff --git a/pytwin/examples/__init__.py b/pytwin/examples/__init__.py deleted file mode 100644 index 38f6fa3b..00000000 --- a/pytwin/examples/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .downloads import download_file, load_data diff --git a/pytwin/__init__.py b/src/ansys/pytwin/__init__.py similarity index 73% rename from pytwin/__init__.py rename to src/ansys/pytwin/__init__.py index c39abc71..19e6a010 100644 --- a/pytwin/__init__.py +++ b/src/ansys/pytwin/__init__.py @@ -10,7 +10,7 @@ """ PUBLIC API TO PYTWIN SETTINGS """ -from .settings import ( +from pytwin.settings import ( PyTwinLogLevel, PyTwinLogOption, PyTwinSettingsError, @@ -34,10 +34,15 @@ """ PUBLIC API TO PYTWIN EVALUATE """ -from .evaluate.twin_model import TwinModel, TwinModelError +from pytwin.evaluate.twin_model import TwinModel, TwinModelError """ PUBLIC API TO PYTWIN RUNTIME """ -from .twin_runtime.log_level import LogLevel -from .twin_runtime.twin_runtime_core import TwinRuntime, TwinRuntimeError +from pytwin.twin_runtime.log_level import LogLevel +from pytwin.twin_runtime.twin_runtime_core import TwinRuntime, TwinRuntimeError + +""" +PUBLIC API TO EXAMPLES +""" +from pytwin.examples.downloads import download_file, load_data diff --git a/pytwin/evaluate/__init__.py b/src/ansys/pytwin/evaluate/__init__.py similarity index 100% rename from pytwin/evaluate/__init__.py rename to src/ansys/pytwin/evaluate/__init__.py diff --git a/pytwin/evaluate/model.py b/src/ansys/pytwin/evaluate/model.py similarity index 100% rename from pytwin/evaluate/model.py rename to src/ansys/pytwin/evaluate/model.py diff --git a/pytwin/evaluate/saved_state_registry.py b/src/ansys/pytwin/evaluate/saved_state_registry.py similarity index 99% rename from pytwin/evaluate/saved_state_registry.py rename to src/ansys/pytwin/evaluate/saved_state_registry.py index 5b72cc5b..1fa79592 100644 --- a/pytwin/evaluate/saved_state_registry.py +++ b/src/ansys/pytwin/evaluate/saved_state_registry.py @@ -3,7 +3,6 @@ import uuid import numpy as np - from pytwin import get_pytwin_logger from pytwin.evaluate.model import Model diff --git a/pytwin/evaluate/twin_model.py b/src/ansys/pytwin/evaluate/twin_model.py similarity index 99% rename from pytwin/evaluate/twin_model.py rename to src/ansys/pytwin/evaluate/twin_model.py index 4b3060a7..00ddfda7 100644 --- a/pytwin/evaluate/twin_model.py +++ b/src/ansys/pytwin/evaluate/twin_model.py @@ -4,7 +4,6 @@ import numpy as np import pandas as pd - from pytwin.evaluate.model import Model from pytwin.evaluate.saved_state_registry import SavedState, SavedStateRegistry from pytwin.settings import PyTwinLogLevel, get_pytwin_log_level, pytwin_logging_is_enabled diff --git a/src/ansys/pytwin/examples/__init__.py b/src/ansys/pytwin/examples/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/ansys/pytwin/examples/__init__.py @@ -0,0 +1 @@ + diff --git a/pytwin/examples/downloads.py b/src/ansys/pytwin/examples/downloads.py similarity index 100% rename from pytwin/examples/downloads.py rename to src/ansys/pytwin/examples/downloads.py diff --git a/pytwin/settings.py b/src/ansys/pytwin/settings.py similarity index 97% rename from pytwin/settings.py rename to src/ansys/pytwin/settings.py index b5dd6539..520db8d6 100644 --- a/pytwin/settings.py +++ b/src/ansys/pytwin/settings.py @@ -126,7 +126,7 @@ def modify_pytwin_working_dir(new_path: str, erase: bool = True): Raises ------ PyTwinSettingsError - If provided path it None. + If provided path is None. If provided path does not exist AND some parent directories do not exist or last parent directory does not have writing permission. If erase is not a boolean. @@ -321,8 +321,17 @@ def _initialize_wd(): ) else: pytwin_temp_dir = os.path.join(tempfile.gettempdir(), _PyTwinSettings.WORKING_DIRECTORY_NAME) - if os.path.exists(pytwin_temp_dir): - shutil.rmtree(pytwin_temp_dir) + for i in range(5): + # Loop to wait until logging file is freed + try: + if os.path.exists(pytwin_temp_dir): + shutil.rmtree(pytwin_temp_dir) + except PermissionError as e: + import time + + logging.warning(f"_PyTwinSettings failed to clear working dir (attempt #{i})! \n {str(e)}") + time.sleep(1) + os.mkdir(pytwin_temp_dir) _PyTwinSettings.WORKING_DIRECTORY_PATH = pytwin_temp_dir diff --git a/pytwin/twin_runtime/__init__.py b/src/ansys/pytwin/twin_runtime/__init__.py similarity index 100% rename from pytwin/twin_runtime/__init__.py rename to src/ansys/pytwin/twin_runtime/__init__.py diff --git a/pytwin/twin_runtime/ansysli_msgs.xml b/src/ansys/pytwin/twin_runtime/ansysli_msgs.xml similarity index 100% rename from pytwin/twin_runtime/ansysli_msgs.xml rename to src/ansys/pytwin/twin_runtime/ansysli_msgs.xml diff --git a/pytwin/twin_runtime/licensingclient/linx64/ansyscl b/src/ansys/pytwin/twin_runtime/licensingclient/linx64/ansyscl similarity index 100% rename from pytwin/twin_runtime/licensingclient/linx64/ansyscl rename to src/ansys/pytwin/twin_runtime/licensingclient/linx64/ansyscl diff --git a/pytwin/twin_runtime/licensingclient/winx64/ansyscl.exe b/src/ansys/pytwin/twin_runtime/licensingclient/winx64/ansyscl.exe similarity index 100% rename from pytwin/twin_runtime/licensingclient/winx64/ansyscl.exe rename to src/ansys/pytwin/twin_runtime/licensingclient/winx64/ansyscl.exe diff --git a/pytwin/twin_runtime/linux64/__init__.py b/src/ansys/pytwin/twin_runtime/linux64/__init__.py similarity index 100% rename from pytwin/twin_runtime/linux64/__init__.py rename to src/ansys/pytwin/twin_runtime/linux64/__init__.py diff --git a/pytwin/twin_runtime/linux64/libTwinRuntimeSDK.so b/src/ansys/pytwin/twin_runtime/linux64/libTwinRuntimeSDK.so similarity index 100% rename from pytwin/twin_runtime/linux64/libTwinRuntimeSDK.so rename to src/ansys/pytwin/twin_runtime/linux64/libTwinRuntimeSDK.so diff --git a/pytwin/twin_runtime/linux64/libgcc_s.so.1 b/src/ansys/pytwin/twin_runtime/linux64/libgcc_s.so.1 similarity index 100% rename from pytwin/twin_runtime/linux64/libgcc_s.so.1 rename to src/ansys/pytwin/twin_runtime/linux64/libgcc_s.so.1 diff --git a/pytwin/twin_runtime/linux64/libgfortran.so.5 b/src/ansys/pytwin/twin_runtime/linux64/libgfortran.so.5 similarity index 100% rename from pytwin/twin_runtime/linux64/libgfortran.so.5 rename to src/ansys/pytwin/twin_runtime/linux64/libgfortran.so.5 diff --git a/pytwin/twin_runtime/linux64/libm.so.6 b/src/ansys/pytwin/twin_runtime/linux64/libm.so.6 similarity index 100% rename from pytwin/twin_runtime/linux64/libm.so.6 rename to src/ansys/pytwin/twin_runtime/linux64/libm.so.6 diff --git a/pytwin/twin_runtime/linux64/libngcore.so b/src/ansys/pytwin/twin_runtime/linux64/libngcore.so similarity index 100% rename from pytwin/twin_runtime/linux64/libngcore.so rename to src/ansys/pytwin/twin_runtime/linux64/libngcore.so diff --git a/pytwin/twin_runtime/linux64/libstdc++.so.6 b/src/ansys/pytwin/twin_runtime/linux64/libstdc++.so.6 similarity index 100% rename from pytwin/twin_runtime/linux64/libstdc++.so.6 rename to src/ansys/pytwin/twin_runtime/linux64/libstdc++.so.6 diff --git a/pytwin/twin_runtime/log_level.py b/src/ansys/pytwin/twin_runtime/log_level.py similarity index 100% rename from pytwin/twin_runtime/log_level.py rename to src/ansys/pytwin/twin_runtime/log_level.py diff --git a/pytwin/twin_runtime/messages/en_US_Security.dll b/src/ansys/pytwin/twin_runtime/messages/en_US_Security.dll similarity index 100% rename from pytwin/twin_runtime/messages/en_US_Security.dll rename to src/ansys/pytwin/twin_runtime/messages/en_US_Security.dll diff --git a/pytwin/twin_runtime/messages/en_US_translators.dll b/src/ansys/pytwin/twin_runtime/messages/en_US_translators.dll similarity index 100% rename from pytwin/twin_runtime/messages/en_US_translators.dll rename to src/ansys/pytwin/twin_runtime/messages/en_US_translators.dll diff --git a/pytwin/twin_runtime/messages/liben_US_Security.so b/src/ansys/pytwin/twin_runtime/messages/liben_US_Security.so similarity index 100% rename from pytwin/twin_runtime/messages/liben_US_Security.so rename to src/ansys/pytwin/twin_runtime/messages/liben_US_Security.so diff --git a/pytwin/twin_runtime/messages/liben_US_translators.so b/src/ansys/pytwin/twin_runtime/messages/liben_US_translators.so similarity index 100% rename from pytwin/twin_runtime/messages/liben_US_translators.so rename to src/ansys/pytwin/twin_runtime/messages/liben_US_translators.so diff --git a/pytwin/twin_runtime/msgs_security.xml b/src/ansys/pytwin/twin_runtime/msgs_security.xml similarity index 100% rename from pytwin/twin_runtime/msgs_security.xml rename to src/ansys/pytwin/twin_runtime/msgs_security.xml diff --git a/pytwin/twin_runtime/twin_runtime_core.py b/src/ansys/pytwin/twin_runtime/twin_runtime_core.py similarity index 100% rename from pytwin/twin_runtime/twin_runtime_core.py rename to src/ansys/pytwin/twin_runtime/twin_runtime_core.py diff --git a/pytwin/twin_runtime/twin_runtime_error.py b/src/ansys/pytwin/twin_runtime/twin_runtime_error.py similarity index 100% rename from pytwin/twin_runtime/twin_runtime_error.py rename to src/ansys/pytwin/twin_runtime/twin_runtime_error.py diff --git a/pytwin/twin_runtime/win64/TwinRuntimeSDK.dll b/src/ansys/pytwin/twin_runtime/win64/TwinRuntimeSDK.dll similarity index 100% rename from pytwin/twin_runtime/win64/TwinRuntimeSDK.dll rename to src/ansys/pytwin/twin_runtime/win64/TwinRuntimeSDK.dll diff --git a/pytwin/twin_runtime/win64/__init__.py b/src/ansys/pytwin/twin_runtime/win64/__init__.py similarity index 100% rename from pytwin/twin_runtime/win64/__init__.py rename to src/ansys/pytwin/twin_runtime/win64/__init__.py diff --git a/pytwin/twin_runtime/win64/boost_filesystem-vc142-mt-x64-1_71.dll b/src/ansys/pytwin/twin_runtime/win64/boost_filesystem-vc142-mt-x64-1_71.dll similarity index 100% rename from pytwin/twin_runtime/win64/boost_filesystem-vc142-mt-x64-1_71.dll rename to src/ansys/pytwin/twin_runtime/win64/boost_filesystem-vc142-mt-x64-1_71.dll diff --git a/pytwin/twin_runtime/win64/boost_system-vc142-mt-x64-1_71.dll b/src/ansys/pytwin/twin_runtime/win64/boost_system-vc142-mt-x64-1_71.dll similarity index 100% rename from pytwin/twin_runtime/win64/boost_system-vc142-mt-x64-1_71.dll rename to src/ansys/pytwin/twin_runtime/win64/boost_system-vc142-mt-x64-1_71.dll diff --git a/pytwin/twin_runtime/win64/libcrypto-1_1-x64.dll b/src/ansys/pytwin/twin_runtime/win64/libcrypto-1_1-x64.dll similarity index 100% rename from pytwin/twin_runtime/win64/libcrypto-1_1-x64.dll rename to src/ansys/pytwin/twin_runtime/win64/libcrypto-1_1-x64.dll diff --git a/pytwin/twin_runtime/win64/ngcore.dll b/src/ansys/pytwin/twin_runtime/win64/ngcore.dll similarity index 100% rename from pytwin/twin_runtime/win64/ngcore.dll rename to src/ansys/pytwin/twin_runtime/win64/ngcore.dll diff --git a/pytwin/twin_runtime/win64/pthreadVC2.dll b/src/ansys/pytwin/twin_runtime/win64/pthreadVC2.dll similarity index 100% rename from pytwin/twin_runtime/win64/pthreadVC2.dll rename to src/ansys/pytwin/twin_runtime/win64/pthreadVC2.dll diff --git a/tests/evaluate/test_savedstate_registry.py b/tests/evaluate/test_savedstate_registry.py index e4c97317..bcc77bda 100644 --- a/tests/evaluate/test_savedstate_registry.py +++ b/tests/evaluate/test_savedstate_registry.py @@ -1,7 +1,6 @@ import os import pytest - from pytwin import get_pytwin_log_file from pytwin.evaluate.model import Model from pytwin.evaluate.saved_state_registry import ( @@ -10,6 +9,7 @@ SavedStateRegistry, SavedStateRegistryError, ) + from tests.utilities import compare_dictionary UNIT_TEST_WD = os.path.join(os.path.dirname(__file__), "unit_test_wd") diff --git a/tests/evaluate/test_twin_model.py b/tests/evaluate/test_twin_model.py index 179048a9..3ab667e4 100644 --- a/tests/evaluate/test_twin_model.py +++ b/tests/evaluate/test_twin_model.py @@ -4,15 +4,9 @@ import pandas as pd import pytest +from pytwin import TwinModel, TwinModelError, download_file +from pytwin.settings import get_pytwin_log_file, get_pytwin_logger, get_pytwin_working_dir, modify_pytwin_working_dir -from pytwin import TwinModel, TwinModelError, examples -from pytwin.settings import ( - get_pytwin_log_file, - get_pytwin_logger, - get_pytwin_working_dir, - modify_pytwin_working_dir, - reinit_settings_for_unit_tests, -) from tests.utilities import compare_dictionary COUPLE_CLUTCHES_FILEPATH = os.path.join(os.path.dirname(__file__), "data", "CoupleClutches_22R2_other.twin") @@ -39,12 +33,14 @@ def test_instantiation_with_valid_model_filepath(self): TwinModel(model_filepath=model_filepath) def test_instantiation_with_invalid_model_filepath(self): - with pytest.raises(TwinModelError) as e: + try: TwinModel(model_filepath=None) - assert "Please provide valid filepath" in str(e) - with pytest.raises(TwinModelError) as e: + except TwinModelError as e: + assert "Please provide valid filepath" in str(e) + try: TwinModel(model_filepath="") - assert "Please provide existing filepath" in str(e) + except TwinModelError as e: + assert "Please provide existing filepath" in str(e) def test_parameters_property(self): model_filepath = COUPLE_CLUTCHES_FILEPATH @@ -216,41 +212,48 @@ def test_raised_errors_with_step_by_step_evaluation(self): model_filepath = COUPLE_CLUTCHES_FILEPATH twin = TwinModel(model_filepath=model_filepath) # Raise an error if TWIN MODEL HAS NOT BEEN INITIALIZED - with pytest.raises(TwinModelError) as e: + try: twin.evaluate_step_by_step(step_size=0.001) - assert "Please initialize evaluation" in str(e) + except TwinModelError as e: + assert "Please initialize evaluation" in str(e) # Raise an error if STEP SIZE IS ZERO - with pytest.raises(TwinModelError) as e: + try: twin.initialize_evaluation() twin.evaluate_step_by_step(step_size=0.0) - assert "Step size must be strictly bigger than zero" in str(e) - with pytest.raises(TwinModelError) as e: + except TwinModelError as e: + assert "Step size must be strictly bigger than zero" in str(e) + try: twin.initialize_evaluation() twin.evaluate_step_by_step(step_size=-0.1) - assert "Step size must be strictly bigger than zero" in str(e) + except TwinModelError as e: + assert "Step size must be strictly bigger than zero" in str(e) def test_raised_errors_with_batch_evaluation(self): model_filepath = COUPLE_CLUTCHES_FILEPATH twin = TwinModel(model_filepath=model_filepath) # Raise an error if TWIN MODEL HAS NOT BEEN INITIALIZED - with pytest.raises(TwinModelError) as e: + try: twin.evaluate_batch(pd.DataFrame()) - assert "Please initialize evaluation" in str(e) + except TwinModelError as e: + assert "Please initialize evaluation" in str(e) # Raise an error if INPUTS DATAFRAME HAS NO TIME COLUMN - with pytest.raises(TwinModelError) as e: + try: twin.initialize_evaluation() twin.evaluate_batch(pd.DataFrame()) - assert "Please provide a dataframe with a 'Time' column to use batch mode evaluation" in str(e) + except TwinModelError as e: + assert "Please provide a dataframe with a 'Time' column to use batch mode evaluation" in str(e) # Raise an error if INPUTS DATAFRAME HAS NO TIME INSTANT ZERO - with pytest.raises(TwinModelError) as e: + try: twin.initialize_evaluation() twin.evaluate_batch(pd.DataFrame({"Time": [0.1]})) - assert "Please provide inputs at time instant t=0.s" in str(e) + except TwinModelError as e: + assert "Please provide inputs at time instant t=0.s" in str(e) # Raise an error if INPUTS DATAFRAME HAS NO TIME INSTANT ZERO - with pytest.raises(TwinModelError) as e: + try: twin.initialize_evaluation() twin.evaluate_batch(pd.DataFrame({"Time": [1e-50]})) - assert "Please provide inputs at time instant t=0.s" in str(e) + except TwinModelError as e: + assert "Please provide inputs at time instant t=0.s" in str(e) def test_evaluation_methods_give_same_results(self): inputs_df = pd.DataFrame( @@ -352,13 +355,13 @@ def test_close_method(self): def test_each_twin_model_has_a_subfolder_in_wd(self): # Init unit test - reinit_settings_for_unit_tests() + reinit_settings() logger = get_pytwin_logger() # Verify a subfolder is created each time a new twin model is instantiated m_count = 10 for m in range(m_count): model = TwinModel(model_filepath=COUPLE_CLUTCHES_FILEPATH) - time.sleep(0.5) + time.sleep(1) wd = get_pytwin_working_dir() temp = os.listdir(wd) assert len(os.listdir(wd)) == m_count + 2 @@ -604,7 +607,7 @@ def test_raised_errors_with_tbrom_none(self): def test_raised_errors_with_tbrom_bad_name(self): reinit_settings() - model_filepath = examples.download_file("ThermalTBROM_23R1_other.twin", "twin_files") + model_filepath = download_file("ThermalTBROM_23R1_other.twin", "twin_files") twin = TwinModel(model_filepath=model_filepath) twin.initialize_evaluation() # Raise an error if TWIN MODEL DOES NOT INCLUDE ANY TBROM NAMED 'test' @@ -640,7 +643,7 @@ def test_raised_errors_with_tbrom_bad_name(self): def test_raised_errors_with_tbrom_bad_view(self): reinit_settings() - model_filepath = examples.download_file("ThermalTBROM_23R1_other.twin", "twin_files") + model_filepath = download_file("ThermalTBROM_23R1_other.twin", "twin_files") twin = TwinModel(model_filepath=model_filepath) twin.initialize_evaluation() diff --git a/tests/test_settings.py b/tests/test_settings.py index 2b921987..70b416a5 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -3,7 +3,6 @@ import tempfile import pytest - from pytwin import ( PyTwinLogLevel, PyTwinLogOption, diff --git a/tests/twin_runtime/test_twin_runtime_core.py b/tests/twin_runtime/test_twin_runtime_core.py index 5ed98332..ad334905 100644 --- a/tests/twin_runtime/test_twin_runtime_core.py +++ b/tests/twin_runtime/test_twin_runtime_core.py @@ -1,5 +1,4 @@ import pytest - from pytwin import TwinRuntime, TwinRuntimeError import pytwin.examples.downloads as downloads import pytwin.twin_runtime.twin_runtime_error as twin_runtime_error