6060from ansys .aedt .core .generic .numbers import decompose_variable_value
6161from ansys .aedt .core .generic .numbers import is_number
6262from ansys .aedt .core .generic .settings import settings
63+ from ansys .aedt .core .internal .errors import AEDTRuntimeError
6364from ansys .aedt .core .modules .boundary .layout_boundary import NativeComponentObject
6465from ansys .aedt .core .modules .boundary .layout_boundary import NativeComponentPCB
6566from ansys .aedt .core .modules .design_xploration import OptimizationSetups
@@ -1903,6 +1904,7 @@ def stop_simulations(self, clean_stop=True):
19031904 """
19041905 return self .desktop_class .stop_simulations (clean_stop = clean_stop )
19051906
1907+ # flake8: noqa: E501
19061908 @pyaedt_function_handler (filename = "file_name" , numcores = "cores" , num_tasks = "tasks" , setup_name = "setup" )
19071909 def solve_in_batch (
19081910 self ,
@@ -1919,6 +1921,11 @@ def solve_in_batch(
19191921 .. note::
19201922 To use this function, the project must be closed.
19211923
1924+ .. warning::
1925+ Do not execute this function with untrusted input parameters.
1926+ See the :ref:`security guide<https://aedt.docs.pyansys.com/version/stable/User_guide/security_consideration.html>`
1927+ for details.
1928+
19221929 Parameters
19231930 ----------
19241931 file_name : str, optional
@@ -1945,6 +1952,15 @@ def solve_in_batch(
19451952 bool
19461953 ``True`` when successful, ``False`` when failed.
19471954 """
1955+ try :
1956+ cores = int (cores )
1957+ except ValueError :
1958+ raise ValueError (f"The number of cores is not a valid integer." )
1959+ try :
1960+ tasks = int (tasks )
1961+ except ValueError :
1962+ raise ValueError (f"The number of tasks is not a valid integer." )
1963+
19481964 inst_dir = self .desktop_install_dir
19491965 self .last_run_log = ""
19501966 self .last_run_job = ""
@@ -1979,46 +1995,37 @@ def solve_in_batch(
19791995 if setup and design_name :
19801996 options .append (f'{ design_name } :{ "Nominal" if setup in self .setup_names else "Optimetrics" } :{ setup } ' )
19811997 if is_linux and not settings .use_lsf_scheduler :
1982- batch_run = [inst_dir + "/ansysedt" ]
1998+ command = [inst_dir + "/ansysedt" ]
19831999 elif is_linux and settings .use_lsf_scheduler : # pragma: no cover
2000+ if not isinstance (settings .lsf_ram , int ) or settings .lsf_ram <= 0 :
2001+ raise AEDTRuntimeError ("Invalid memory value." )
2002+ if not settings .lsf_aedt_command :
2003+ raise AEDTRuntimeError ("Invalid LSF AEDT command." )
2004+ command = [
2005+ "bsub" ,
2006+ "-n" ,
2007+ str (cores ),
2008+ "-R" ,
2009+ f"span[ptile={ cores } ]" ,
2010+ "-R" ,
2011+ f"rusage[mem={ settings .lsf_ram } ]" ,
2012+ settings .lsf_aedt_command ,
2013+ ]
19842014 if settings .lsf_queue :
1985- batch_run = [
1986- "bsub" ,
1987- "-n" ,
1988- str (cores ),
1989- "-R" ,
1990- f"span[ptile={ cores } ]" ,
1991- "-R" ,
1992- f"rusage[mem={ settings .lsf_ram } ]" ,
1993- f"-queue { settings .lsf_queue } " ,
1994- settings .lsf_aedt_command ,
1995- ]
1996- else :
1997- batch_run = [
1998- "bsub" ,
1999- "-n" ,
2000- str (cores ),
2001- "-R" ,
2002- f"span[ptile={ cores } ]" ,
2003- "-R" ,
2004- f"rusage[mem={ settings .lsf_ram } ]" ,
2005- settings .lsf_aedt_command ,
2006- ]
2015+ command .extend (["-queue" , settings .lsf_queue ])
20072016 else :
2008- batch_run = [inst_dir + "/ansysedt.exe" ]
2009- batch_run .extend (options )
2010- batch_run .append (file_name )
2017+ command = [inst_dir + "/ansysedt.exe" ]
2018+ command .extend (options )
2019+ command .append (file_name )
20112020
20122021 # check for existing solution directory and delete it if it exists so we
20132022 # don't have old .asol files etc
2014-
20152023 self .logger .info ("Solving model in batch mode on " + machine )
20162024 if run_in_thread and is_windows :
2017- DETACHED_PROCESS = 0x00000008
2018- subprocess .Popen (batch_run , creationflags = DETACHED_PROCESS )
2025+ subprocess .Popen (command , creationflags = subprocess .DETACHED_PROCESS ) # nosec
20192026 self .logger .info ("Batch job launched." )
20202027 else :
2021- subprocess .Popen (batch_run )
2028+ subprocess .Popen (command ) # nosec
20222029 self .logger .info ("Batch job finished." )
20232030
20242031 if machine == "localhost" :
0 commit comments