ansys / pymechanical

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

gRPC Error with Ansys 2023 R2 and Conda Environment #371

Closed lstubbig closed 11 months ago

lstubbig commented 1 year ago

πŸ” Before submitting the issue

🐞 Description of the bug

Hi, I am trying to use pymechanical with a conda environment and Ansys 2023 R2 on a Windows machine. I followed the normal installation steps (see below) and Workbench 2023 R2 is running.

pymechanical also finds the path to AnsysWBU.exe: image

However, trying to verify the installation results in a gRPC error (VersionError: The Mechanical gRPC interface requires Mechanical 2023 R1 or later.): image

Not sure if this is a bug (Anys 2023 R2 is later than R1 and available) or a problem with my setup. Any ideas?

πŸ“ Steps to reproduce

πŸ’» Which operating system are you using?

Windows

πŸ“€ Which ANSYS version are you using?

2023 R2

🐍 Which Python version are you using?

3.11

πŸ“¦ Installed packages

ansys-api-mechanical==0.1.0
ansys-api-platform-instancemanagement==1.0.0
ansys-mechanical-core==0.10.1
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_1670263926556/work
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
cffi==1.15.1
click==8.1.7
clr-loader==0.2.6
colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1666700638685/work
comm @ file:///home/conda/feedstock_root/build_artifacts/comm_1691044910542/work
debugpy @ file:///C:/b/abs_c0y1fjipt2/croot/debugpy_1690906864587/work
decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work
executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1667317341051/work
grpcio==1.57.0
importlib-metadata @ file:///home/conda/feedstock_root/build_artifacts/importlib-metadata_1688754491823/work
ipykernel @ file:///D:/bld/ipykernel_1691424574547/work
ipython @ file:///D:/bld/ipython_1685727936079/work
jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1690896916983/work
jupyter_client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1687700988094/work
jupyter_core @ file:///D:/bld/jupyter_core_1686775880418/work
matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1660814786464/work
nest-asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1664684991461/work
packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1681337016113/work
parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1638334955874/work
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work
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:///C:/ci_311_rebuilds/psutil_1679005906571/work
pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work
pycparser==2.21
Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1691408637400/work
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1626286286081/work
pywin32==305.1
pyzmq @ file:///C:/b/abs_655zk4a3s8/croot/pyzmq_1686601465034/work
six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
stack-data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1669632077133/work
tornado @ file:///C:/b/abs_61jhmrrua1/croot/tornado_1690848767317/work
tqdm==4.66.1
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1675110562325/work
typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1688315532570/work
wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1673864653149/work
zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1689374466814/work
koubaa commented 1 year ago

@klmcadams could you please look into this?

lstubbig commented 1 year ago

Hi, did you have look at this problem? We soon have to decide on an approach for automating our simulations and Anaconda is the only approved Python distribution at the company.

klmcadams commented 1 year ago

Hi, did you have look at this problem? We soon have to decide on an approach for automating our simulations and Anaconda is the only approved Python distribution at the company.

Hi, I haven't had a chance to look at it, but I will look at it today and let you know. Thanks for your patience!

klmcadams commented 1 year ago

Hi @lstubbig, I wasn't able to recreate the error you were seeing using ansys-mechanical-core==0.10.1 and grpcio==1.57.0. Could you try recreating your conda environment and installing ansys-mechanical-core==0.10.2 and grpcio==1.58.0? Those were the only differences I saw between our pip freeze outputs. I attached a video following the steps to reproduce above. Please let me know if this works or if you are still seeing the error. Thanks!

video.webm

lstubbig commented 1 year ago

Thanks for running the test! Unfortunately the exactly list of packages still results in the same error message. I am using Anaconda Prompt and tried ansys-mechanical-core==0.10.1 and 0.10.2, both with grpcio==1.58.0:

(pymech2) C:\Users\XXX\Documents>python --version
Python 3.11.5

(pymech2) C:\Users\XXX\Documents>pip freeze
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
cffi==1.15.1
click==8.1.7
clr-loader==0.2.6
colorama==0.4.6
grpcio==1.58.0
importlib-metadata==6.8.0
platformdirs==3.10.0
protobuf==3.20.3
pycparser==2.21
tqdm==4.66.1
zipp==3.17.0

(pymech2) C:\Users\XXX\Documents>type pymech-test.py
from ansys.mechanical.core import launch_mechanical 
mech = launch_mechanical()
print(mech.version)

