ansys / pyaedt

AEDT Python Client Package
https://aedt.docs.pyansys.com
MIT License
207 stars 128 forks source link

Bug located in Maxwell2DManager.plot - logging not used to issue "install with" information #3097

Closed ansAFinney closed 8 months ago

ansAFinney commented 1 year ago

Before submitting the issue

Description of the bug

I attempted to use Maxwell2DManager.plot within a SAF GLOW method without pyvista and numpy in the virtual environment.

The method execution environment in SAF/GLOW recorded the python log (at the INFO level) as follows:

2023-06-07 13:45:47,980 INFO [ansys.platform.instancemanagement.client] [client.py:55] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Connecting.
2023-06-07 13:45:47,991 INFO [root] [aedt.py:255] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- calling Maxwell2d(specified_version="2023.1", machine="127.0.0.1", port=62015)
2023-06-07 13:45:48,091 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- StdOut has been enabled
2023-06-07 13:45:48,092 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- using existing logger.
2023-06-07 13:45:48,098 INFO [Global] [aedt_logger.py:479] [trace_id=0 span_id=0 resource.service.name=Method Runner]- AEDT file load (threaded) time: 0.006998300552368164
2023-06-07 13:45:48,149 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- AEDT installation Path C:\Program Files\AnsysEM\v231\Win64
2023-06-07 13:45:48,150 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Launching AEDT with the gRPC plugin.
2023-06-07 13:45:48,160 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Connecting to AEDT session on gRPC port 62015
2023-06-07 13:45:48,168 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- pyaedt v0.6.79
2023-06-07 13:45:48,168 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Python version 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
2023-06-07 13:45:48,170 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- AEDT 2023.1.0 Build Date 2022-11-20 22:10:41
2023-06-07 13:45:48,175 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Project project set to active.
2023-06-07 13:45:48,177 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Aedt Objects initialized
2023-06-07 13:45:48,177 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Variable Manager initialized
2023-06-07 13:45:48,177 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Design Loaded
2023-06-07 13:45:48,177 INFO [Global] [aedt_logger.py:479] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Materials Loaded
2023-06-07 13:45:48,556 ERROR [Global] [general_methods.py:55] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]-   File "D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py", line 1491, in plot, NAME ERROR
2023-06-07 13:45:48,557 ERROR [Global] [general_methods.py:55] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Method arguments: 
2023-06-07 13:45:48,557 ERROR [Global] [general_methods.py:55] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]-     export_image_path = C:\Users\afinney\OneDrive - ANSYS, Inc\Documents\x2\.product_instance_state\first_step\aedt\plot.jpg 
2023-06-07 13:45:48,557 ERROR [Global] [general_methods.py:55] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- Check Online documentation on: https://aedt.docs.pyansys.com/version/stable/search.html?q=plot+export_image_path
2023-06-07 13:45:48,574 ERROR [root] [method_runner.py:60] [trace_id=06894ad4a5cf64e391897b8af3c2eb9f span_id=e65098978bcc31a5 resource.service.name=Method Runner]- [Errno 2] No such file or directory: 'C:\\Users\\afinney\\OneDrive - ANSYS, Inc\\Documents\\x2\\.product_instance_state\\first_step\\aedt\\plot.jpg' - Traceback (most recent call last):

whereas running the same code directly in python I got the following more informative output.

>>> maxwell_2d.plot(show=False, export_path=os.path.join(maxwell_2d.working_directory, "Image.jpg"), plot_air_objects=True)
D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py:22: UserWarning: The NumPy module is required to run some functionalities of PostProcess.
Install with

pip install numpy

Requires CPython.
  warnings.warn(
D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py:32: UserWarning: The PyVista module is required to run some functionalities of PostProcess.
Install with

pip install pyvista

Requires CPython.
  warnings.warn(
Install with

pip install matplotlib

Requires CPython.
  warnings.warn(
D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\modules\AdvancedPostProcessing.py:21: UserWarning: The NumPy module is required to run some functionalities of PostProcess.
Install with

pip install numpy
Requires CPython.
  warnings.warn(
PyAEDT ERROR:   File "D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py", line 1491, in plot, NAME ERROR
PyAEDT ERROR: Method arguments:
PyAEDT ERROR:     export_image_path = C:/Users/afinney/AppData/Local/Temp/pyaedt_prj_8WE/Project_YEI.pyaedt\Maxwell_2D_OAF\Image.jpg
PyAEDT ERROR: Check Online documentation on: https://aedt.docs.pyansys.com/version/stable/search.html?q=plot+export_image_path
<pyaedt.generic.plot.ModelPlotter object at 0x00000279B0678550>

pyaedt should ensure the extra information above, the "Install with" information, is logged as Errors so that it is visible in logs.

Steps To Reproduce

run the following in an venv without numpy or pyvista

import logging
import os
import pyaedt

logging.basicConfig(filename='c:\\temp\\log.log', level=logging.DEBUG)

maxwell_2d = pyaedt.Maxwell2d(
    solution_type="TransientXY",
    specified_version="2023.1",
    non_graphical=True,
    new_desktop_session=True,
    projectname=pyaedt.generate_unique_project_name())

rect1 = maxwell_2d.modeler.create_rectangle([0, 0, 0], [10, 20], name="winding", matname="copper")
added = rect1.duplicate_along_line([14, 0, 0])
rect2 = maxwell_2d.modeler[added[0]]

region = maxwell_2d.modeler.create_region([100, 100, 100, 100, 100, 100])

maxwell_2d.assign_winding([rect1.name, rect2.name], name="PHA")
maxwell_2d.assign_balloon(region.edges)

maxwell_2d.plot(show=False, export_path=os.path.join(maxwell_2d.working_directory, "Image.jpg"), plot_air_objects=True)

the following is output to console:

Install with

pip install numpy

Requires CPython.
  warnings.warn(
D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py:32: UserWarning: The PyVista module is required to run some functionalities of PostProcess.
Install with

pip install pyvista

Requires CPython.
  warnings.warn(
D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py:43: UserWarning: The Matplotlib module is required to run some functionalities of PostProcess.
Install with

pip install matplotlib

Requires CPython.
  warnings.warn(
D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\modules\AdvancedPostProcessing.py:21: UserWarning: The NumPy module is required to run some functionalities of PostProcess.
Install with

pip install numpy

Requires CPython.
  warnings.warn(
PyAEDT ERROR:   File "D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py", line 1491, in plot, NAME ERROR
PyAEDT ERROR: Method arguments: 
PyAEDT ERROR:     export_image_path = C:/Users/afinney/AppData/Local/Temp/pyaedt_prj_ZED/Project_8CT.pyaedt\Maxwell_2D_KSF\Image.jpg
PyAEDT ERROR: Check Online documentation on: https://aedt.docs.pyansys.com/version/stable/search.html?q=plot+export_image_path

but the file c:\temp\log.log only contains

INFO:Global:StdOut has been enabled
INFO:Global:using existing logger.
INFO:Global:AEDT installation Path C:\Program Files\AnsysEM\v231\Win64
INFO:Global:Launching AEDT with the gRPC plugin.
INFO:Global:New AEDT session is starting on gRPC port 63738
INFO:Global:Ansoft.ElectronicsDesktop.2023.1  version started with process ID 32052.
INFO:Global:pyaedt v0.6.79
INFO:Global:Python version 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
INFO:Global:AEDT 2023.1.0 Build Date 2022-11-20 22:10:41
INFO:Global:Project Project_8CT has been created.
INFO:Global:No design is present. Inserting a new design.
INFO:Global:Added design 'Maxwell 2D_KSF' of type Maxwell 2D.
INFO:Global:Aedt Objects initialized
INFO:Global:Variable Manager initialized
INFO:Global:Design Loaded
INFO:Global:Materials Loaded
INFO:Global:aedt file load time 0.0060007572174072266
INFO:Global:Successfully loaded project materials !
ERROR:Global:  File "D:\ANSYSDEV\tutorial-simple-instance\.venv\lib\site-packages\pyaedt\generic\plot.py", line 1491, in plot, NAME ERROR
ERROR:Global:Method arguments: 
ERROR:Global:    export_image_path = C:/Users/afinney/AppData/Local/Temp/pyaedt_prj_ZED/Project_8CT.pyaedt\Maxwell_2D_KSF\Image.jpg 
ERROR:Global:Check Online documentation on: https://aedt.docs.pyansys.com/version/stable/search.html?q=plot+export_image_path

Which Operating System are you using?

Windows

Which Python version are you using?

3.8

Installed packages

aiofiles==23.1.0
aiosqlite==0.19.0
alabaster==0.7.13
ansys-api-platform-instancemanagement==1.0.0b3
ansys-dash-treeview==0.0.1.dev0
ansys-platform-instancemanagement==1.1.1
ansys-saf-glow==0.3.dev2
ansys-saf-pim-light-server==0.1.9
ansys-saf-portal==0.1.7
ansys-solutions-dash-lib==0.3.0
ansys-solutions-products-ecosystem==0.1.dev0
# Editable install with no version control (ansys-solutions-tutorial-simple-instances==0.0.1)
-e d:\ansysdev\tutorial-simple-instance
ansys-sphinx-theme==0.8.2
anyio==3.7.0
apeye==1.4.0
apeye-core==1.1.4
asgiref==3.7.2
async-generator==1.10
attrs==23.1.0
autodocsumm==0.2.11
Babel==2.12.1
backoff==2.2.1
beautifulsoup4==4.12.2
bleach==6.0.0
bottle==0.12.25
build==0.8.0
CacheControl==0.13.0
cachelib==0.9.0
cachetools==5.3.1
certifi==2023.5.7
cffi==1.15.1
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
clr-loader==0.2.5
colorama==0.4.6
coverage==6.5.0
cryptography==39.0.2
cssutils==2.6.0
dash==2.10.2
dash-bootstrap-components==1.4.1
dash-core-components==2.0.0
dash-extensions==0.1.13
dash-html-components==2.0.0
dash-iconify==0.1.2
dash-table==5.0.0
dash-uploader==0.6.0
debugpy==1.6.7
Deprecated==1.2.14
dict2css==0.3.0
distlib==0.3.6
docker==6.1.3
docutils==0.18.1
domdf-python-tools==3.6.1
EditorConfig==0.12.3
exceptiongroup==1.1.1
execnet==1.9.0
fastapi==0.95.2
filelock==3.12.0
Flask==2.2.5
Flask-Caching==2.0.2
googleapis-common-protos==1.59.0
greenlet==2.0.2
grpcio==1.47.0
grpcio-health-checking==1.24.0
h11==0.14.0
html5lib==1.1
httpcore==0.16.3
httpx==0.23.3
idna==3.4
imagesize==1.4.1
importlib-metadata==6.0.1
importlib-resources==5.12.0
iniconfig==2.0.0
itsdangerous==2.1.2
jaraco.classes==3.2.3
Jinja2==3.1.2
jsbeautifier==1.14.8
keyring==23.13.1
lockfile==0.12.2
markdown-it-py==2.2.0
MarkupSafe==2.1.3
mdurl==0.1.2
mistune==2.0.5
mock==4.0.3
more-itertools==9.1.0
msgpack==1.0.5
natsort==8.3.1
networkx==3.1
nodeenv==1.8.0
numpydoc==1.5.0
opentelemetry-api==1.17.0
opentelemetry-exporter-otlp==1.17.0
opentelemetry-exporter-otlp-proto-grpc==1.17.0
opentelemetry-exporter-otlp-proto-http==1.17.0
opentelemetry-instrumentation==0.38b0
opentelemetry-instrumentation-asgi==0.38b0
opentelemetry-instrumentation-fastapi==0.38b0
opentelemetry-instrumentation-flask==0.38b0
opentelemetry-instrumentation-httpx==0.38b0
opentelemetry-instrumentation-logging==0.38b0
opentelemetry-instrumentation-wsgi==0.38b0
opentelemetry-proto==1.17.0
opentelemetry-sdk==1.17.0
opentelemetry-semantic-conventions==0.38b0
opentelemetry-util-http==0.38b0
outcome==1.2.0
packaging==23.1
pep517==0.13.0
pep8==1.7.1
pkginfo==1.9.6
platformdirs==3.5.1
plotly==5.14.1
pluggy==1.0.0
plumbum==1.8.2
protobuf==3.20.3
protoc-gen-swagger==0.1.0
proxy-tools==0.1.0
psutil==5.9.5
pyaedt==0.6.79
pycparser==2.21
pydantic==1.10.8
pydata-sphinx-theme==0.9.0
pyflakes==3.0.1
Pygments==2.15.1
pyproject_api==1.5.1
pyright==1.1.311
pyshortcuts==1.9.0
PySocks==1.7.1
pytest==7.3.1
pytest-cache==1.0
pytest-cov==3.0.0
pytest-dependency==0.5.1
pytest-flakes==4.0.5
pytest-pep8==1.0.6
pytest-pythonpath==0.7.3
pytest-xdist==3.3.1
python-dotenv==1.0.0
python-json-logger==2.0.7
python-multipart==0.0.6
pythonnet==3.0.1
pytz==2023.3
pywebview==4.1
pywin32==306
pywin32-ctypes==0.2.0
PyYAML==6.0
readme-renderer==37.3
requests==2.31.0
requests-toolbelt==1.0.0
rfc3986==1.5.0
rich==13.4.1
rpyc==5.3.1
ruamel.yaml==0.17.31
ruamel.yaml.clib==0.2.7
selenium==4.9.1
six==1.16.0
sniffio==1.3.0
snowballstemmer==2.2.0
sortedcontainers==2.4.0
soupsieve==2.4.1
Sphinx==5.1.0
sphinx-autodoc-typehints==1.19.1
sphinx-code-tabs==0.5.3
sphinx-copybutton==0.5.2
sphinx-gallery==0.11.1
sphinx-jinja2-compat==0.2.0
sphinx-prompt==1.5.0
sphinx-tabs==3.4.1
sphinx-toolbox==3.4.0
sphinx_design==0.3.0
sphinx_mdinclude==0.5.3
sphinxcontrib-applehelp==1.0.4
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-mermaid==0.7.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
SQLAlchemy==2.0.15
starlette==0.27.0
tabulate==0.9.0
tenacity==8.2.2
toml==0.10.2
tomli==2.0.1
tox==4.6.0
trio==0.22.0
trio-websocket==0.10.2
twine==4.0.2
typing_extensions==4.6.3
urllib3==2.0.2
uvicorn==0.21.1
virtualenv==20.23.0
webencodings==0.5.1
websocket-client==1.5.2
Werkzeug==2.2.3
wrapt==1.15.0
wsproto==1.2.0
zipp==3.15.0
Samuelopez-ansys commented 8 months ago

You need to install all dependencies: pip install pyaedt[all] to install postprocessing dependencies:

README.md: https://github.com/ansys/pyaedt