ansys / pymechanical

Pythonic interface to Ansys Mechanical β„’
https://mechanical.docs.pyansys.com/
MIT License
36 stars 18 forks source link

Bug located in ...launch_mechanical with remote session #417

Closed narnia-mason closed 1 year ago

narnia-mason commented 1 year ago

πŸ” Before submitting the issue

🐞 Description of the bug

I'm struggling with using PyMechanical remote session.

A valid Ansys has been installed in a local Windows machine. I'm planning to run Mechanical using PyMechanical remote session from a different Linux machine. The main script is as follow:

from ansys.mechanical.core import launch_mechanical

mechanical = launch_mechanical(ip='172.xxx.xxx.1')
mechanical.run_python_script(script_block)
mechanical.exit()

However, launch_mechanical does not respond and eventually it returns timeout error.

I've checked that it works with a PyMechanical installed in the same Windows machine.

Is there any necessary setting for the local Ansys or Windows machine beforehand? Or do I need to try with every possible port?

P.S. the ping test has been passed.

πŸ“ Steps to reproduce

  1. Installing WSL2 Ubuntu-20.04 distribution on a Windows machine.

  2. Checking the IP address of the local Windows machine from the WSL Ubuntu as follows:

    $ ip route

    It returns

    default via 172.xxx.xxx.1 dev eth0 
    172.xxx.xxx.0/20 dev eth0 proto kernel scope link src 172.xxx.yyy.124

    The IP address after default via is the IP of the local Windows machine.

  3. Creating a new Windows Firewall inbound rule (for the ping test).

  4. Creating a new conda environment in the WSL Ubuntu.

  5. Installing PyMechanical $ python -m pip install ansys-mechanical-core in the conda environment.

  6. Running launch_mechanical(ip='172.xxx.xxx.1') it returns OSError: Unable to connect to Mechanical instance at 172.xxx.xxx.1:10000.

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

2023 R1

🐍 Which Python version are you using?

3.10

πŸ“¦ Installed packages

ansys-api-mechanical==0.1.0
ansys-api-platform-instancemanagement==1.0.0
ansys-mechanical-core==0.10.2
ansys-platform-instancemanagement==1.1.2
ansys-pythonnet==3.1.0rc1
ansys-tools-path==0.3.1
appdirs==1.4.4
asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1694046349000/work
attrs==23.1.0
backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work
backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1687772187254/work
cached-property @ file:///home/conda/feedstock_root/build_artifacts/cached_property_1615209429212/work
certifi==2023.7.22
cffi==1.15.1
cftime @ file:///home/conda/feedstock_root/build_artifacts/cftime_1695560979326/work
chardet==5.2.0
charset-normalizer==3.2.0
click==8.1.7
clr-loader==0.2.6
colorlog==6.7.0
comm @ file:///home/conda/feedstock_root/build_artifacts/comm_1691044910542/work
Cython==3.0.2
debugpy @ file:///croot/debugpy_1690905042057/work
decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work
embreex==2.17.7.post3
entrypoints @ file:///home/conda/feedstock_root/build_artifacts/entrypoints_1643888246732/work
exceptiongroup @ file:///home/conda/feedstock_root/build_artifacts/exceptiongroup_1692026125334/work
executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1667317341051/work
grpcio==1.58.0
h5py @ file:///home/conda/feedstock_root/build_artifacts/h5py_1656336064499/work
idna==3.4
imageio==2.31.4
importlib-metadata @ file:///home/conda/feedstock_root/build_artifacts/importlib-metadata_1688754491823/work
ipykernel @ file:///home/conda/feedstock_root/build_artifacts/ipykernel_1693880262622/work
ipython @ file:///home/conda/feedstock_root/build_artifacts/ipython_1693579759651/work
jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1690896916983/work
jsonschema==4.19.1
jsonschema-specifications==2023.7.1
jupyter-client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1654730843242/work
jupyter_core @ file:///home/conda/feedstock_root/build_artifacts/jupyter_core_1695648222969/work
lazy_loader==0.3
lxml==4.9.3
mapbox-earcut==1.0.1
markdown-it-py @ file:///home/conda/feedstock_root/build_artifacts/markdown-it-py_1686175045316/work
matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1660814786464/work
mdurl @ file:///home/conda/feedstock_root/build_artifacts/mdurl_1639515908913/work
meshio @ file:///home/conda/feedstock_root/build_artifacts/meshio_1647016219543/work
nest-asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1664684991461/work
netCDF4 @ file:///home/conda/feedstock_root/build_artifacts/netcdf4_1656505563317/work
networkx==3.1
numpy @ file:///home/conda/feedstock_root/build_artifacts/numpy_1695290862901/work/dist/numpy-1.26.0-cp310-cp310-linux_x86_64.whl#sha256=44509c98ccedaff13cf312f80a8e392a35d5f649bdf63f1b7e705fdfdc621c6d
packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1681337016113/work
parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1638334955874/work
pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1667297516076/work
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work
Pillow==10.0.1
platformdirs @ file:///home/conda/feedstock_root/build_artifacts/platformdirs_1690813113769/work
prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1688565951714/work
protobuf==3.20.3
psutil @ file:///opt/conda/conda-bld/psutil_1656431268089/work
ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1609419310487/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl
pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work
pycollada==0.7.2
pycparser==2.21
pygalmesh @ file:///home/conda/feedstock_root/build_artifacts/pygalmesh_1667124688214/work
pyglet==1.5.27
Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1691408637400/work
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1626286286081/work
python-fcl==0.7.0.5
PyWavelets==1.4.1
pyzmq @ file:///croot/pyzmq_1686601365461/work
referencing==0.30.2
requests==2.31.0
rich @ file:///home/conda/feedstock_root/build_artifacts/rich-split_1694974539951/work/dist
rpds-py==0.10.3
Rtree==1.0.1
scikit-image==0.21.0
scipy==1.11.2
shapely==2.0.1
six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
stack-data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1669632077133/work
svg.path==6.3
tifffile==2023.9.18
tornado @ file:///home/conda/feedstock_root/build_artifacts/tornado_1648827254365/work
tqdm==4.66.1
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1694710374095/work
trimesh==3.23.5
typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1695040754690/work
urllib3==2.0.5
wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1673864653149/work
xatlas==0.0.8
xxhash==3.3.0
zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1695255097490/work
koubaa commented 1 year ago