(pymech2) C:\Users\XXX\Documents>python pymech-test.py
CRITICAL -  -  logging - handle_exception - Uncaught exception
Traceback (most recent call last):
  File "C:\Users\XXX\Documents\pymech-test.py", line 3, in <module>
    mech = launch_mechanical()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\pymech2\Lib\site-packages\ansys\mechanical\core\mechanical.py", line 2235, in launch_mechanical
    raise exception
  File "C:\ProgramData\Anaconda3\envs\pymech2\Lib\site-packages\ansys\mechanical\core\mechanical.py", line 2220, in launch_mechanical
    port = launch_grpc(port=port, verbose=verbose_mechanical, **start_parm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\pymech2\Lib\site-packages\ansys\mechanical\core\mechanical.py", line 1909, in launch_grpc
    raise VersionError("The Mechanical gRPC interface requires Mechanical 2023 R1 or later.")
ansys.mechanical.core.errors.VersionError: The Mechanical gRPC interface requires Mechanical 2023 R1 or later.

The executable is correctly found:

(pymech2) C:\Users\XXX\Documents>python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansys.mechanical.core as a
>>> a.find_mechanical()
('C:\\Program Files\\ANSYS Inc\\v232\\aisol\\bin\\winx64\\AnsysWBU.exe', 23.2)

What else could I try?

koubaa commented 1 year ago

@lstubbig There's a version argument, like this launch_mechanical(version=232), but looking at it, the version is ignored unless pypim is used. (that's a documented limitation but we should support it)

try running ansys.tools.path.version_from_path("mechanical", ""), this is what launch_mechanical internally uses to find the version, before it ever tries to start the process.

import ansys.tools.path
ansys.tools.path.version_from_path("mechanical", "")

If ansys.tools.path.version_from_path("mechanical", "") returns 231, but find_mechanical returns 232, then this is a bug in the ansys.tools.path library.

lstubbig commented 1 year ago

@koubaa Here's the output. It looks like ansys.tools.path.version_from_path("mechanical", "") does return the correct version.

(pymech2) C:\Users\XXX>python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansys.tools.path
>>> import ansys.mechanical.core as a
>>> apath = a.find_mechanical()[0]
>>> apath
'C:\\Program Files\\ANSYS Inc\\v232\\aisol\\bin\\winx64\\AnsysWBU.exe'
>>> ansys.tools.path.version_from_path("mechanical", apath)
232
>>> a.find_mechanical()
('C:\\Program Files\\ANSYS Inc\\v232\\aisol\\bin\\winx64\\AnsysWBU.exe', 23.2)

Is this what you would expect as normal behaviour? launch_mechanical(version=232) results in the same VersionError as above.

koubaa commented 1 year ago

@lstubbig

Until #419 is fixed the version argument of launch_mechanical won't have an effect for you.

I see one more block of code that might be responsible.

try running this: ansys.tools.path.get_mechanical_path(False)

lstubbig commented 11 months ago

Hi, thanks again for the help. I got around to testing it and this is the output:

(pymech2) C:\Users\XXX>python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansys.tools.path
>>> ansys.tools.path.get_mechanical_path(False)
'C:\\Program Files\\ANSYS Inc\\v212\\aisol\\bin\\winx64\\AnsysWBU.exe'

This seems to point at the old version (21.2)! I have it on my machine (2019R3, 2021R2 and 2023R2), so the path exists.

koubaa commented 11 months ago

@lstubbig I filed a bug to the ansys.tools.path project, I think it needs to be fixed there. I did miss one thing, I wanted to know the output of ansys.tools.path.version_from_path("mechanical", "") when the second argument is an empty string, not ansys.mechanical.core.find_mechanical()[0].

ansys.tools.path will store the results of its search in your appdata folder under platformdirs.user_data_dir(appname="ansys_tools_path", appauthor="Ansys") which for me evaluates to 'C:\Users\mkoubaa\AppData\Local\Ansys\ansys_tools_path'

Can you please attach the contents of that folder to this bug, we can use it to fix the issue. In the meantime, you can try removing that folder and that should reset the behavior of ansys.tools.path.

lstubbig commented 11 months ago

@koubaa Here's the output of ansys.tools.path.version_from_path("mechanical", ""):

(pymech2) C:\Users\XXX>python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansys.tools.path
>>> ansys.tools.path.version_from_path("mechanical", "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\envs\pymech2\Lib\site-packages\ansys\tools\path\path.py", line 909, in version_from_path
    return _mechanical_version_from_path(path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\pymech2\Lib\site-packages\ansys\tools\path\path.py", line 864, in _mechanical_version_from_path
    raise RuntimeError(f"Unable to extract Mechanical version from {path}.")
RuntimeError: Unable to extract Mechanical version from .

There was one file in C:\Users\XXX\AppData\Local\Ansys\ansys_tools_path, which points at 2021R2. I attached it here: config.txt

After deleting it PyMechanical launches!

koubaa commented 11 months ago

@lstubbig great! Since this issue is now tracked in the ansys.tools.path project, I am closing this issue. cc @samigithub2022 @klmcadams @dipinknair