Skip to content

Commit

Permalink
refactor: More FluentConnection refactoring. (#2636)
Browse files Browse the repository at this point in the history
* refactor: More FluentConnection refactoring.

* Fix watchdog.
  • Loading branch information
prmukherj authored Mar 31, 2024
1 parent 32016f2 commit 0a34962
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/ansys/fluent/core/fluent_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import socket
import subprocess
import threading
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from typing import Callable, List, Optional, Tuple, Union
import warnings
import weakref

Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(
channel: Optional[grpc.Channel] = None,
cleanup_on_exit: bool = True,
remote_instance: Optional[Instance] = None,
launcher_args: Optional[Dict[str, Any]] = None,
slurm_job_id: Optional[str] = None,
inside_container: Optional[bool] = None,
):
"""Initialize a Session.
Expand Down Expand Up @@ -299,7 +299,7 @@ def __init__(
# throws, we should not proceed.
self.health_check_service.check_health()

self._slurm_job_id = launcher_args and launcher_args.get("slurm_job_id")
self._slurm_job_id = slurm_job_id

self._id = f"session-{next(FluentConnection._id_iter)}"

Expand Down Expand Up @@ -365,7 +365,6 @@ def __init__(
)

self._remote_instance = remote_instance
self.launcher_args = launcher_args

self._exit_event = threading.Event()

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/launcher/container_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def __call__(self):
port=port,
password=password,
cleanup_on_exit=self.cleanup_on_exit,
launcher_args=self.argvals,
slurm_job_id=self.argvals and self.argvals.get("slurm_job_id"),
inside_container=True,
),
file_transfer_service=self.file_transfer_service,
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/launcher/pim_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def launch_remote_fluent(
channel=channel,
cleanup_on_exit=cleanup_on_exit,
remote_instance=instance,
launcher_args=launcher_args,
slurm_job_id=launcher_args and launcher_args.get("slurm_job_id"),
)

file_transfer_service = (
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/launcher/watchdog_exec
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if __name__ == "__main__":
"ip": ip,
"port": int(port),
"password": password,
"launcher_args": None,
"slurm_job_id": None,
"cleanup_on_exit": True,
}

Expand Down
6 changes: 5 additions & 1 deletion src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import importlib
import json
import logging
from typing import Any, Optional, Union
from typing import Any, Dict, Optional, Union
import warnings

from ansys.fluent.core.fluent_connection import FluentConnection
Expand Down Expand Up @@ -94,6 +94,7 @@ def __init__(
fluent_connection: FluentConnection,
file_transfer_service: Optional[Any] = None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
):
"""BaseSession.
Expand All @@ -109,6 +110,7 @@ def __init__(
subsequently via method calls on the Session object.
"""
self._start_transcript = start_transcript
self._launcher_args = launcher_args
BaseSession.build_from_fluent_connection(
self, fluent_connection, file_transfer_service
)
Expand Down Expand Up @@ -270,6 +272,7 @@ def _create_from_server_info_file(
server_info_file_name: str,
file_transfer_service: Optional[Any] = None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
**connection_kwargs,
):
"""Create a Session instance from server-info file.
Expand Down Expand Up @@ -302,6 +305,7 @@ def _create_from_server_info_file(
),
file_transfer_service=file_transfer_service,
start_transcript=start_transcript,
launcher_args=launcher_args,
)
return session

Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/session_meshing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module containing class encapsulating Fluent connection."""

from typing import Any, Optional
from typing import Any, Dict, Optional

from ansys.fluent.core.fluent_connection import FluentConnection
from ansys.fluent.core.session_pure_meshing import PureMeshing
Expand All @@ -22,6 +22,7 @@ def __init__(
fluent_connection: FluentConnection,
file_transfer_service: Optional[Any] = None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
):
"""Meshing session.
Expand All @@ -33,6 +34,7 @@ def __init__(
fluent_connection=fluent_connection,
file_transfer_service=file_transfer_service,
start_transcript=start_transcript,
launcher_args=launcher_args,
)
self.switch_to_solver = lambda: self._switch_to_solver()
self.switched = False
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/session_pure_meshing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module containing class encapsulating Fluent connection."""

import functools
from typing import Any, Optional
from typing import Any, Dict, Optional

import ansys.fluent.core as pyfluent
from ansys.fluent.core.data_model_cache import DataModelCache, NameKey
Expand Down Expand Up @@ -32,6 +32,7 @@ def __init__(
fluent_connection: FluentConnection,
file_transfer_service: Optional[Any] = None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
):
"""PureMeshing session.
Expand All @@ -43,6 +44,7 @@ def __init__(
fluent_connection=fluent_connection,
file_transfer_service=file_transfer_service,
start_transcript=start_transcript,
launcher_args=launcher_args,
)
self._base_meshing = BaseMeshing(
self.execute_tui,
Expand Down
6 changes: 4 additions & 2 deletions src/ansys/fluent/core/session_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import importlib
import logging
import threading
from typing import Any, Optional
from typing import Any, Dict, Optional
import warnings

from ansys.fluent.core.services import service_creator
Expand Down Expand Up @@ -78,6 +78,7 @@ def __init__(
fluent_connection,
file_transfer_service: Optional[Any] = None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
):
"""Solver session.
Expand All @@ -89,6 +90,7 @@ def __init__(
fluent_connection=fluent_connection,
file_transfer_service=file_transfer_service,
start_transcript=start_transcript,
launcher_args=launcher_args,
)
self._build_from_fluent_connection(fluent_connection)

Expand Down Expand Up @@ -252,7 +254,7 @@ def read_case_lightweight(self, file_name: str):
import ansys.fluent.core as pyfluent

self.file.read(file_type="case", file_name=file_name, lightweight_setup=True)
launcher_args = dict(self._fluent_connection.launcher_args)
launcher_args = dict(self._launcher_args)
launcher_args.pop("lightweight_mode", None)
launcher_args["case_file_name"] = file_name
fut: Future = asynchronous(pyfluent.launch_fluent)(**launcher_args)
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/fluent/core/session_solver_icing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import importlib
from typing import Any, Optional
from typing import Any, Dict, Optional

from ansys.fluent.core.fluent_connection import FluentConnection
from ansys.fluent.core.session_solver import Solver
Expand All @@ -22,6 +22,7 @@ def __init__(
fluent_connection: FluentConnection,
file_transfer_service: Optional[Any] = None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
):
"""SolverIcing session.
Expand All @@ -33,6 +34,7 @@ def __init__(
fluent_connection=fluent_connection,
file_transfer_service=file_transfer_service,
start_transcript=start_transcript,
launcher_args=launcher_args,
)
self._flserver_root = None
self._fluent_version = None
Expand Down
4 changes: 4 additions & 0 deletions src/ansys/fluent/core/session_solver_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
**********PRESENTLY SAME AS SOLVER WITH A SWITCH TO SOLVER***********
"""

from typing import Any, Dict, Optional

from ansys.fluent.core.session_solver import Solver


Expand All @@ -15,6 +17,7 @@ def __init__(
self,
fluent_connection=None,
start_transcript: bool = True,
launcher_args: Optional[Dict[str, Any]] = None,
):
"""SolverLite session.
Expand All @@ -24,6 +27,7 @@ def __init__(
super().__init__(
fluent_connection=fluent_connection,
start_transcript=start_transcript,
launcher_args=launcher_args,
)
self._tui_service = self.datamodel_service_tui
self._settings_service = self.settings_service
Expand Down

0 comments on commit 0a34962

Please sign in to comment.