Skip to content

Commit

Permalink
Merge branch 'feat/rpc-rpyc' of https://github.com/ansys/pymechanical
Browse files Browse the repository at this point in the history
…into feat/rpc-rpyc
  • Loading branch information
dipinknair committed Jan 24, 2025
2 parents 04679b9 + 989b3e9 commit 1fdbf6c
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repos:
args: ["--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt", "-w"]

- repo: https://github.com/ansys/pre-commit-hooks
rev: v0.4.4
rev: v0.5.1
hooks:
- id: add-license-headers
args:
Expand Down
26 changes: 17 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,23 @@ on Windows and Linux for version 2023 R2 and later. Here is an example:
app.update_globals(globals())
project_dir = DataModel.Project.ProjectDirectory
Documentation and issues
------------------------
How to report issues
--------------------

If you encounter any issues or limitations with PyMechanical that hinder your work, please create
an issue or discussion so our team can address them promptly:

* `PyMechanical Issues <https://github.com/ansys/pymechanical/issues>`_: Report bugs and request new features.
* `PyMechanical Discussions <https://github.com/ansys/pymechanical/discussions>`_: Post questions, share ideas, and get community feedback.

For issues pertaining to `Mechanical scripting <https://mechanical.docs.pyansys.com/version/stable/user_guide_scripting/index.html>`_,
please make a post on the `Developer Portal <https://forum.ansys.com/categories/structures>`_.

If you have general questions about PyAnsys or are unsure which repository to place an issue in,
email `[email protected] <[email protected]>`_.

Documentation resources
-----------------------

Documentation for the latest stable release of PyMechanical is hosted at `PyMechanical documentation
<https://mechanical.docs.pyansys.com/>`_.
Expand All @@ -139,13 +154,6 @@ You can also `view <https://cheatsheets.docs.pyansys.com/pymechanical_cheat_shee
PyMechanical cheat sheet. This one-page reference provides syntax rules and commands
for using PyMechanical.

On the `PyMechanical Issues <https://github.com/ansys/pymechanical/issues>`_ page,
you can create issues to report bugs and request new features. On the `PyMechanical Discussions
<https://github.com/ansys/pymechanical/discussions>`_ page or the `Discussions <https://discuss.ansys.com/>`_
page on the Ansys Developer portal, you can post questions, share ideas, and get community feedback.

To reach the project support team, email `[email protected] <[email protected]>`_.

Testing and development
-----------------------

Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1054.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump the doc group with 4 updates
1 change: 1 addition & 0 deletions doc/changelog.d/1056.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre-commit automatic update
1 change: 1 addition & 0 deletions doc/changelog.d/1060.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create option for PyPIM to be installed separately
1 change: 1 addition & 0 deletions doc/changelog.d/1061.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify support guidelines
17 changes: 12 additions & 5 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# necessary when building the sphinx gallery
pymechanical.BUILDING_GALLERY = True

# Whether or not to build the cheatsheet
BUILD_CHEATSHEET = True

# suppress annoying matplotlib bug
warnings.filterwarnings(
"ignore",
Expand Down Expand Up @@ -57,10 +60,12 @@
"sphinx_autodoc_typehints",
"sphinx_copybutton",
"sphinx_design",
"sphinx_gallery.gen_gallery",
"sphinxemoji.sphinxemoji",
]

if pymechanical.BUILDING_GALLERY:
extensions.append("sphinx_gallery.gen_gallery")

# Intersphinx mapping
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
Expand Down Expand Up @@ -207,14 +212,16 @@
"icon": "fa fa-comment fa-fw",
},
],
"cheatsheet": {
"file": "cheatsheet/cheat_sheet.qmd",
"title": "PyMechanical cheat sheet",
},
"ansys_sphinx_theme_autoapi": {"project": project, "templates": "_templates/autoapi"},
"navigation_depth": 10,
}

if BUILD_CHEATSHEET:
html_theme_options["cheatsheet"] = {
"file": "cheatsheet/cheat_sheet.qmd",
"title": "PyMechanical cheat sheet",
}

# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
Expand Down
92 changes: 49 additions & 43 deletions doc/source/kil/index.rst
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
.. _ref_known_issues_and_limitation:

Known issues and limitations
============================

Note the following known issues and limitations. Some features may not be fully compatible across different versions of **Mechanical** and **PyMechanical**.
Ansys recommends that you always use the latest version of both to achieve the best results.

..
This toctree must be a top-level index to get it to show up in
pydata_sphinx_theme.
.. toctree::
:maxdepth: 2
:hidden:


mechanical
pymechanical

.. grid:: 2
:gutter: 2 2 3 4

