Skip to content

Commit af402a0

Browse files
hpohekarpyansys-ci-bot
authored andcommitted
feat: Make graphics driver null except in gui / hidden_gui modes (#4149)
closes #4143 Make graphics driver null except in gui / hidden_gui modes. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 3651523 commit af402a0

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

doc/changelog.d/4149.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make graphics driver null except in gui / hidden_gui modes

src/ansys/fluent/core/launcher/launch_options.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424

2525
from enum import Enum
2626
import os
27+
import warnings
2728

2829
from ansys.fluent.core.exceptions import DisallowedValuesError
2930
from ansys.fluent.core.fluent_connection import FluentConnection
3031
import ansys.fluent.core.launcher.error_handler as exceptions
3132
from ansys.fluent.core.launcher.launcher_utils import is_windows
33+
from ansys.fluent.core.pyfluent_warnings import PyFluentUserWarning
3234
from ansys.fluent.core.session_meshing import Meshing
3335
from ansys.fluent.core.session_pure_meshing import PureMeshing
3436
from ansys.fluent.core.session_solver import Solver
@@ -280,11 +282,17 @@ def _get_fluent_launch_mode(start_container, container_dict, scheduler_options):
280282
return fluent_launch_mode
281283

282284

285+
def _should_add_driver_null(ui_mode: UIMode | None = None) -> bool:
286+
return ui_mode not in {UIMode.GUI, UIMode.HIDDEN_GUI}
287+
288+
283289
def _get_graphics_driver(
284290
graphics_driver: (
285291
FluentWindowsGraphicsDriver | FluentLinuxGraphicsDriver | str | None
286292
) = None,
293+
ui_mode: UIMode | None = None,
287294
):
295+
ui_mode_ = UIMode(ui_mode)
288296
if isinstance(
289297
graphics_driver, (FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver)
290298
):
@@ -294,6 +302,20 @@ def _get_graphics_driver(
294302
if is_windows()
295303
else FluentLinuxGraphicsDriver(graphics_driver)
296304
)
305+
if graphics_driver.value != "null" and ui_mode_ not in {
306+
UIMode.GUI,
307+
UIMode.HIDDEN_GUI,
308+
}:
309+
warnings.warn(
310+
"User-specified value for graphics driver is ignored while launching Fluent without GUI or without graphics.",
311+
PyFluentUserWarning,
312+
)
313+
if _should_add_driver_null(ui_mode_):
314+
return (
315+
FluentWindowsGraphicsDriver.NULL
316+
if is_windows()
317+
else FluentLinuxGraphicsDriver.NULL
318+
)
297319
return graphics_driver
298320

299321

@@ -361,7 +383,9 @@ def _validate_gpu(gpu: bool | list, dimension: int):
361383

362384
def _get_argvals_and_session(argvals):
363385
_validate_gpu(argvals["gpu"], argvals["dimension"])
364-
argvals["graphics_driver"] = _get_graphics_driver(argvals["graphics_driver"])
386+
argvals["graphics_driver"] = _get_graphics_driver(
387+
argvals["graphics_driver"], argvals["ui_mode"]
388+
)
365389
argvals["mode"] = FluentMode(argvals["mode"])
366390
del argvals["self"]
367391
new_session = argvals["mode"].get_fluent_value()

tests/test_launcher.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import pytest
3030

3131
import ansys.fluent.core as pyfluent
32-
from ansys.fluent.core import PyFluentDeprecationWarning
32+
from ansys.fluent.core import PyFluentDeprecationWarning, PyFluentUserWarning
3333
from ansys.fluent.core.examples.downloads import download_file
3434
from ansys.fluent.core.exceptions import DisallowedValuesError, InvalidArgument
3535
from ansys.fluent.core.launcher import launcher_utils
@@ -45,6 +45,7 @@
4545
FluentWindowsGraphicsDriver,
4646
LaunchMode,
4747
UIMode,
48+
_get_graphics_driver,
4849
)
4950
from ansys.fluent.core.launcher.launcher import create_launcher
5051
from ansys.fluent.core.launcher.launcher_utils import (
@@ -516,7 +517,7 @@ def test_standalone_launcher_dry_run(monkeypatch):
516517
assert str(Path(server_info_file_name).parent) == tempfile.gettempdir()
517518
assert (
518519
fluent_launch_string
519-
== f"{fluent_path} 3ddp -gu -sifile={server_info_file_name} -nm"
520+
== f"{fluent_path} 3ddp -gu -driver null -sifile={server_info_file_name} -nm"
520521
)
521522

522523

@@ -531,7 +532,7 @@ def test_standalone_launcher_dry_run_with_server_info_dir(monkeypatch):
531532
assert str(Path(server_info_file_name).parent) == tmp_dir
532533
assert (
533534
fluent_launch_string
534-
== f"{fluent_path} 3ddp -gu -sifile={Path(server_info_file_name).name} -nm"
535+
== f"{fluent_path} 3ddp -gu -driver null -sifile={Path(server_info_file_name).name} -nm"
535536
)
536537

537538

@@ -583,3 +584,71 @@ def test_docker_compose(monkeypatch):
583584
)
584585
solver.file.read_case(file_name=case_file_name)
585586
solver.exit()
587+
588+
589+
@pytest.mark.standalone
590+
def test_respect_driver_is_not_null_in_windows():
591+
driver = _get_graphics_driver(
592+
graphics_driver=FluentWindowsGraphicsDriver.DX11, ui_mode=UIMode.GUI
593+
)
594+
assert driver == FluentWindowsGraphicsDriver.DX11
595+
596+
driver = _get_graphics_driver(
597+
graphics_driver=FluentWindowsGraphicsDriver.OPENGL, ui_mode=UIMode.HIDDEN_GUI
598+
)
599+
assert driver == FluentWindowsGraphicsDriver.OPENGL
600+
601+
602+
def test_respect_driver_is_not_null_in_linux():
603+
driver = _get_graphics_driver(
604+
graphics_driver=FluentLinuxGraphicsDriver.X11, ui_mode=UIMode.GUI
605+
)
606+
assert driver == FluentLinuxGraphicsDriver.X11
607+
608+
driver = _get_graphics_driver(
609+
graphics_driver=FluentLinuxGraphicsDriver.OPENGL, ui_mode=UIMode.HIDDEN_GUI
610+
)
611+
assert driver == FluentLinuxGraphicsDriver.OPENGL
612+
613+
614+
@pytest.mark.standalone
615+
def test_warning_in_windows():
616+
with pytest.warns(PyFluentUserWarning):
617+
driver = _get_graphics_driver(
618+
graphics_driver=FluentWindowsGraphicsDriver.DX11, ui_mode=UIMode.NO_GUI
619+
)
620+
assert driver == FluentWindowsGraphicsDriver.NULL
621+
622+
with pytest.warns(PyFluentUserWarning):
623+
driver = _get_graphics_driver(
624+
graphics_driver=FluentWindowsGraphicsDriver.AUTO, ui_mode=UIMode.NO_GRAPHICS
625+
)
626+
assert driver == FluentWindowsGraphicsDriver.NULL
627+
628+
with pytest.warns(PyFluentUserWarning):
629+
driver = _get_graphics_driver(
630+
graphics_driver=FluentWindowsGraphicsDriver.AUTO,
631+
ui_mode=UIMode.NO_GUI_OR_GRAPHICS,
632+
)
633+
assert driver == FluentWindowsGraphicsDriver.NULL
634+
635+
636+
def test_warning_in_linux():
637+
with pytest.warns(PyFluentUserWarning):
638+
driver = _get_graphics_driver(
639+
graphics_driver=FluentLinuxGraphicsDriver.X11, ui_mode=UIMode.NO_GUI
640+
)
641+
assert driver == FluentLinuxGraphicsDriver.NULL
642+
643+
with pytest.warns(PyFluentUserWarning):
644+
driver = _get_graphics_driver(
645+
graphics_driver=FluentLinuxGraphicsDriver.AUTO, ui_mode=UIMode.NO_GRAPHICS
646+
)
647+
assert driver == FluentLinuxGraphicsDriver.NULL
648+
649+
with pytest.warns(PyFluentUserWarning):
650+
driver = _get_graphics_driver(
651+
graphics_driver=FluentLinuxGraphicsDriver.AUTO,
652+
ui_mode=UIMode.NO_GUI_OR_GRAPHICS,
653+
)
654+
assert driver == FluentLinuxGraphicsDriver.NULL

0 commit comments

Comments
 (0)