From 94d8462b86e65b97cf94d8df75ddce7d15402ea6 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Fri, 16 Dec 2022 14:05:30 +0530 Subject: [PATCH] Retire root object latest (#1190) * Retire root object latest * Updated test marker * Removed Session * Retire root object latest * Updated test marker * Removed Session * Removed Session from import statement * Removed unnecessary brackets * Updated import statement Co-authored-by: Prithwish Mukherjee <109645853+prmukherj@users.noreply.github.com> --- Makefile | 2 +- src/ansys/fluent/core/launcher/launcher.py | 35 ++-- src/ansys/fluent/core/session.py | 199 +-------------------- tests/util/solver_workflow.py | 2 +- 4 files changed, 20 insertions(+), 218 deletions(-) diff --git a/Makefile b/Makefile index ccfdd5cb81a..dc6fc61d73f 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ unittest-all-222: @sudo rm -rf /home/ansys/.local/share/ansys_fluent_core/examples/* @echo "Running all unittests" @pip install -r requirements/requirements_tests.txt - @python -m pytest -v -m "not fluent_231" --cov=ansys.fluent --cov-report html:cov_html --cov-config=.coveragerc --durations=0 + @python -m pytest -v -m "not fluent_231 and not fluent_232" --cov=ansys.fluent --cov-report html:cov_html --cov-config=.coveragerc --durations=0 unittest-all-231: @sudo rm -rf /home/ansys/.local/share/ansys_fluent_core/examples/* diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index f033d85c035..1360901e2c6 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -17,7 +17,7 @@ from ansys.fluent.core.fluent_connection import _FluentConnection from ansys.fluent.core.launcher.fluent_container import start_fluent_container from ansys.fluent.core.scheduler import build_parallel_options, load_machines -from ansys.fluent.core.session import Session, _BaseSession, parse_server_info_file +from ansys.fluent.core.session import _BaseSession, parse_server_info_file from ansys.fluent.core.session_meshing import Meshing from ansys.fluent.core.session_pure_meshing import PureMeshing from ansys.fluent.core.session_solver import Solver @@ -229,7 +229,7 @@ def launch_remote_fluent( Parameters ---------- - session_cls: [_BaseSession, Session] + session_cls: _BaseSession Instance of the Session class start_transcript: bool Whether to start streaming the Fluent transcript in the client. The @@ -281,22 +281,18 @@ def launch_remote_fluent( def _get_session_info( - argvals, mode: Union[LaunchModes, str, None] = None, meshing_mode: bool = None + argvals, mode: Union[LaunchModes, str, None] = None ): """Updates the session information.""" if mode is None: - new_session = Session - elif mode and meshing_mode: - raise RuntimeError( - "Please select either of the 2 ways of running ('mode' or 'meshing_mode')" - ) - else: - if type(mode) == str: - mode = LaunchModes.get_mode(mode) - new_session = mode.value[1] - meshing_mode = mode.value[2] - for k, v in mode.value[3]: - argvals[k] = v + mode = LaunchModes.SOLVER + + if type(mode) == str: + mode = LaunchModes.get_mode(mode) + new_session = mode.value[1] + meshing_mode = mode.value[2] + for k, v in mode.value[3]: + argvals[k] = v return new_session, meshing_mode, argvals, mode @@ -438,14 +434,14 @@ def launch_fluent( start_transcript: bool = True, show_gui: bool = None, case_filepath: str = None, - meshing_mode: bool = None, mode: Union[LaunchModes, str, None] = None, server_info_filepath: str = None, password: str = None, py: bool = None, cwd: str = None, topy: Union[str, list] = None, -) -> Union[_BaseSession, Session]: +) -> _BaseSession: + """Launch Fluent locally in server mode or connect to a running Fluent server instance. @@ -512,9 +508,6 @@ def launch_fluent( case_filepath : str, optional If provided, reads a fluent case file and sets the required settings in the fluent session - meshing_mode : bool, optional - Whether to launch Fluent in meshing mode. The default is ``None``, - in which case Fluent is launched in meshing mode. mode : str, optional Launch mode of Fluent to point to a specific session type. The default value is ``None``. Options are ``"meshing"``, @@ -546,7 +539,7 @@ def launch_fluent( argvals = locals() new_session, meshing_mode, argvals, mode = _get_session_info( - argvals, mode, meshing_mode + argvals, mode ) _raise_exception_g_gu_in_windows_os(additional_arguments) if _start_instance(start_instance): diff --git a/src/ansys/fluent/core/session.py b/src/ansys/fluent/core/session.py index 91c5dd97a4e..a9eeab94d0c 100644 --- a/src/ansys/fluent/core/session.py +++ b/src/ansys/fluent/core/session.py @@ -4,16 +4,12 @@ import json import os from typing import Any -import warnings - -import grpc from ansys.fluent.core.fluent_connection import _FluentConnection -from ansys.fluent.core.services.datamodel_tui import TUIMenu -from ansys.fluent.core.session_base_meshing import _BaseMeshing -from ansys.fluent.core.session_shared import _CODEGEN_MSG_DATAMODEL, _CODEGEN_MSG_TUI -from ansys.fluent.core.solver.flobject import get_root as settings_get_root -from ansys.fluent.core.utils.fluent_version import get_version_for_filepath +from ansys.fluent.core.session_shared import ( # noqa: F401 + _CODEGEN_MSG_DATAMODEL, + _CODEGEN_MSG_TUI, +) from ansys.fluent.core.utils.logging import LOG try: @@ -155,193 +151,6 @@ def download(self, file_name: str, local_file_path: str = None): return self._uploader.download(file_name, local_file_path) -class Session: - """Instantiates a Fluent connection. This is a deprecated class. This has - been replaced by the "_BaseSession" class to implement the new fluent - launch modes. - - Attributes - ---------- - scheme_eval: SchemeEval - Instance of SchemeEval on which Fluent's scheme code can be - executed. - - Methods - ------- - create_from_server_info_file( - server_info_filepath, cleanup_on_exit, start_transcript - ) - Create a Session instance from server-info file - """ - - def __init__( - self, - ip: str = None, - port: int = None, - password: str = None, - channel: grpc.Channel = None, - cleanup_on_exit: bool = True, - start_transcript: bool = True, - remote_instance=None, - fluent_connection=None, - ): - warnings.warn("Please use the new fluent launch modes", DeprecationWarning) - if not fluent_connection: - self.fluent_connection = _FluentConnection( - ip=ip, - port=port, - password=password, - channel=channel, - cleanup_on_exit=cleanup_on_exit, - start_transcript=start_transcript, - remote_instance=remote_instance, - ) - else: - self.fluent_connection = fluent_connection - - self.scheme_eval = self.fluent_connection.scheme_eval - - self.meshing = _BaseMeshing(None, self.fluent_connection) - - self._datamodel_service_se = self.fluent_connection.datamodel_service_se - self._datamodel_service_tui = self.fluent_connection.datamodel_service_tui - self._settings_service = self.fluent_connection.settings_service - - self.solver = Session.Solver(self.fluent_connection) - - self._uploader = None - self._preferences = None - self._solverworkflow = None - - @classmethod - def create_from_server_info_file( - cls, - server_info_filepath: str, - cleanup_on_exit: bool = True, - start_transcript: bool = True, - ) -> "Session": - """Create a Session instance from server-info file. - - Parameters - ---------- - server_info_filepath : str - Path to server-info file written out by Fluent server - cleanup_on_exit : bool, optional - When True, the connected Fluent session will be shut down - when PyFluent is exited or exit() is called on the session - instance, by default True. - start_transcript : bool, optional - The Fluent transcript is started in the client only when - start_transcript is True. It can be started and stopped - subsequently via method calls on the Session object. - Defaults to true. - - Returns - ------- - Session - Session instance - """ - ip, port, password = parse_server_info_file(server_info_filepath) - session = Session( - fluent_connection=_FluentConnection( - ip=ip, - port=port, - password=password, - cleanup_on_exit=cleanup_on_exit, - start_transcript=start_transcript, - ) - ) - return session - - def __enter__(self): - """Close the Fluent connection and exit Fluent.""" - return self - - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any): - self.fluent_connection.exit() - - def __getattr__(self, attr): - return getattr(self.fluent_connection, attr) - - def __dir__(self): - return sorted( - set( - list(self.__dict__.keys()) - + dir(type(self)) - + dir(self.fluent_connection) - ) - ) - - def upload(self, file_path: str, remote_file_name: str = None): - """Uploads a file on the server.""" - if not self._uploader: - self._uploader = _Uploader(self.fluent_connection._remote_instance) - return self._uploader.upload(file_path, remote_file_name) - - def download(self, file_name: str, local_file_path: str = None): - """Downloads a file from the server.""" - if not self._uploader: - self._uploader = _Uploader(self.fluent_connection._remote_instance) - return self._uploader.download(file_name, local_file_path) - - @property - def preferences(self): - """preferences datamodel root.""" - if self._preferences is None: - self._preferences = _get_preferences(self) - return self._preferences - - @property - def solverworkflow(self): - """solverworkflow datamodel root.""" - if self._solverworkflow is None: - self._solverworkflow = _get_solverworkflow(self) - return self._solverworkflow - - class Solver: - def __init__(self, fluent_connection: _FluentConnection): - self._fluent_connection = fluent_connection - self._tui_service = fluent_connection.datamodel_service_tui - self._settings_service = fluent_connection.settings_service - self._tui = None - self._settings_root = None - self._version = None - - def get_fluent_version(self): - """Gets and returns the fluent version.""" - return self._fluent_connection.get_fluent_version() - - @property - def version(self): - if self._version is None: - self._version = get_version_for_filepath(session=self) - return self._version - - @property - def tui(self): - """Instance of ``main_menu`` on which Fluent's SolverTUI methods - can be executed.""" - if self._tui is None: - try: - tui_module = importlib.import_module( - f"ansys.fluent.core.solver.tui_{self.version}" - ) - self._tui = tui_module.main_menu([], self._tui_service) - except (ImportError, ModuleNotFoundError): - LOG.warning(_CODEGEN_MSG_TUI) - self._tui = TUIMenu([], self._tui_service) - return self._tui - - @property - def root(self): - """root settings object.""" - if self._settings_root is None: - self._settings_root = settings_get_root( - flproxy=self._settings_service, version=self.version - ) - return self._settings_root - - class _Uploader: """Instantiates a file uploader and downloader to have a seamless file reading / writing in the cloud particularly in Ansys lab . Here we are diff --git a/tests/util/solver_workflow.py b/tests/util/solver_workflow.py index bf0bf2902e2..54063227eb8 100644 --- a/tests/util/solver_workflow.py +++ b/tests/util/solver_workflow.py @@ -9,7 +9,7 @@ def create_solver_session(*args, **kwargs): @pytest.fixture def new_solver_session(with_launching_container): - solver = create_solver_session(mode="solver") + solver = create_solver_session() yield solver solver.exit()