slurm_launcher#
Provides a module for launching Fluent within a Slurm environment.
Examples#
Note that the keys scheduler_headnode
, scheduler_queue
and scheduler_account
are optional and should be specified in a similar manner to Fluent’s scheduler options.
>>> slurm = pyfluent.launch_fluent(
... scheduler_options={
... "scheduler": "slurm",
... "scheduler_headnode": "<headnode>",
... "scheduler_queue": "<queue>",
... "scheduler_account": "<account>"
... },
... additional_arguments="-t16 -cnf=m1:8,m2:8",
... )
>>> type(slurm)
<class 'ansys.fluent.core.launcher.slurm_launcher.SlurmFuture'>
>>> slurm.pending(), slurm.running(), slurm.done() # before Fluent is launched
(True, False, False)
>>> slurm.pending(), slurm.running(), slurm.done() # after Fluent is launched
(False, True, False)
>>> session = slurm.result()
>>> type(session)
<class 'ansys.fluent.core.session_solver.Solver'>
>>> session.exit()
>>> slurm.pending(), slurm.running(), slurm.done()
(False, False, True)
# Callable slurm launcher
>>> from ansys.fluent.core.launcher.launcher import create_launcher
>>> from ansys.fluent.core.launcher.pyfluent_enums import LaunchMode, FluentMode
>>> slurm_meshing_launcher = create_launcher(LaunchMode.SLURM, mode=FluentMode.MESHING)
>>> slurm_meshing_session = slurm_meshing_launcher()
>>> slurm_solver_launcher = create_launcher(LaunchMode.SLURM)
>>> slurm_solver_session = slurm_solver_launcher()
Classes:
|
Encapsulates asynchronous launch of Fluent within a Slurm environment. |
|
Instantiates Fluent session within a Slurm environment. |
- class ansys.fluent.core.launcher.slurm_launcher.SlurmFuture(future, job_id)#
Bases:
object
Encapsulates asynchronous launch of Fluent within a Slurm environment.
The interface is similar to Python’s future object.
Methods:
__init__
(future, job_id)Attaches the callable function.
cancel
([timeout])Attempt to cancel the Fluent launch within timeout seconds.
done
()Return
True
if the Fluent launch was successfully cancelled or Fluent was finished running, otherwiseFalse
.exception
([timeout])Return the exception raised by the Fluent launch.
pending
()Return
True
if the Fluent launch is currently waiting for Slurm allocation or Fluent is being launched, otherwiseFalse
.result
([timeout])Return the session instance corresponding to the Fluent launch.
running
()Return
True
if Fluent is currently running, otherwiseFalse
.- __init__(future, job_id)#
- add_done_callback(fn)#
Attaches the callable function. The function will be called, with the session as its only argument, when Fluent is launched.
- Parameters:
- fn
Callable
Callback function.
- fn
- cancel(timeout=60)#
Attempt to cancel the Fluent launch within timeout seconds.
- done()#
Return
True
if the Fluent launch was successfully cancelled or Fluent was finished running, otherwiseFalse
.
- exception(timeout=None)#
Return the exception raised by the Fluent launch. If Fluent hasn’t yet launched, then this method will wait up to timeout seconds. If Fluent hasn’t launched in timeout seconds, then a TimeoutError will be raised. If timeout is not specified or None, there is no limit to the wait time.
If the Fluent launch completed without raising, None is returned.
- pending()#
Return
True
if the Fluent launch is currently waiting for Slurm allocation or Fluent is being launched, otherwiseFalse
.
- result(timeout=None)#
Return the session instance corresponding to the Fluent launch. If Fluent hasn’t yet launched, then this method will wait up to timeout seconds. If Fluent hasn’t launched in timeout seconds, then a TimeoutError will be raised. If timeout is not specified or None, there is no limit to the wait time.
If the Fluent launch raised an exception, this method will raise the same exception.
- Parameters:
- timeout
int
,optional
timeout in seconds
- timeout
- Returns:
Union
[Meshing
,PureMeshing
,Solver
,SolverIcing
]The session instance corresponding to the Fluent launch.
- running()#
Return
True
if Fluent is currently running, otherwiseFalse
.
- class ansys.fluent.core.launcher.slurm_launcher.SlurmLauncher(mode=None, ui_mode=None, graphics_driver=None, product_version=None, dimension=None, precision=None, processor_count=None, journal_file_names=None, start_timeout=-1, additional_arguments='', env=None, cleanup_on_exit=True, start_transcript=True, case_file_name=None, case_data_file_name=None, lightweight_mode=None, py=None, gpu=None, cwd=None, fluent_path=None, topy=None, start_watchdog=None, scheduler_options=None, file_transfer_service=None)#
Bases:
object
Instantiates Fluent session within a Slurm environment.
Methods:
__init__
([mode, ui_mode, graphics_driver, ...])Launch Fluent session in standalone mode.
- __init__(mode=None, ui_mode=None, graphics_driver=None, product_version=None, dimension=None, precision=None, processor_count=None, journal_file_names=None, start_timeout=-1, additional_arguments='', env=None, cleanup_on_exit=True, start_transcript=True, case_file_name=None, case_data_file_name=None, lightweight_mode=None, py=None, gpu=None, cwd=None, fluent_path=None, topy=None, start_watchdog=None, scheduler_options=None, file_transfer_service=None)#
Launch Fluent session in standalone mode.
- Parameters:
- mode
FluentMode
Launch mode of Fluent to point to a specific session type.
- ui_mode
UIMode
Fluent user interface mode. Options are the values of the
UIMode
enum.- graphics_driver
FluentWindowsGraphicsDriver
orFluentLinuxGraphicsDriver
Graphics driver of Fluent. Options are the values of the
FluentWindowsGraphicsDriver
enum in Windows or the values of theFluentLinuxGraphicsDriver
enum in Linux.- product_version
FluentVersion
orstr
orfloat
orint
,optional
Version of Ansys Fluent to launch. To use Fluent version 2024 R2, pass
FluentVersion.v242
,"24.2.0"
,"24.2"
,24.2
, or242
. The default isNone
, in which case the newest installed version is used.- dimension
Dimension
orint
,optional
Geometric dimensionality of the Fluent simulation. The default is
None
, in which caseDimension.THREE
is used. Options are either the values of theDimension
enum (Dimension.TWO
orDimension.THREE
) or any of2
and3
.- precision
Precision
orstr
,optional
Floating point precision. The default is
None
, in which casePrecision.DOUBLE
is used. Options are either the values of thePrecision
enum (Precision.SINGLE
orPrecision.DOUBLE
) or any of"double"
and"single"
.- processor_count
int
,optional
Number of processors. The default is
None
, in which case1
processor is used. In job scheduler environments the total number of allocated cores is clamped to value ofprocessor_count
.- journal_file_names
str
orlist
of
str
,optional
The string path to a Fluent journal file or a list of such paths. Fluent executes the journals. The default is
None
.- start_timeout
int
,optional
Maximum allowable time in seconds for connecting to the Fluent server. The default is
60
.- additional_arguments
str
,optional
Additional arguments to send to Fluent as a string in the same format they are normally passed to Fluent on the command line.
- env
dict
[str
,str
],optional
Mapping to modify environment variables in Fluent. The default is
None
.- cleanup_on_exitbool,
optional
Whether to shut down the connected Fluent session when PyFluent is exited, or the
exit()
method is called on the session instance, or if the session instance becomes unreferenced. The default isTrue
.- start_transcriptbool,
optional
Whether to start streaming the Fluent transcript in the client. The default is
True
. You can stop and start the streaming of the Fluent transcript subsequently via the method calls,transcript.start()
andtranscript.stop()
on the session object.- case_file_name
str
,optional
Name of the case file to read into the Fluent session. The default is
None
.- case_data_file_name
str
,optional
Name of the case data file. If names of both a case file and case data file are provided, they are read into the Fluent session.
- lightweight_modebool,
optional
Whether to run in lightweight mode. In lightweight mode, the lightweight settings are read into the current Fluent solver session. The mesh is read into a background Fluent solver session, which replaces the current Fluent solver session once the mesh is read and the lightweight settings made by the user in the current Fluent solver session have been applied in the background Fluent solver session. This is all orchestrated by PyFluent and requires no special usage. This parameter is used only when
case_file_name
is provided. The default isFalse
.- pybool,
optional
If True, Fluent will run in Python mode. Default is None.
- gpubool,
optional
If True, Fluent will start with GPU Solver.
- cwd
str
,Optional
Working directory for the Fluent client.
- fluent_path: str, Optional
User provided Fluent installation path.
- topybool or
str
,optional
A boolean flag to write the equivalent Python journal(s) from the journal(s) passed. Can optionally take the file name of the new python journal file.
- start_watchdogbool,
optional
When
cleanup_on_exit
is True,start_watchdog
defaults to True, which means an independent watchdog process is run to ensure that any local GUI-less Fluent sessions started by PyFluent are properly closed (or killed if frozen) when the current Python process ends.- scheduler_options
dict
,optional
Dictionary containing scheduler options. Default is None.
Currently only the Slurm scheduler is supported. The
scheduler_options
dictionary must be of the form{"scheduler": "slurm", "scheduler_headnode": "<headnode>", "scheduler_queue": "<queue>", "scheduler_account": "<account>"}
. The keysscheduler_headnode
,scheduler_queue
andscheduler_account
are optional and should be specified in a similar manner to Fluent’s scheduler options.- file_transfer_service
optional
File transfer service for uploading and downloading files to and from the server.
- mode
- Returns:
Union
[Meshing
,PureMeshing
,Solver
,SolverIcing
,dict
]Session object or configuration dictionary if
dry_run = True
.
Notes
Job scheduler environments such as SLURM, LSF, and PBS, allocate resources and compute nodes. The allocated machines and core counts are queried from the scheduler environment and passed to Fluent.