Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: gRPC remote FTS refactoring #2743

Closed
wants to merge 10 commits into from
8 changes: 5 additions & 3 deletions src/ansys/fluent/core/launcher/container_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ class DockerLauncher:

def __init__(
self,
mode: FluentMode,
ui_mode: UIMode,
graphics_driver: Union[FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver],
mode: Optional[Union[FluentMode, str, None]] = None,
ui_mode: Union[UIMode, str, None] = None,
graphics_driver: Union[
FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver, str, None
] = None,
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
product_version: Optional[FluentVersion] = None,
version: Optional[str] = None,
precision: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/launcher/fluent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def configure_container_dict(
logger.debug(f"container_dict before processing: {container_dict}")

if not host_mount_path:
host_mount_path = pyfluent.EXAMPLES_PATH
host_mount_path = pyfluent.USER_DATA_PATH
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
elif "volumes" in container_dict:
logger.warning(
"'volumes' keyword specified in 'container_dict', but "
Expand Down
8 changes: 5 additions & 3 deletions src/ansys/fluent/core/launcher/pim_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class PIMLauncher:

def __init__(
self,
mode: FluentMode,
ui_mode: UIMode,
graphics_driver: Union[FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver],
mode: Optional[Union[FluentMode, str, None]] = None,
ui_mode: Union[UIMode, str, None] = None,
graphics_driver: Union[
FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver, str, None
] = None,
product_version: Optional[FluentVersion] = None,
version: Optional[str] = None,
precision: Optional[str] = None,
Expand Down
8 changes: 5 additions & 3 deletions src/ansys/fluent/core/launcher/standalone_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class StandaloneLauncher:

def __init__(
self,
mode: FluentMode,
ui_mode: UIMode,
graphics_driver: Union[FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver],
mode: Optional[Union[FluentMode, str, None]] = None,
ui_mode: Union[UIMode, str, None] = None,
graphics_driver: Union[
FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver, str, None
] = None,
product_version: Optional[FluentVersion] = None,
version: Optional[str] = None,
precision: Optional[str] = None,
Expand Down
63 changes: 33 additions & 30 deletions src/ansys/fluent/core/utils/file_transfer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,11 @@ def download(

def _get_files(
file_name: Union[str, pathlib.PurePath, list[Union[str, pathlib.PurePath]]],
path: str,
):
if isinstance(file_name, (str, pathlib.PurePath)):
file_name = pathlib.Path(file_name)
file_path_check = os.path.join(path, file_name.name)
files = [file_path_check] if os.path.isfile(file_path_check) else [file_name]
logger.debug(f"\n pyfluent.EXAMPLES_PATH = {pyfluent.EXAMPLES_PATH} \n")
logger.debug(f"\n host_mount_path = {path} \n")
logger.debug(f"\n file_name = {file_name} \n")
logger.debug(f"\n file_name.name = {file_name.name} \n")
logger.debug(f"\n file_path_check = {file_path_check} \n")
logger.debug(f"\n is_file_path_check = {os.path.isfile(file_path_check)} \n")
logger.debug(f"\n files = {files} \n")
elif isinstance(file_name, list):
files = []
for file in file_name:
file_path_check = os.path.join(path, os.path.basename(file))
logger.debug(f"\n file_path_check = {file_path_check} \n")
logger.debug(
f"\n is_file_path_check = {os.path.isfile(file_path_check)} \n"
)
if os.path.isfile(file_path_check):
files.append(file_path_check)
else:
files.append(file)
logger.debug(f"\n files = {files} \n")
files = [pathlib.Path(file_name)]
if isinstance(file_name, list):
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
files = [pathlib.Path(file) for file in file_name]
return files


Expand Down Expand Up @@ -176,8 +155,10 @@ def __init__(
container_mount_path if container_mount_path else "/home/container/workdir/"
)
self.host_mount_path = (
host_mount_path if host_mount_path else pyfluent.EXAMPLES_PATH
host_mount_path if host_mount_path else pyfluent.USER_DATA_PATH
)
if not pathlib.Path(self.host_mount_path).exists():
pathlib.Path(self.host_mount_path).mkdir(parents=True, exist_ok=True)
try:
self.host_port = port if port else random.randint(5000, 6000)
self.ports = {"50000/tcp": self.host_port}
Expand Down Expand Up @@ -213,7 +194,7 @@ def file_exists_on_remote(self, file_name: str) -> bool:
full_file_name = pathlib.Path(self.host_mount_path) / os.path.basename(
file_name
)
return full_file_name.is_file()
return full_file_name, full_file_name.is_file()

def upload(
self, file_name: Union[list[str], str], remote_file_name: Optional[str] = None
Expand All @@ -232,15 +213,37 @@ def upload(
FileNotFoundError
If a file does not exist.
"""
files = _get_files(file_name, self.host_mount_path)
files = _get_files(file_name)
if self.client:
for file in files:
is_file_on_remote = self.file_exists_on_remote(os.path.basename(file))
if is_file_on_remote:
full_file_name, is_file_on_remote = self.file_exists_on_remote(
os.path.basename(file)
)
if is_file_on_remote and full_file_name.samefile(file):
warnings.warn(
f"\n{file} with the same name exists at the remote location.\n",
UserWarning,
)
return
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
elif (
is_file_on_remote
and os.path.isfile(file)
and not full_file_name.samefile(file)
):
warnings.warn(
f"\n{file} with the same name and different content exists at the remote location. "
f"It's replaced with the given file.\n",
UserWarning,
)
full_file_name.unlink()
self.client.upload_file(
local_filename=file,
remote_filename=(
remote_file_name
if remote_file_name
else os.path.basename(file)
),
)
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
elif os.path.isfile(file) and not is_file_on_remote:
self.client.upload_file(
local_filename=file,
Expand All @@ -265,7 +268,7 @@ def download(
local_directory : str, optional
Local directory. The default is ``None``.
"""
files = _get_files(file_name, self.host_mount_path)
files = _get_files(file_name)
if self.client:
for file in files:
if os.path.isfile(file):
Expand Down
5 changes: 4 additions & 1 deletion tests/parametric/test_parametric_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def test_parametric_workflow():
Path(pyfluent.EXAMPLES_PATH).mkdir(parents=True, exist_ok=True)
tmp_save_path = tempfile.mkdtemp(dir=pyfluent.EXAMPLES_PATH)
import_file_name = examples.download_file(
"Static_Mixer_main.cas.h5", "pyfluent/static_mixer", save_path=tmp_save_path
"Static_Mixer_main.cas.h5",
"pyfluent/static_mixer",
save_path=tmp_save_path,
return_without_path=False,
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
)
if os.getenv("PYFLUENT_LAUNCH_CONTAINER") == "1":
inside_container = True
Expand Down
8 changes: 6 additions & 2 deletions tests/test_batch_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def test_batch_ops_create_mesh(new_solver_session):
solver = new_solver_session
mesh = solver.results.graphics.mesh
case_file_name = examples.download_file(
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
"mixing_elbow.cas.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)
with pyfluent.BatchOps(solver):
solver.file.read(
Expand All @@ -28,7 +30,9 @@ def test_batch_ops_create_mesh_and_access_fails(new_solver_session):
solver = new_solver_session
mesh = solver.results.graphics.mesh
case_file_name = examples.download_file(
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
"mixing_elbow.cas.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)
with pytest.raises(KeyError):
with pyfluent.BatchOps(solver):
Expand Down
20 changes: 15 additions & 5 deletions tests/test_datamodel_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def test_add_on_affected(new_mesh_session):
calls = []
subscription2 = meshing.workflow.add_on_affected(lambda obj: calls.append(True))
geom = examples.download_file(
file_name="mixing_elbow.pmdb", directory="pyfluent/mixing_elbow"
file_name="mixing_elbow.pmdb",
directory="pyfluent/mixing_elbow",
return_without_path=False,
)
import_geom = meshing.workflow.TaskObject["Import Geometry"]
assert "FileName" not in import_geom.Arguments()
Expand Down Expand Up @@ -241,7 +243,9 @@ def test_add_on_command_executed(new_mesh_session):
assert data == []
meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry")
import_file_name = examples.download_file(
"mixing_elbow.pmdb", "pyfluent/mixing_elbow"
"mixing_elbow.pmdb",
"pyfluent/mixing_elbow",
return_without_path=False,
)
meshing.meshing.ImportGeometry(FileName=import_file_name)
sleep(5)
Expand Down Expand Up @@ -278,7 +282,9 @@ def cb(state, deleted_paths):

meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry")
import_file_name = examples.download_file(
"mixing_elbow.pmdb", "pyfluent/mixing_elbow"
"mixing_elbow.pmdb",
"pyfluent/mixing_elbow",
return_without_path=False,
)
meshing.meshing.ImportGeometry(FileName=import_file_name)
sleep(5)
Expand Down Expand Up @@ -306,7 +312,9 @@ def cb(state, deleted_paths):

meshing.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry")
import_file_name = examples.download_file(
"mixing_elbow.pmdb", "pyfluent/mixing_elbow"
"mixing_elbow.pmdb",
"pyfluent/mixing_elbow",
return_without_path=False,
)
meshing.meshing.ImportGeometry(FileName=import_file_name)
sleep(5)
Expand Down Expand Up @@ -390,7 +398,9 @@ def test_generic_datamodel(new_solver_session):
@pytest.mark.fluent_version(">=24.2")
def test_named_object_specific_methods_using_flserver(new_solver_session):
import_file_name = examples.download_file(
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
"mixing_elbow.cas.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)
solver = new_solver_session
solver.file.read(file_type="case", file_name=import_file_name)
Expand Down
20 changes: 15 additions & 5 deletions tests/test_field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
def test_field_data(new_solver_session) -> None:
solver = new_solver_session
import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)
solver.file.read(file_type="case", file_name=import_file_name)
solver.tui.mesh.check()
Expand Down Expand Up @@ -115,7 +117,9 @@ def test_field_data(new_solver_session) -> None:
def test_field_data_allowed_values(new_solver_session) -> None:
solver = new_solver_session
import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)

field_data = solver.fields.field_data
Expand Down Expand Up @@ -171,7 +175,9 @@ def test_field_data_allowed_values(new_solver_session) -> None:
def test_field_data_objects_3d(new_solver_session) -> None:
solver = new_solver_session
import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)

field_data = solver.fields.field_data
Expand Down Expand Up @@ -299,7 +305,9 @@ def test_field_data_objects_2d(load_disk_mesh) -> None:
def test_field_data_errors(new_solver_session) -> None:
solver = new_solver_session
import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)

with pytest.raises(DisallowedValuesError) as fne:
Expand Down Expand Up @@ -348,7 +356,9 @@ def test_field_data_errors(new_solver_session) -> None:
def test_field_info_validators(new_solver_session) -> None:
solver = new_solver_session
import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)
solver.file.read(file_type="case", file_name=import_file_name)
solver.solution.initialization.hybrid_initialize()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_file_transfer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"mixing_elbow.cas.h5", "pyfluent/mixing_elbow"
)
import_mesh_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)


Expand Down
24 changes: 19 additions & 5 deletions tests/test_fluent_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def test_allowed_values_on_report_definitions_1364(new_solver_session):
solver = new_solver_session

import_file_name = examples.download_file(
"elbow.cas.h5", "pyfluent/examples/DOE-ML-Mixing-Elbow"
"elbow.cas.h5",
"pyfluent/examples/DOE-ML-Mixing-Elbow",
return_without_path=False,
)

solver.file.read(
Expand Down Expand Up @@ -40,11 +42,15 @@ def test_monitors_list_set_data_637_974_1744_2188(new_solver_session):
solver_session = new_solver_session

import_case = examples.download_file(
file_name="exhaust_system.cas.h5", directory="pyfluent/exhaust_system"
file_name="exhaust_system.cas.h5",
directory="pyfluent/exhaust_system",
return_without_path=False,
)

import_data = examples.download_file(
file_name="exhaust_system.dat.h5", directory="pyfluent/exhaust_system"
file_name="exhaust_system.dat.h5",
directory="pyfluent/exhaust_system",
return_without_path=False,
)

solver_session.tui.file.read_case(import_case)
Expand Down Expand Up @@ -92,9 +98,17 @@ def test_monitors_list_set_data_637_974_1744_2188(new_solver_session):
def test_empty_vector_field_data_2339(new_solver_session):
solver = new_solver_session

import_case = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow")
import_case = examples.download_file(
"mixing_elbow.cas.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)

import_data = examples.download_file("mixing_elbow.dat.h5", "pyfluent/mixing_elbow")
import_data = examples.download_file(
"mixing_elbow.dat.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)

assert import_case
assert import_data
Expand Down
4 changes: 3 additions & 1 deletion tests/test_launcher_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import ansys.platform.instancemanagement as pypim

import_file_name = examples.download_file(
"mixing_elbow.msh.h5", "pyfluent/mixing_elbow"
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)


Expand Down
6 changes: 5 additions & 1 deletion tests/test_meshing_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from ansys.fluent.core import examples

import_filename = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow")
import_filename = examples.download_file(
"mixing_elbow.msh.h5",
"pyfluent/mixing_elbow",
return_without_path=False,
)

PYTEST_RELATIVE_TOLERANCE = 0.2

Expand Down