.. grid-item-card:: :fas:`fa-solid fa-gears` Mechanical
:link: mechanical
:link-type: doc

Known issues and limitations of Standalone Mechanical

.. grid-item-card:: :fab:`fa-brands fa-python` PyMechanical
:link: pymechanical
:link-type: doc

Known issues and limitations of PyMechanical

Support
=======

If you encounter any issues or limitations that hinder your work, please contact our support team immediately.
We are committed to providing timely assistance to ensure your projects run smoothly.

- Mechanical : `Discussion forum <https://discuss.ansys.com/categories/structures>`_
- PyMechanical : Create issue in github or contact `pyansys team <pyansys_support_>`_
.. _ref_known_issues_and_limitation:

Known issues and limitations
============================

Note the following known issues and limitations. Some features may not be fully compatible across different versions of **Mechanical** and **PyMechanical**.
Ansys recommends that you always use the latest version of both to achieve the best results.

..
This toctree must be a top-level index to get it to show up in
pydata_sphinx_theme.
.. toctree::
:maxdepth: 2
:hidden:


mechanical
pymechanical

.. grid:: 2
:gutter: 2 2 3 4

.. grid-item-card:: :fas:`fa-solid fa-gears` Mechanical
:link: mechanical
:link-type: doc

Known issues and limitations of Standalone Mechanical

.. grid-item-card:: :fab:`fa-brands fa-python` PyMechanical
:link: pymechanical
:link-type: doc

Known issues and limitations of PyMechanical

Support
=======

If you encounter any issues or limitations with PyMechanical that hinder your work, please create
an issue or discussion so our team can address them promptly:

Check warning on line 40 in doc/source/kil/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/kil/index.rst#L40

[Google.We] Try to avoid using first-person plural like 'our'.
Raw output
{"message": "[Google.We] Try to avoid using first-person plural like 'our'.", "location": {"path": "doc/source/kil/index.rst", "range": {"start": {"line": 40, "column": 27}}}, "severity": "WARNING"}

* `PyMechanical Issues <https://github.com/ansys/pymechanical/issues>`_: Report bugs and request new features.
* `PyMechanical Discussions <https://github.com/ansys/pymechanical/discussions>`_: Post questions, share ideas, and get community feedback.

For issues pertaining to `Mechanical scripting <https://mechanical.docs.pyansys.com/version/stable/user_guide_scripting/index.html>`_,
please make a post on the `Ansys Developer Forum for Mechanical <https://discuss.ansys.com/categories/structures>`_.

If you have general questions about PyAnsys or are unsure which repository to place an issue in,
email `[email protected] <[email protected]>`_.
22 changes: 12 additions & 10 deletions doc/source/user_guide_scripting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ You could already perform scripting of Mechanical with Python from inside
Mechanical. PyMechanical leverages the same APIs but allows you to run your
automation from outside Mechanical.

.. note::
For comprehensive information on these APIs, refer to the following documentation:

For comprehensive information on these APIs, see the `Scripting in Mechanical Guide`_ in the
Ansys Help portal, the `Mechanical scripting interface APIs`_ in the Developer Portal, or the
`Mechanical API Documentation`_.
PyMechanical documentation:

* `Mechanical API Documentation`_ - Lists Mechanical APIs that can be used with PyMechanical.

Developer portal:

* `Mechanical scripting interface APIs`_ - Contains the same information as the `Mechanical API Documentation`_ but is located on the developer portal.

ACT API Reference Guide:

* `ACT API Reference Guide`_ - Provides descriptions of the objects, methods, and properties for all namespaces.

Recording
---------
Expand Down Expand Up @@ -89,9 +97,3 @@ When running scripts inside of Mechanical, you can access the APIs via these ent

You also have access to several types and namespaces that are included in the scripting scope but are not available
from those entry points.

Additional resources
--------------------

