ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
421 stars 119 forks source link

PyMAPDL connect to existing instance instead of creating a new one #1113

Closed germa89 closed 6 months ago

germa89 commented 2 years ago

=== From internal feedback DK ===

If you have a PyMAPDL session running:

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(run_location="C:\temp\temp1")

and run another session:

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(run_location="C:\temp\temp2")

the later will connect into the former, which is not desirable.

germa89 commented 2 years ago

I need to have a look at this and see the implications. I'm creating this issue to raise visibility.

NFougeron commented 1 year ago

Hi, I think I have this issue. It seems that when I start an analysis in one instance of APDL and want to work on a second analysis in the meantime both crash and I have some error message saying that I can't use some functions (from the second analysis) in the /SOLU menu (the one where is running the first analysis).

Do you have any idea on how to bypass this issue?

Thanks

germa89 commented 1 year ago

Hi @NFougeron

Can you try specifying the ports for each instance??

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(port=50052, run_location="C:\temp\temp1")
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(port=50053, run_location="C:\temp\temp2")
NFougeron commented 1 year ago

Thanks it seems to work !

Nolwenn Fougeron, Docteur en Biomécanique Chercheur en post-doctorat au laboratoire TIMC - Équipe Biomeca-TIMC

Univ. Grenoble Alpes - CNRS UMR 5525 - Pavillon Taillefer

Faculté de Médecine - 38706 La Tronche cedex - France


De : German @.> Envoyé : vendredi 18 novembre 2022 11:24 À : pyansys/pymapdl @.> Cc : NFougeron @.>; Mention @.> Objet : Re: [pyansys/pymapdl] PyMAPDL connect to existing instance instead of creating a new one (Issue #1113)

Hi @NFougeronhttps://github.com/NFougeron

Can you try specifying the ports for each instance??

from ansys.mapdl.core import launch_mapdl mapdl = launch_mapdl(port=50052, run_location="C:\temp\temp1")

from ansys.mapdl.core import launch_mapdl mapdl = launch_mapdl(port=50053, run_location="C:\temp\temp2")

— Reply to this email directly, view it on GitHubhttps://github.com/pyansys/pymapdl/issues/1113#issuecomment-1319809346, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHEOASRK7IVHRDZ3Z3QMRFTWI5KMFANCNFSM5VRUOJTQ. You are receiving this because you were mentioned.Message ID: @.***>

germa89 commented 1 year ago

We should probably consider implementing a logic that checks if an MAPDL instance is running already at the given port. If start_instance is equal to True, we should launch another instance in another port.

This might require some rewriting on the launcher module which might be difficult. Also we will need to list the instances (e.g. posix with ps aux).

SerinaAnsys commented 1 year ago

@germa89 Kind of stupid question, in windows system, how to know which port the 'mapdl' is using? And what should be a valid port number? Is it just a random number?

germa89 commented 1 year ago

@germa89 Kind of stupid question, in windows system, how to know which port the 'mapdl' is using? And what should be a valid port number? Is it just a random number?

Hi @SerinaAnsys

By default the port is 50052. If the instance is already launched you can check mapdl.port in any OS.

>>> from ansys.mapdl.core import launch_mapdl
>>> mapdl = launch_mapdl()
>>> mapdl.port
50052 

Ideally a number above 50052. I tend to use any number between 50060-5080.

SerinaAnsys commented 1 year ago

@germa89


AttributeError Traceback (most recent call last) Cell In[10], line 1 ----> 1 mapdl.port

AttributeError: 'MapdlGrpc' object has no attribute 'port'

It seems doesn't work. Do you know why?

SerinaAnsys commented 1 year ago

Are we able to do that now? Suppose the mapdl is already exited, how can I check that and load a new one? Is there a command?

I tried to check ''mapdl' in locals()' and I see it's there. However, I tried to type 'mapdl', it says, 'MAPDL exited'.

We should probably consider implementing a logic that checks if an MAPDL instance is running already at the given port. If start_instance is equal to True, we should launch another instance in another port.

germa89 commented 1 year ago

Sorry... I meant mapdl._port.

germa89 commented 1 year ago

You can know if the session exited by doing:

>>> mapdl._exited
True # if exited.
germa89 commented 6 months ago

Most of the issues raised in this issue were fixed in: