Skip to content

Commit

Permalink
MAINT: Switch layout to src/ansys/pytwin (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Boucinha <lboucin@ansys.com>
Co-authored-by: chrpetre <108675940+chrpetre@users.noreply.github.com>
Co-authored-by: Maxime Rey <87315832+MaxJPRey@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 20, 2022
1 parent 82da611 commit cdfe9df
Show file tree
Hide file tree
Showing 51 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 3 additions & 3 deletions doc/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,4 +39,4 @@ change them from their default values

sdk/index
evaluate/index
logging/index
logging/index
3 changes: 1 addition & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion doc/source/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -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.

Expand All @@ -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 <https://www.ansys.com/products/digital-twin/ansys-twin-builder>`_.
For more information, see `Ansys Twin Builder and Twin Deployer <https://www.ansys.com/products/digital-twin/ansys-twin-builder>`_
on the Ansys website.

Project index
Expand Down
25 changes: 9 additions & 16 deletions examples/evaluate/00-coupledClutches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


###############################################################################
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions examples/evaluate/01-electricRange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions examples/evaluate/02-heatExchangerRS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions examples/evaluate/03-scalarDROM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


###############################################################################
Expand Down Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions examples/evaluate/04-TBROM_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
7 changes: 3 additions & 4 deletions examples/evaluate/05-TBROM_coSimulation_pyMAPDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ authors = ["ANSYS, Inc. <ansys.support@ansys.com>"]
maintainers = ["PyAnsys developers <pyansys.maintainers@ansys.com>"]
readme = "README.rst"
repository = "https://github.com/pyansys/pytwin"
documentation = "https://twin.docs.pyansys.com/"
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
packages = [
{ include = "pytwin" },
{ include = "pytwin", from = "src/ansys" },
]

[tool.poetry.dependencies]
Expand Down Expand Up @@ -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"]
Expand Down
1 change: 0 additions & 1 deletion pytwin/examples/__init__.py

This file was deleted.

13 changes: 9 additions & 4 deletions pytwin/__init__.py → src/ansys/pytwin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
PUBLIC API TO PYTWIN SETTINGS
"""
from .settings import (
from pytwin.settings import (
PyTwinLogLevel,
PyTwinLogOption,
PyTwinSettingsError,
Expand All @@ -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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import uuid

import numpy as np

from pytwin import get_pytwin_logger
from pytwin.evaluate.model import Model

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ansys/pytwin/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

File renamed without changes.
15 changes: 12 additions & 3 deletions pytwin/settings.py → src/ansys/pytwin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/evaluate/test_savedstate_registry.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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")
Expand Down
Loading

0 comments on commit cdfe9df

Please sign in to comment.