ansys / pydpf-core

Data Processing Framework - Python Core
http://dpf.docs.pyansys.com/
MIT License
64 stars 23 forks source link

Bug located in DataFrame print command #1417

Closed AJJLagerweij closed 5 months ago

AJJLagerweij commented 5 months ago

Before submitting the issue

Description of the bug

I followed the example on the ansys.dpf.post website to learn about processing Ansys outputs from python. Sadly, I ran into an error simply by running the example, and performing the print(displacement_dataframe) command. There seems to be an issue regarding the type of attributes of the DataFrame.

It returns the following exact error

Traceback (most recent call last):
  File "/home/bram/.local/share/JetBrains/Toolbox/apps/pycharm-professional/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "/home/bram/.local/share/JetBrains/Toolbox/apps/pycharm-professional/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bram/.local/share/JetBrains/Toolbox/apps/pycharm-professional/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/bram/Documenten/TU Delft PostDoc/Specimen/APDL/main.py", line 850, in <module>
    print(displacement_dataframe)  # but printing fails.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bram/.miniconda3/envs/Ansys/lib/python3.11/site-packages/ansys/dpf/post/dataframe.py", line 436, in __str__
    self._update_str(
  File "/home/bram/.miniconda3/envs/Ansys/lib/python3.11/site-packages/ansys/dpf/post/dataframe.py", line 493, in _update_str
    values = self._first_n_ids_first_field(num_mesh_entities_to_ask)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bram/.miniconda3/envs/Ansys/lib/python3.11/site-packages/ansys/dpf/post/dataframe.py", line 707, in _first_n_ids_first_field
    return self._fc[0].scoping.ids[:n]
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bram/.miniconda3/envs/Ansys/lib/python3.11/site-packages/ansys/dpf/core/scoping.py", line 279, in ids
    return self._get_ids()
           ^^^^^^^^^^^^^^^
  File "/home/bram/.miniconda3/envs/Ansys/lib/python3.11/site-packages/ansys/dpf/core/scoping.py", line 172, in _get_ids
    np_array = settings.get_runtime_client_config(self._server).return_arrays
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'return_arrays''

I tried debugging the command. The settings.get_runtime_client_config(self._server) command gives a dictionary, specifically {'use_cache': False, 'streaming_buffer_size': 524288, 'stream_floats': False} which indeed cannot be transformed into an array with the array setter return_array.

Steps To Reproduce

Running the following script with the versions of the software on my computer, produce the error. These lines of code are the start of an example regarding DataFrame interaction on the pyansys post website.

from ansys.dpf import post
from ansys.dpf.post import examples

# Follow instructions on the post.docs.pyansys.com
example_path = examples.download_crankshaft()

# to enable auto-completion, use the equivalent:
simulation = post.StaticMechanicalSimulation(example_path)

# print the simulation to get an overview of what's available
print(simulation)

# get the displacement as a dataframe.
displacement_dataframe = simulation.displacement(all_sets=True)
print(type(displacement_dataframe))  # clearly a dataframe type
print(displacement_dataframe)  # but printing fails.

Which Operating System causes the issue?

Linux

Which DPF/Ansys version are you using?

Ansys 2023 R2

Which Python version causes the issue?

3.11

Installed packages

╭─  bram   /Specimen/APDL  ─────────────────────────────────────────────────────────
╰  python -m pip list                                                       ✔  0s     
Package                               Version
------------------------------------- ------------
ansys-additive-core                   0.17.0
ansys-api-additive                    1.4.1
ansys-api-dbu                         0.2.2
ansys-api-dyna                        0.3.5
ansys-api-edb                         1.0.0
ansys-api-fluent                      0.3.22
ansys-api-geometry                    0.3.5
ansys-api-mapdl                       0.5.1
ansys-api-mechanical                  0.1.1
ansys-api-meshing-prime               0.1.2
ansys-api-platform-instancemanagement 1.0.0
ansys-api-pyensight                   0.3.4
ansys-api-sherlock                    0.1.22
ansys-api-systemcoupling              0.1.0
ansys-dpf-composites                  0.3.2
ansys-dpf-core                        0.10.1
ansys-dpf-gate                        0.4.1
ansys-dpf-gatebin                     0.4.1
ansys-dpf-post                        0.6.0
ansys-dyna-core                       0.4.6
ansys-dynamicreporting-core           0.5.1
ansys-edb-core                        0.1.2
ansys-fluent-core                     0.18.2
ansys-geometry-core                   0.4.9
ansys-grantami-bomanalytics           2.0.0
ansys-grantami-bomanalytics-openapi   2.0.0
ansys-grantami-recordlists            1.1.0
ansys-grantami-serverapi-openapi      2.0.0
ansys-grpc-dpf                        0.8.1
ansys-mapdl-core                      0.67.0
ansys-mapdl-reader                    0.53.0
ansys-math-core                       0.1.3
ansys-mechanical-core                 0.10.6
ansys-mechanical-env                  0.1.2
ansys-meshing-prime                   0.5.1
ansys-motorcad-core                   0.4.0
ansys-openapi-common                  1.4.0
ansys-optislang-core                  0.5.1
ansys-platform-instancemanagement     1.1.2
ansys-pyensight-core                  0.7.5
ansys-pythonnet                       3.1.0rc3
ansys-seascape                        0.2.0
ansys-sherlock-core                   0.4.0
ansys-systemcoupling-core             0.3.1
ansys-tools-path                      0.4.1
ansys-turbogrid-api                   0.4.dev5
ansys-turbogrid-core                  0.4.dev1
appdirs                               1.4.4
asgiref                               3.7.2
bcrypt                                4.1.2
beartype                              0.17.0
bleach                                6.1.0
bokeh                                 3.3.4
build                                 1.0.3
cachetools                            5.3.2
certifi                               2024.2.2
cffi                                  1.16.0
charset-normalizer                    3.3.2
click                                 8.1.7
clr-loader                            0.2.6
contourpy                             1.2.0
cryptography                          42.0.2
cycler                                0.12.1
decorator                             5.1.1
defusedxml                            0.7.1
Deprecated                            1.2.14
dill                                  0.3.8
distro                                1.9.0
Django                                5.0.1
docker                                7.0.0
docutils                              0.20.1
dotnetcore2                           3.1.23
elementpath                           4.2.0
fabric                                3.2.2
filelock                              3.13.1
fonttools                             4.47.2
fpdf2                                 2.7.7
geomdl                                5.3.1
google-api-core                       2.16.2
google-api-python-client              2.116.0
google-auth                           2.27.0
google-auth-httplib2                  0.2.0
googleapis-common-protos              1.62.0
grpcio                                1.60.1
grpcio-health-checking                1.48.2
grpcio-status                         1.48.2
httplib2                              0.22.0
idna                                  3.6
importlib-metadata                    7.0.1
invoke                                2.2.0
jaraco.classes                        3.3.0
jeepney                               0.8.0
Jinja2                                3.1.3
keyring                               24.3.0
kiwisolver                            1.4.5
linkify-it-py                         2.0.3
lxml                                  5.1.0
Markdown                              3.5.2
markdown-it-py                        3.0.0
MarkupSafe                            2.1.5
matplotlib                            3.8.2
mdit-py-plugins                       0.4.0
mdurl                                 0.1.2
mkl-fft                               1.3.8
mkl-random                            1.2.4
mkl-service                           2.4.0
more-itertools                        10.2.0
mpld3                                 0.5.9
munkres                               1.1.4
nh3                                   0.2.15
numpy                                 1.26.4
packaging                             23.2
pandas                                2.2.0
panel                                 1.3.8
param                                 2.0.2
paramiko                              3.4.0
pexpect                               4.9.0
pillow                                10.2.0
Pint                                  0.23
pip                                   23.3.1
pkginfo                               1.9.6
platformdirs                          4.2.0
plotly                                5.18.0
plumbum                               1.8.2
pooch                                 1.8.0
protobuf                              3.20.3
psutil                                5.9.8
ptyprocess                            0.7.0
pyaedt                                0.7.10
pyansys                               2024.1.5
pyansys-tools-versioning              0.5.0
pyasn1                                0.5.1
pyasn1-modules                        0.3.0
pycparser                             2.21
Pygments                              2.17.2
pygranta                              2024.1.0
pyiges                                0.3.1
PyNaCl                                1.5.0
pyparsing                             3.1.1
pypng                                 0.20220715.0
pyproject_hooks                       1.0.0
pyspnego                              0.10.2
python-dateutil                       2.8.2
pytwin                                0.6.0
pytz                                  2024.1
pyvista                               0.43.2
pyviz_comms                           3.0.1
PyYAML                                6.0.1
readme-renderer                       42.0
requests                              2.31.0
requests-ntlm                         1.2.0
requests-toolbelt                     1.0.0
rfc3986                               2.0.0
rich                                  13.7.0
rpyc                                  5.3.1
rsa                                   4.9
scipy                                 1.12.0
scooby                                0.9.2
SecretStorage                         3.3.3
setuptools                            68.2.2
six                                   1.16.0
sqlparse                              0.4.4
tenacity                              8.2.3
tornado                               6.4
tqdm                                  4.66.1
twine                                 4.0.2
typing_extensions                     4.9.0
tzdata                                2023.4
uc-micro-py                           1.0.2
uritemplate                           4.1.1
urllib3                               2.2.0
vtk                                   9.3.0
webencodings                          0.5.1
wheel                                 0.41.2
wrapt                                 1.16.0
xmlschema                             2.5.1
xyzservices                           2023.10.1
zipp                                  3.17.0
PProfizi commented 5 months ago

Hi @AJJLagerweij , please try again after uninstalling ansys-dpf-gate, ansys-dpf-gatebin and ansys-grpc-dpf from your Python environment. Is this a fresh venv, and if so, did you create it using the PyAnsys Installer?

AJJLagerweij commented 5 months ago

Many thanks for the quick reply.

To answer your questions, the environment is not made by the PyAnsys installer, rather a week-old anaconda environment. Reinstalling the environment, and installing only specific ansys packages, did resolve my issues.

For future reference, the correctly created environment was setup with:

  1. Create conda envirionment and install things like numpy and matplotlib.
    • conda create --name APDL python=3.11
    • conda install scipy pandas matplotlib (not required)
  2. Use pip to install ansys-packages:
    • pip install ansys-mapdl-core
    • pip install ansys-dpf-post

(in my case there was an extra issue, probably related to ansys-mapdl-core and thus not to the issue mentioned above, which required an exctra step to fix)

  1. Fix broken libstdc++.so.6 and GLIBCXX_3.4.30 dependency through:
    • Instal/update libstdc++ (on fedora sudo dnf install libstdc++)
    • Check libstdc++ GLIBCXX support versions with strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
    • Create symlink to this file in your conda envirioment ln -sf /usr/local/lib64/libstdc++.so.6 path/to/your/conda/envirionment/lib/libstdc++.so.6

Sorry for wasting your time, all is working fine now.

PProfizi commented 5 months ago

@AJJLagerweij Glad you managed to make it work, and thank you so much for the detailed description of the steps you had to take!