The `ACT API Reference Guide`_
provides descriptions of the objects, methods, and properties for all namespaces.
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies = [
"ansys-api-mechanical==0.1.2",
"ansys-mechanical-env==0.1.9",
"ansys-mechanical-stubs==0.1.6",
"ansys-platform-instancemanagement>=1.0.1",
"ansys-pythonnet>=3.1.0rc2",
"ansys-tools-path>=0.3.1",
"appdirs>=1.4.0",
Expand Down Expand Up @@ -60,12 +59,12 @@ doc = [
"sphinx==8.1.3",
"ansys-sphinx-theme[autoapi]==1.2.6",
"grpcio==1.69.0",
"imageio-ffmpeg==0.5.1",
"imageio==2.36.1",
"imageio-ffmpeg==0.6.0",
"imageio==2.37.0",
"jupyter_sphinx==0.5.3",
"jupyterlab>=3.2.8",
"matplotlib==3.10.0",
"numpy==2.2.1",
"numpy==2.2.2",
"numpydoc==1.8.0",
"pandas==2.2.3",
"panel==1.5.5",
Expand All @@ -75,7 +74,7 @@ doc = [
"pythreejs==2.4.2",
"pyvista>=0.39.1",
"sphinx-autobuild==2024.10.3",
"sphinx-autodoc-typehints==3.0.0",
"sphinx-autodoc-typehints==3.0.1",
"sphinx-copybutton==0.5.2",
"sphinx_design==0.6.1",
"sphinx-gallery==0.18.0",
Expand All @@ -91,6 +90,9 @@ rpc = [
"rpyc==6.0.1",
"toolz==1.0.0",
]
pim = [
"ansys-platform-instancemanagement>=1.0.1",
]

[project.scripts]
ansys-mechanical = "ansys.mechanical.core.run:cli"
Expand Down
29 changes: 24 additions & 5 deletions src/ansys/mechanical/core/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import socket
import threading
import time
from typing import Optional
import warnings
import weakref

import ansys.api.mechanical.v0.mechanical_pb2 as mechanical_pb2
import ansys.api.mechanical.v0.mechanical_pb2_grpc as mechanical_pb2_grpc
import ansys.platform.instancemanagement as pypim
from ansys.platform.instancemanagement import Instance
import ansys.tools.path as atp
import grpc

Expand All @@ -57,6 +57,16 @@
threaded,
)

# Check if PyPIM is installed
try:
import ansys.platform.instancemanagement as pypim # pragma: nocover noqa: F401

_HAS_ANSYS_PIM = True
"""Whether or not PyPIM exists."""
except ImportError:
_HAS_ANSYS_PIM = False


# Checking if tqdm is installed.
# If it is, the default value for progress_bar is true.
try:
Expand Down Expand Up @@ -1932,7 +1942,9 @@ def launch_grpc(
return port


def launch_remote_mechanical(version=None) -> (grpc.Channel, Instance): # pragma: no cover
def launch_remote_mechanical(
version=None,
) -> (grpc.Channel, Optional["Instance"]): # pragma: no cover
"""Start Mechanical remotely using the Product Instance Management (PIM) API.
When calling this method, you must ensure that you are in an environment
Expand All @@ -1951,6 +1963,13 @@ def launch_remote_mechanical(version=None) -> (grpc.Channel, Instance): # pragm
-------
Tuple containing channel, remote_instance.
"""
# Display warning if PyPIM is not installed
if not _HAS_ANSYS_PIM:
warnings.warn(
"Installation of pim option required! Use ``pip install ansys-mechanical-core[pim]``."
)
return

pim = pypim.connect()
instance = pim.create_instance(product_name="mechanical", product_version=version)

Expand Down Expand Up @@ -2062,7 +2081,7 @@ def launch_mechanical(
version : str, optional
Mechanical version to run in the three-digit format. For example, ``"251"``
for 2025 R1. The default is ``None``, in which case the server runs the
latest installed version. If PyPIM is configured and ``exce_file=None``,
latest installed version. If PyPIM is configured and ``exec_file=None``,
PyPIM launches Mechanical using its ``version`` parameter.
keep_connection_alive : bool, optional
Whether to keep the gRPC connection alive by running a background thread
Expand Down Expand Up @@ -2099,7 +2118,7 @@ def launch_mechanical(
"""
# Start Mechanical with PyPIM if the environment is configured for it
# and a directive on how to launch Mechanical was not passed.
if pypim.is_configured() and exec_file is None: # pragma: no cover
if _HAS_ANSYS_PIM and pypim.is_configured() and exec_file is None: # pragma: no cover
LOG.info("Starting Mechanical remotely. The startup configuration will be ignored.")
channel, remote_instance = launch_remote_mechanical(version=version)
return Mechanical(
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import time
import warnings

import ansys.platform.instancemanagement as pypim
from ansys.tools.path import version_from_path

from ansys.mechanical.core.errors import VersionError
from ansys.mechanical.core.mechanical import (
_HAS_ANSYS_PIM,
_HAS_TQDM,
LOG,
MECHANICAL_DEFAULT_PORT,
Expand Down Expand Up @@ -175,7 +175,7 @@ def __init__(
if "exec_file" in kwargs:
exec_file = kwargs["exec_file"]
else:
if pypim.is_configured(): # pragma: no cover
if _HAS_ANSYS_PIM and pypim.is_configured(): # pragma: no cover
if "version" in kwargs:
version = kwargs["version"]
self._remote = True
Expand Down

0 comments on commit 1fdbf6c

Please sign in to comment.