Skip to content

feat: Make graphics driver null except in gui / hidden_gui modes #4149

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

Merged
merged 20 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/4149.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make graphics driver null except in gui / hidden_gui modes
26 changes: 25 additions & 1 deletion src/ansys/fluent/core/launcher/launch_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

from enum import Enum
import os
import warnings

from ansys.fluent.core.exceptions import DisallowedValuesError
from ansys.fluent.core.fluent_connection import FluentConnection
import ansys.fluent.core.launcher.error_handler as exceptions
from ansys.fluent.core.launcher.launcher_utils import is_windows
from ansys.fluent.core.pyfluent_warnings import PyFluentUserWarning
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
Expand Down Expand Up @@ -280,11 +282,17 @@ def _get_fluent_launch_mode(start_container, container_dict, scheduler_options):
return fluent_launch_mode


def _should_add_driver_null(ui_mode: UIMode | None = None) -> bool:
return ui_mode not in {UIMode.GUI, UIMode.HIDDEN_GUI}


def _get_graphics_driver(
graphics_driver: (
FluentWindowsGraphicsDriver | FluentLinuxGraphicsDriver | str | None
) = None,
ui_mode: UIMode | None = None,
):
ui_mode_ = UIMode(ui_mode)
if isinstance(
graphics_driver, (FluentWindowsGraphicsDriver, FluentLinuxGraphicsDriver)
):
Expand All @@ -294,6 +302,20 @@ def _get_graphics_driver(
if is_windows()
else FluentLinuxGraphicsDriver(graphics_driver)
)
if graphics_driver.value != "null" and ui_mode_ not in {
UIMode.GUI,
UIMode.HIDDEN_GUI,
}:
warnings.warn(
"User-specified value for graphics driver is ignored while launching Fluent without GUI or without graphics.",
PyFluentUserWarning,
)
if _should_add_driver_null(ui_mode_):
return (
FluentWindowsGraphicsDriver.NULL
if is_windows()
else FluentLinuxGraphicsDriver.NULL
)
return graphics_driver


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

def _get_argvals_and_session(argvals):
_validate_gpu(argvals["gpu"], argvals["dimension"])
argvals["graphics_driver"] = _get_graphics_driver(argvals["graphics_driver"])
argvals["graphics_driver"] = _get_graphics_driver(
argvals["graphics_driver"], argvals["ui_mode"]
)
argvals["mode"] = FluentMode(argvals["mode"])
del argvals["self"]
new_session = argvals["mode"].get_fluent_value()
Expand Down
75 changes: 72 additions & 3 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import pytest

import ansys.fluent.core as pyfluent
from ansys.fluent.core import PyFluentDeprecationWarning
from ansys.fluent.core import PyFluentDeprecationWarning, PyFluentUserWarning
from ansys.fluent.core.examples.downloads import download_file
from ansys.fluent.core.exceptions import DisallowedValuesError, InvalidArgument
from ansys.fluent.core.launcher import launcher_utils
Expand All @@ -45,6 +45,7 @@
FluentWindowsGraphicsDriver,
LaunchMode,
UIMode,
_get_graphics_driver,
)
from ansys.fluent.core.launcher.launcher import create_launcher
from ansys.fluent.core.launcher.launcher_utils import (
Expand Down Expand Up @@ -516,7 +517,7 @@ def test_standalone_launcher_dry_run(monkeypatch):
assert str(Path(server_info_file_name).parent) == tempfile.gettempdir()
assert (
fluent_launch_string
== f"{fluent_path} 3ddp -gu -sifile={server_info_file_name} -nm"
== f"{fluent_path} 3ddp -gu -driver null -sifile={server_info_file_name} -nm"
)


Expand All @@ -531,7 +532,7 @@ def test_standalone_launcher_dry_run_with_server_info_dir(monkeypatch):
assert str(Path(server_info_file_name).parent) == tmp_dir
assert (
fluent_launch_string
== f"{fluent_path} 3ddp -gu -sifile={Path(server_info_file_name).name} -nm"
== f"{fluent_path} 3ddp -gu -driver null -sifile={Path(server_info_file_name).name} -nm"
)


Expand Down Expand Up @@ -583,3 +584,71 @@ def test_docker_compose(monkeypatch):
)
solver.file.read_case(file_name=case_file_name)
solver.exit()


@pytest.mark.standalone
def test_respect_driver_is_not_null_in_windows():
driver = _get_graphics_driver(
graphics_driver=FluentWindowsGraphicsDriver.DX11, ui_mode=UIMode.GUI
)
assert driver == FluentWindowsGraphicsDriver.DX11

driver = _get_graphics_driver(
graphics_driver=FluentWindowsGraphicsDriver.OPENGL, ui_mode=UIMode.HIDDEN_GUI
)
assert driver == FluentWindowsGraphicsDriver.OPENGL


def test_respect_driver_is_not_null_in_linux():
driver = _get_graphics_driver(
graphics_driver=FluentLinuxGraphicsDriver.X11, ui_mode=UIMode.GUI
)
assert driver == FluentLinuxGraphicsDriver.X11

driver = _get_graphics_driver(
graphics_driver=FluentLinuxGraphicsDriver.OPENGL, ui_mode=UIMode.HIDDEN_GUI
)
assert driver == FluentLinuxGraphicsDriver.OPENGL


@pytest.mark.standalone
def test_warning_in_windows():
with pytest.warns(PyFluentUserWarning):
driver = _get_graphics_driver(
graphics_driver=FluentWindowsGraphicsDriver.DX11, ui_mode=UIMode.NO_GUI
)
assert driver == FluentWindowsGraphicsDriver.NULL

with pytest.warns(PyFluentUserWarning):
driver = _get_graphics_driver(
graphics_driver=FluentWindowsGraphicsDriver.AUTO, ui_mode=UIMode.NO_GRAPHICS
)
assert driver == FluentWindowsGraphicsDriver.NULL

with pytest.warns(PyFluentUserWarning):
driver = _get_graphics_driver(
graphics_driver=FluentWindowsGraphicsDriver.AUTO,
ui_mode=UIMode.NO_GUI_OR_GRAPHICS,
)
assert driver == FluentWindowsGraphicsDriver.NULL


def test_warning_in_linux():
with pytest.warns(PyFluentUserWarning):
driver = _get_graphics_driver(
graphics_driver=FluentLinuxGraphicsDriver.X11, ui_mode=UIMode.NO_GUI
)
assert driver == FluentLinuxGraphicsDriver.NULL

with pytest.warns(PyFluentUserWarning):
driver = _get_graphics_driver(
graphics_driver=FluentLinuxGraphicsDriver.AUTO, ui_mode=UIMode.NO_GRAPHICS
)
assert driver == FluentLinuxGraphicsDriver.NULL

with pytest.warns(PyFluentUserWarning):
driver = _get_graphics_driver(
graphics_driver=FluentLinuxGraphicsDriver.AUTO,
ui_mode=UIMode.NO_GUI_OR_GRAPHICS,
)
assert driver == FluentLinuxGraphicsDriver.NULL