@narnia-mason launch_mechanical may actually be misnamed here. It is only capable of launching mechanical on the local machine, and when a remote IP is used, it only tries to connect to it. @samigithub2022 is that correct?

narnia-mason commented 1 year ago

@koubaa I'm not sure... πŸ₯² I just found a different approach in here. It says

from ansys.mechanical.core import Mechanical
mechanical = Mechanical(ip=my_ip_address, port=my_port)

But it does not work either.

Many materials say using launch_mechanical with ip address argument to connect remotely.

samigithub2022 commented 1 year ago

@narnia-mason - as @koubaa mentioned launch_mechanical is only capable of launching on a local machine. You can use the same function to connect to a mechanical instance running on a different machine. Mechanical(ip, port) - is also used for only connecting. These two apis are similar to pymapdl.

Your requirement is - launch a Mechanical session on Windows. Connect from Linux machine.

you can try something like this:

On Windows machine: You can either launch mechanical manually. "C:\Program Files\ANSYS Inc\v232\aisol\bin\winx64\AnsysWBU.exe" -DSApplet -nosplash -notabctrl -grpc 10000

or using the pymechanical API

import ansys.mechanical.core as pymechanical
# to launch in batch/non-UI mode with the given path to AnsysWBU.exe 
# useful, if you need to work with different versions / installs
# mechanical = pymechanical.launch_mechanical(exec_file=exe_path, batch=True, cleanup_on_exit=False, port=10000)
# to launch with latest version in batch mode
mechanical = pymechanical.launch_mechanical(batch=True, cleanup_on_exit=False, port=10000)

On Linux machine:

import ansys.mechanical.core as pymechanical
mechanical = pymechanical.launch_mechanical(start_instance=False, cleanup_on_exit=False, clear_on_connect=False, ip=windows_hostname_or_ip, port=10000)
...
mechanical.Exit(force=True) # Exit without asking for the confirmation from the UI

Please let me know if you need more info.

narnia-mason commented 1 year ago

@samigithub2022 Thanks! It works! :) So, I need to run AnsysWBU.exe on the local machine, and then I can access it from the other machine, right? But, can I run AnsysWBU.exe without GUI (batch mode)? I cannot find any related document for other AnsysWBU.exe options.

pmaroneh commented 1 year ago

@samigithub2022 This is not the first time I see users wondering how to start a remote session from remote computer, and then connect to it. Could we add a page in the help about this? Thanks

RobPasMue commented 1 year ago

@samigithub2022 @pmaroneh @koubaa @klmcadams @dipinknair

We should create a FAQ site in the documentation, similarly to other projects:

https://fluent.docs.pyansys.com/version/stable/getting_started/faqs.html https://geometry.docs.pyansys.com/version/stable/getting_started/faq.html https://mapdl.docs.pyansys.com/version/stable/getting_started/faq.html

samigithub2022 commented 1 year ago

@narnia-mason - we do give that control - launch in UI or batch launch_mechanical(batch=True,...) 'batch' argument controls the behavior.

We don't currently document the AnsysWBU.exe options. I can create a story on the development side for v242.

@RobPasMue That's a good idea. We should be able to add that in the FAQ.@pmaroneh @koubaa @klmcadams @dipinknair

samigithub2022 commented 1 year ago

@narnia-mason

we already have a documentation on the pymechanical side about

"Launch Mechanical from the command line"

Please refer the following link for details

https://mechanical.docs.pyansys.com/version/stable/getting_started/running_mechanical.html#launch-mechanical-from-the-command-line

thanks @koubaa for pointing to this.

FYI @koubaa @pmaroneh @klmcadams @dipinknair