Closed Abdulla060 closed 11 months ago
Hi @Abdulla060
I think I am going to need a bit more explanations about this.
If you are working on WSL, can you launch MAPDL from inside WSL?? I didn't know you can do that.
In that case, I guess you can launch MAPDL (start_instance=True
) but the IP of the MAPDL instance won't be the local IP (127.0.0.1
) but the Windows OS IP (127.0.1.1
).
I see there is a conflict there because if you start the instance, it is expected to be in the local IP.
Before I do any changes on this, I will have to test locally. Feel free to recommend any approach or suggest any script for this.
See Windows Subsystem Linux in PyMAPDL for more information. Pinging @RobPasMue because I think this could be interesting for him.
Definitely interested... 😄
Hi @Abdulla060
I think I am going to need a bit more explanations about this.
If you are working on WSL, can you launch MAPDL from inside WSL?? I didn't know you can do that.
In that case, I guess you can launch MAPDL (
start_instance=True
) but the IP of the MAPDL instance won't be the local IP (127.0.0.1
) but the Windows OS IP (127.0.1.1
). I see there is a conflict there because if you start the instance, it is expected to be in the local IP.Before I do any changes on this, I will have to test locally. Feel free to recommend any approach or suggest any script for this.
See Windows Subsystem Linux in PyMAPDL for more information. Pinging @RobPasMue because I think this could be interesting for him.
In wsl you can run ANY Windows program simply by calling it from the terminal ref. ANSYS is no different.
to test this: 1- install ANSYS on windows 2- install wsl2 3- Install conda in wsl and create an environment 4- Install pymapdl in this environment 5- Run the following script inside of wsl
import time
import threading
import matplotlib.pyplot as plt
from ansys.mapdl.core import launch_mapdl
def starter():
launch_mapdl(
exec_file='/mnt/c/Program Files/ANSYS Inc/v231/ANSYS/bin/winx64/ANSYS231.exe',
start_timeout=10000
)
# some threading gymnastics to run the instance and connect to it.
# launch_mapdl will block until it connects to the instance (which will never happen)
starter_thread = threading.Thread(target=starter)
starter_thread.start()
apdl = launch_mapdl(
ip='172.25.192.1' # ip of the windows host in the hyper-v VLAN
)
apdl.prep7()
apdl.et(1, 183)
apdl.mp('ex', 1, 200e6)
apdl.mp('prxy', 1, 0.3)
apdl.k(1, 0, 0)
apdl.k(2, 50, 0)
apdl.k(3, 50, 50)
apdl.k(4, 0, 50)
apdl.l(1, 2)
apdl.l(2, 3)
apdl.l(3, 4)
apdl.l(4, 1)
apdl.lesize(5)
apdl.al(1, 2, 3, 4)
apdl.amesh('all')
apdl.run('/solu')
apdl.nsel('s', 'loc', 'y', 0)
apdl.d('all', 'ux', 0)
apdl.d('all', 'uy', 0)
apdl.nsel('s', 'loc', 'y', 50)
apdl.f('all', 'fy', -100)
apdl.nsel('all')
apdl.solve()
coords_x = apdl.mesh.nodes[:, 0]
coords_y = apdl.mesh.nodes[:, 1]
displacement_y = apdl.post_processing.nodal_displacement('y')
plt.tricontourf(coords_x, coords_y, displacement_y, levels=50)
plt.colorbar()
plt.show()
apdl.exit()
starter_thread.join()
Hi @Abdulla060
I'm trying locally, but I think my WSL Python process cannot connect to the MAPDL process in the host machine. I believe it is a firewall issue or IP mapping.
I have disabled the firewall and try as IP the one in /etc/hosts
(host.docker.internal
) and the one obtained from ip route
.
Do you have any suggestions to allow WSL to connect to the MAPDL process at the host?? (Windows 11)
@germa89 in the Windows host run the ipconfig
command and use the IP under the Ethernet adapter vEthernet (WSL)
adapter.
edit: the ip of the host machine is also shown when you run the ip route
default via 172.25.192.1 dev eth0 proto kernel <<<=== this
172.25.192.0/20 dev eth0 proto kernel scope link src 172.25.195.101 <<<=== not this
I still cannot connect to the local instance. I am not sure what is happening.
In the meantime, if you can check this branch, it will be very helpful. https://github.com/ansys/pymapdl/pull/2324
I'll check it in a couple of hours.
For the record, i didn't do anything in term of configuration. My code worked pretty much out of the box.
To troubleshoot, try to run something else on the windows host and try to access it from wsl. Just to rule out that the problem is not in Ansys of mapdl.
Example: hfs on Windows and try to get a file using wget
from wsl. If you still can't then the problem is networking related.
I still cannot connect to the local instance. I am not sure what is happening.
In the meantime, if you can check this branch, it will be very helpful. #2324
@germa89 I just tested this out. works like a charm.
one issue though, I still had to specify the exec_file
in launch_mapdl
. so it looks like we should also add this new path to the default installation paths of ANSYS. not really required but definitely nice to have
I could do some checks.
For example, if ON_WSL
is True
(this env var is based on having some predefined env vars, see #2324), I we can add the /mnt/c...
path to the list of paths to check.
Furthermore, we could check if the AWP_ROOT
env var exists in the host:
https://stackoverflow.com/a/50051520/6650211
But given the WSL architecture and my problems to test it, it might be buggy.
Stack OverflowI was thinking of adding something like this to my setup.bash script. ln -s /mnt/c/Users/Ryan/Downloads $HOME/Downloads But obviously that isn't always an accurate path so I was hoping to be able...
@Abdulla060 The changes required to allow PyMAPDL to launch MAPDL in the host OS natively must be done in the package ansys-tools-path. Hence I'm closing here as completed.
If I have time, I will explore the possibility of doing the changes required in that library.
@germa89 I will also look at it when I have the time. That said the original issue of start_instance
being forced to False is still unresolved. What I don't understand is why this is even needed.
@germa89 I will also look at it when I have the time. That said the original issue of
start_instance
being forced to False is still unresolved. What I don't understand is why this is even needed.
On the branch I'm working in #2324 the start_instance
as default is disabled when ON_WSL
.
start_instance
needs to be set to False
if the IP is passed, because normally, you cannot launch MAPDL instances in a different IP than yours. WSL is the exception I would say. PyMAPDL checks that variable later in the code to see if it needs to launch it locally or not.
and
@Abdulla060 Once #2324 is merged, you should be able to launch and connect to MAPDL from WSL. Please do check it and report any issues.
The exec_file
is still needed (depends on ansys-tools-path
package) but you do not need to specify the IP address which I think it is good!
Description of the feature
This will allow the ANSYS instance to be started from within wsl2 even if ANSYS is not installed there.
This situation is relatively common when using conda with wsl2. For example, a user might be doing machine learning research and they are using Tensorflow with conda. This creates a situation where they have to maintain 2 separate Python environments, inside and outside wsl.
Steps for implementing the feature
I'm not really sure as i haven't delved into the source code yet
Useful links and references
No response