11"""Contains methods used only when running on ANSYS's jupyterhub cluster"""
2- import warnings
32
43try :
54 from ansys .jupyterhub import manager
65except ImportError :
76 raise ImportError (
87 "Module `ansys-jupyterhub-manager` missing.\n "
9- "This module is required to spawn instances on jupyterhub "
8+ "This library is required to spawn instances on pyansys.com "
109 )
1110
1211
@@ -30,56 +29,62 @@ def check_manager():
3029
3130
3231def launch_mapdl_on_cluster (
33- nproc = 2 ,
34- memory = 4 ,
35- loglevel = "INFO" ,
36- additional_switches = "" ,
37- verbose = True ,
38- start_timeout = 600 ,
39- ** kwargs ,
32+ nproc = 2 ,
33+ memory = 4 ,
34+ loglevel = "ERROR" ,
35+ additional_switches = "" ,
36+ verbose = False ,
37+ start_timeout = 600 ,
38+ tag = "latest" ,
39+ ** kwargs ,
4040):
4141 """Start MAPDL on the ANSYS jupyter cluster in gRPC mode.
4242
4343 Parameters
4444 ----------
4545 nproc : int, optional
4646 Number of processors. Defaults to 2.
47-
4847 memory : float, optional
4948 Fixed amount of memory to request for MAPDL in Gigabytes. If
5049 the mapdl instance requires more ram than your provide MAPDL
5150 may segfault.
52-
5351 loglevel : str, optional
5452 Sets which messages are printed to the console. Default
55- 'INFO' prints out all ANSYS messages, 'WARNING` prints only
56- messages containing ANSYS warnings, and 'ERROR' prints only
53+ `` 'INFO'`` logs out all MAPDL messages, `` 'WARNING`` ` prints only
54+ messages containing MAPDL warnings, and `` 'ERROR'`` prints only
5755 error messages.
58-
5956 additional_switches : str, optional
60- Additional switches for MAPDL, for example aa_r, and academic
61- research license, would be added with:
62-
63- - ``additional_switches="-aa_r"``
57+ Additional switches for MAPDL, for example ``"-p aa_r"``, the
58+ academic research license, would be added with:
6459
65- Avoid adding switches like -i -o or -b as these are already
66- included to start up the MAPDL server. See the notes
67- section for additional details.
60+ - ``additional_switches="-p aa_r"``
6861
62+ Avoid adding switches like ``"-i"`` ``"-o"`` or ``"-b"`` as
63+ these are already included to start up the MAPDL server. See
64+ the notes section for additional details.
6965 start_timeout : float, optional
7066 Maximum allowable time to connect to the MAPDL server.
67+ tag : str, optional
68+ Docker image tag from `PyAnsys MAPDL Image
69+ <https://github.com/orgs/pyansys/packages/container/package/pymapdl%2Fmapdl>`. Defaults
70+ to ``"latest"``. For example "v22.1.0".
7171
7272 Returns
7373 -------
74- port : int
75- Returns the port number that the gRPC instance started on .
74+ MapdlGrpc
75+ MAPDL instance.
7676
7777 Examples
7878 --------
7979 Launch MAPDL using the default configuration.
8080
8181 >>> from ansys.mapdl import launch_mapdl
8282 >>> mapdl = launch_mapdl()
83+
84+ Launch MAPDL and guarantee 16 GB minimum RAM and 8 CPUs.
85+
86+ >>> mapdl = launch_mapdl(memory=16, nproc=8)
87+
8388 """
8489 # attempt to connect to the remote scheduler
8590 check_manager ()
@@ -88,53 +93,38 @@ def launch_mapdl_on_cluster(
8893 if "-m " in additional_switches :
8994 raise ValueError (
9095 'Memory option "-m" not permitted when launching from the '
91- "kubernetes cluster and is set with the `memory` parameter"
96+ "kubernetes cluster and is set with the `` memory` ` parameter"
9297 )
9398 if "-np " in additional_switches :
9499 raise ValueError (
95100 'CPU option "-np" not permitted when launching from the '
96- "kubernetes cluster and is set with the `nproc` parameter"
101+ "kubernetes cluster and is set with the `` nproc` ` parameter"
97102 )
98103
99104 # check resources
100105 nproc = int (nproc )
101106 if nproc < 0 :
102- raise ValueError ("Requested CPUs `nproc` must be greater than 0" )
107+ raise ValueError ("Requested CPUs `` nproc` ` must be greater than 0" )
103108 if nproc > MAX_CPU :
104- raise ValueError (f"Requested CPUs `nproc` must be less than { MAX_CPU } " )
109+ raise ValueError (f"Requested CPUs `` nproc` ` must be less than { MAX_CPU } " )
105110
106111 if memory < 0.25 :
107- raise ValueError ("Requested memory `mem` must be greater than 0.25" )
112+ raise ValueError ("Requested memory `` mem` ` must be greater than 0.25" )
108113 if memory > MAX_MEM :
109- raise ValueError (f"Requested memory `mem` must be less than than { MAX_MEM } " )
114+ raise ValueError (f"Requested memory `` mem` ` must be less than than { MAX_MEM } " )
110115
111- # convert memory from GB to Mi
116+ # # convert memory from GB to Mi
112117 memory *= 1024
118+
113119 if "-smp" in additional_switches :
114- warnings . warn (
115- 'Ignoring additional switch "-smp". Incompatible with docker ' "container."
120+ raise ValueError (
121+ 'The additional switch "-smp" is incompatible with docker containers.'
116122 )
117- additional_switches = additional_switches .replace ("-smp" , "" )
118- additional_switches += f"-m -{ memory } -np { nproc } "
119123
120- # need a way of making the image user-selectable
121- image = "mapdlhelm.azurecr.io/mapdl:v22.0.0"
122- command = (
123- 'printf "" | /ansys_inc/v202/ansys/bin/mapdl %s -smp -grpc -custom /ansys_inc/v202/grpc/ansys.e201t.DEBUG-0.53.1'
124- % additional_switches
125- )
126- env = {
"ANSYSLMD_LICENSE_FILE" :
"[email protected] " }
127- ip , pod_name = manager .spawn_pod (
128- image ,
129- env = env ,
130- cpu = 1000 * nproc ,
131- memory = memory ,
132- command = command ,
133- start_timeout = start_timeout ,
134- verbose = verbose ,
135- )
124+ additional_switches += f"-m -{ memory } -np { nproc } "
125+ args = additional_switches .split ()
126+ ip , name = manager .spawn_mapdl (version = tag , args = args , verbose = verbose )
136127
137128 # connect to the pod instance
138- from ansys .mapdl import Mapdl # import here to avoid recursive
139-
129+ from ansys .mapdl .core import Mapdl
140130 return Mapdl (ip , loglevel = loglevel )
0 commit comments