PyMAPDL exits intermittently when run in a loop

Samukham Member Posts: 35
First Anniversary First Comment Name Dropper
edited September 2023 in General Language Questions

I'm currently running a PyMAPDL script in a for loop. During each iteration, the script makes slight modifications to the mesh and performs a pre-stressed modal analysis. However, I'm encountering an intermittent issue where PyMAPDL exits with the following error message after few iterations:

CRITICAL - pymapdl_global - logging - handle_exception - Uncaught exception
Traceback (most recent call last):
File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\", line 33, in
result = obj.perform_modelSensitivity(niter=None)
File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\", line 73, in perform_modelSensitivity
disp_pert[iter,:] = self.perturb_surf_nds(seed=0)
File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\", line 168, in perturb_surf_nds
surf_ndInd_to_modfy = self._extract_surf_node_ind_modfy(surf_grid)
File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\", line 146, in _extract_surf_node_ind_modfy
File "d:\bitBucket\fcdslib_modalSensitivity\ModalSensitivity\", line 143, in input_file
File "D:\PythonVenvs\sensitivityAnalysis\sensitivityAnalysis\lib\site-packages\ansys\mapdl\core\", line 168, in
raise MapdlExitedError("MAPDL server connection terminated") from None
ansys.mapdl.core.errors.MapdlExitedError: MAPDL server connection terminated

To investigate this issue, I attempted to run the same script in a loop without any modifications, effectively solving the same model repeatedly. However, I'm still encountering the same error after a few iterations. I'm unsure why this is happening and would appreciate any suggestions on how to prevent it.

P.S: I may need to run the PyMAPDL in a loop of appx. 8000 - 10000 iterations

Here is the part of the code that I'd need to run in the loop:

for iter in range(7000):
self.resume_job(self._filename) # resumes a .db file
self.set_jobname('Test') # sets the job name
self.mapdl.input('apdl_pert_node.inp') # input file that contains commands to modify the node locations
self.solve_prestress() # solve pre-stress
freq_pert[iter,:] = self.solve_modal() # solve modal solution


  • JoshGrose
    JoshGrose Member Posts: 1
    First Comment
    edited October 2023

    I'm having the same issue using PyMAPDL when running multiple simulations in parallel with "pool = LocalMapdlPool(...)" within my PyMAPDL script. A random number of simulations will fail with the "MAPDL server connection terminated" error. Each of my simulations contains a python "for" loop that executes commands for each simulation loadstep. This is a transient thermal application.

    Sometimes all simulations will run successfully. Sometimes many will disconnect. This also happens at random loadsteps.

    Any suggestions would be greatly appreciated!

  • M
    M Member, Employee Posts: 230
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited October 2023

    pymapdl will require a license for each launch, so some of these issues might be license related. Make sure you exit every time you finish a solve (mapdl.exit()) The same for pool, that is limited by licenses and available cpu cores. Not quite sure how exactly to test.

  • Samukham
    Samukham Member Posts: 35
    First Anniversary First Comment Name Dropper

    Hello @M, exiting Mapdl for every iteration is not a good idea. In my case, I need to iterate at least 10,000 times. So each time exiting Mapdl and relaunching consumes a lot of time and is not possible. I figured out that in my case at least the termination of the loop is caused by the mapdl.input() command which I use inside the loop. Then I found a workaround and removed the mapdl.input command. Now, it's working fine and iterating through without any interruption. So, there must be some instability with the input() command. I request you to look into it.