From c0908709c849e53806fd4b8359e828e0302c7c30 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 22 Mar 2023 10:09:09 +0100 Subject: [PATCH 01/10] Bump to version 0.2.dev0 (#72) --- .github/workflows/ci_cd.yml | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 0536a6e0..2582a638 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -337,14 +337,14 @@ jobs: release: - name: "Release project to private PyPI and GitHub" + name: "Release project to public PyPI and GitHub" if: github.event_name == 'push' && contains(github.ref, 'refs/tags') needs: [package] runs-on: ubuntu-latest steps: - name: "Release to the public PyPI repository" - uses: pyansys/actions/release-pypi-public@v3 + uses: pyansys/actions/release-pypi-public@v4 with: library-name: ${{ env.PACKAGE_NAME }} twine-username: "__token__" diff --git a/pyproject.toml b/pyproject.toml index 6502142d..303c9cae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi" [project] # Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections name = "ansys-math-core" -version = "0.1.dev0" +version = "0.2.dev0" description = "A Python wrapper for PyAnsys Math libraries." readme = "README.rst" requires-python = ">=3.7" From 652543a83af2fe640f968b3015cf42848bdf13c0 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 22 Mar 2023 10:28:49 +0100 Subject: [PATCH 02/10] Update README.rst --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 8a5907e5..279dc692 100644 --- a/README.rst +++ b/README.rst @@ -1,16 +1,13 @@ PyAnsys Math ============ -|pyansys| |pypi| |PyPIact| |GH-CI| |codecov| |MIT| |black| +|pyansys| |pypi| |GH-CI| |codecov| |MIT| |black| .. |pyansys| image:: https://img.shields.io/badge/Py-Ansys-ffc107.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABDklEQVQ4jWNgoDfg5mD8vE7q/3bpVyskbW0sMRUwofHD7Dh5OBkZGBgW7/3W2tZpa2tLQEOyOzeEsfumlK2tbVpaGj4N6jIs1lpsDAwMJ278sveMY2BgCA0NFRISwqkhyQ1q/Nyd3zg4OBgYGNjZ2ePi4rB5loGBhZnhxTLJ/9ulv26Q4uVk1NXV/f///////69du4Zdg78lx//t0v+3S88rFISInD59GqIH2esIJ8G9O2/XVwhjzpw5EAam1xkkBJn/bJX+v1365hxxuCAfH9+3b9/+////48cPuNehNsS7cDEzMTAwMMzb+Q2u4dOnT2vWrMHu9ZtzxP9vl/69RVpCkBlZ3N7enoDXBwEAAA+YYitOilMVAAAAAElFTkSuQmCC :target: https://docs.pyansys.com/ :alt: PyAnsys -.. |pypi| image:: https://img.shields.io/pypi/v/pyansys-math-core.svg?logo=python&logoColor=white - :target: https://pypi.org/project/ansys-math-core/ - -.. |PyPIact| image:: https://img.shields.io/pypi/dm/pyansys-math-core.svg?label=PyPI%20downloads +.. |pypi| image:: https://img.shields.io/pypi/v/ansys-math-core.svg?logo=python&logoColor=white :target: https://pypi.org/project/ansys-math-core/ .. |codecov| image:: https://codecov.io/gh/pyansys/pyansys-math/branch/main/graph/badge.svg From cf41a879f8de05fa5cd84909333dde9c458b1415 Mon Sep 17 00:00:00 2001 From: Kathy Pippert <84872299+PipKat@users.noreply.github.com> Date: Thu, 23 Mar 2023 03:16:14 -0400 Subject: [PATCH 03/10] Update index.rst for Contribute topic (#74) --- doc/source/contributing/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/contributing/index.rst b/doc/source/contributing/index.rst index 18fd8218..e5f21b77 100644 --- a/doc/source/contributing/index.rst +++ b/doc/source/contributing/index.rst @@ -32,7 +32,7 @@ templates: If your issue does not fit into one of these categories, create your own issue. -To reach the PyAnsys support team, email `pyansys.support@ansys.com `_. +To reach the PyAnsys support team, email `pyansys.core@ansys.com `_. Build documentation From e02384f1cd694bc642883ede02162269a3f50d18 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 23 Mar 2023 09:52:47 +0100 Subject: [PATCH 04/10] Fixing plots in the documentation (#76) Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- examples/scipy_sparse_matrix.py | 3 +-- examples/solve_dense_matrix.py | 3 ++- examples/solve_sparse_matrix.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/scipy_sparse_matrix.py b/examples/scipy_sparse_matrix.py index eb34c5c7..cba3ce77 100644 --- a/examples/scipy_sparse_matrix.py +++ b/examples/scipy_sparse_matrix.py @@ -27,7 +27,6 @@ out = mm._mapdl.input(vmfiles["vm153"]) k = mm.stiff(fname="PRSMEMB.full") -k ################################################################################ # Copy AnsMath sparse matrix to SciPy CSR matrix and plot @@ -36,7 +35,7 @@ # graph of the sparse matrix. pk = k.asarray() -plt.spy(pk, color="orange") +plt.spy(pk, color="orange", markersize=3) plt.title("AnsMath sparse matrix") plt.show() diff --git a/examples/solve_dense_matrix.py b/examples/solve_dense_matrix.py index 63ff56c2..30cac1d1 100644 --- a/examples/solve_dense_matrix.py +++ b/examples/solve_dense_matrix.py @@ -78,12 +78,13 @@ # Plot the elapsed times for PyAnsys Math and Numpy to solve the dense # matrix linear system. # +max_time = max(pymath_time, numpy_time) fig = plt.figure(figsize=(12, 10)) ax = plt.axes() x = ["PyAnsys Math", "NumPy"] y = [pymath_time, numpy_time] plt.title("Elapsed time to solve the linear system") -plt.ylim([0, numpy_time + 1]) +plt.ylim([0, max_time + 0.2 * max_time]) plt.ylabel("Elapsed time (s)") ax.bar(x, y, color="orange") plt.show() diff --git a/examples/solve_sparse_matrix.py b/examples/solve_sparse_matrix.py index 99aaac40..996aca61 100644 --- a/examples/solve_sparse_matrix.py +++ b/examples/solve_sparse_matrix.py @@ -57,7 +57,7 @@ # graph of the sparse matrix. pk = k.asarray() -plt.spy(pk, color="orange") +plt.spy(pk, color="orange", markersize=3) plt.title("AnsMath sparse matrix") plt.show() From c73e915c501622db8da0ad03e5225493e9a5c12d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 16:00:38 +0200 Subject: [PATCH 05/10] Bump pandas from 1.5.3 to 2.0.0 (#78) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 303c9cae..9e91e74e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ doc = [ "jupyter_sphinx==0.4.0", "jupyterlab==3.6.2", "numpydoc==1.5.0", - "pandas==1.5.3", + "pandas==2.0.0", "pypandoc==1.11", "pytest-sphinx==0.5.0", "pyvista==0.38.5", From 7c926993aab95f7f7126094371ebe5a0be215a0a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 16:58:44 +0200 Subject: [PATCH 06/10] Bump jupyterlab from 3.6.2 to 3.6.3 (#79) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Camille <78221213+clatapie@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9e91e74e..2215b130 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ doc = [ "ansys-mapdl-reader==0.52.11", "ansys-sphinx-theme==0.9.5", "jupyter_sphinx==0.4.0", - "jupyterlab==3.6.2", + "jupyterlab==3.6.3", "numpydoc==1.5.0", "pandas==2.0.0", "pypandoc==1.11", From 1f4baa8a5b3222a2e2a8eda90b7343b8f2cb7d30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:06:20 +0000 Subject: [PATCH 07/10] Bump ansys-sphinx-theme from 0.9.5 to 0.9.6 (#80) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Camille <78221213+clatapie@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2215b130..b3e7e245 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ doc = [ "Sphinx==5.3.0", "ansys-mapdl-core==0.64.0", "ansys-mapdl-reader==0.52.11", - "ansys-sphinx-theme==0.9.5", + "ansys-sphinx-theme==0.9.6", "jupyter_sphinx==0.4.0", "jupyterlab==3.6.3", "numpydoc==1.5.0", From 5c2cdc8947a2101b37b49696a2c58246c15f6520 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Apr 2023 10:04:59 +0200 Subject: [PATCH 08/10] Bump ansys-sphinx-theme from 0.9.6 to 0.9.7 (#82) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b3e7e245..44e5c683 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ doc = [ "Sphinx==5.3.0", "ansys-mapdl-core==0.64.0", "ansys-mapdl-reader==0.52.11", - "ansys-sphinx-theme==0.9.6", + "ansys-sphinx-theme==0.9.7", "jupyter_sphinx==0.4.0", "jupyterlab==3.6.3", "numpydoc==1.5.0", From 46388f0e5667c81a0b173352e1bb49fb28ec8355 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 Apr 2023 08:16:19 +0000 Subject: [PATCH 09/10] Bump peter-evans/create-or-update-comment from 2 to 3 (#81) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Camille <78221213+clatapie@users.noreply.github.com> --- .github/workflows/label.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 4b01e417..715fffb5 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -72,7 +72,7 @@ jobs: needs: labeler steps: - name: Suggest to add labels - uses: peter-evans/create-or-update-comment@v2 + uses: peter-evans/create-or-update-comment@v3 # Execute only when no labels have been applied to the pull request if: toJSON(github.event.pull_request.labels.*.name) == '{}' with: From 8e4c7a4d93d554923f72e3e4b0719a2b455c355b Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 12 Apr 2023 11:24:47 +0200 Subject: [PATCH 10/10] Aligning documentation with the other PyAnsys repositories (#77) Co-authored-by: German <28149841+germa89@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> --- README.rst | 7 +++- doc/source/{api_ref => api}/index.rst | 0 doc/source/{api_ref => api}/math.rst | 0 doc/source/index.rst | 11 +++--- doc/source/user_guide/arrays.rst | 50 +++++++++++++++++++++++++++ doc/source/user_guide/index.rst | 31 +++++++++++++++++ src/ansys/math/core/math.py | 32 ++++++++++++----- 7 files changed, 118 insertions(+), 13 deletions(-) rename doc/source/{api_ref => api}/index.rst (100%) rename doc/source/{api_ref => api}/math.rst (100%) create mode 100644 doc/source/user_guide/arrays.rst create mode 100644 doc/source/user_guide/index.rst diff --git a/README.rst b/README.rst index 279dc692..c1d71cc5 100644 --- a/README.rst +++ b/README.rst @@ -40,6 +40,11 @@ For users The ``ansys.math.core`` package currently supports Python 3.7 through Python 3.10 on Windows, Mac OS, and Linux. +.. warning:: + + ``ansys.math.core`` will no longer support Python 3.7 by June 2023. + + Install the latest package for use with this command: .. code:: @@ -77,7 +82,7 @@ Verify your installation Check that you can start PyAnsys Math from Python by running this code: -.. code:: python +.. code:: python3 import ansys.math.core.math as pymath diff --git a/doc/source/api_ref/index.rst b/doc/source/api/index.rst similarity index 100% rename from doc/source/api_ref/index.rst rename to doc/source/api/index.rst diff --git a/doc/source/api_ref/math.rst b/doc/source/api/math.rst similarity index 100% rename from doc/source/api_ref/math.rst rename to doc/source/api/math.rst diff --git a/doc/source/index.rst b/doc/source/index.rst index 6b3eddec..5ed73a67 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -33,7 +33,7 @@ the NumPy and SciPy linear algebra solvers and the PyAnsys Math solver: +--------------------------------------------+-----------------------------------+ | NumPy and SciPy | PyAnsys Math | +============================================+===================================+ - | .. code:: python | .. code:: python | + | .. code:: python3 | .. code:: python3 | | | | | k_py = k + sparse.triu(k, 1).T | k = mm.matrix(k_py, triu=True) | | m_py = m + sparse.triu(m, 1).T | m = mm.matrix(m_py, triu=True) | @@ -63,7 +63,7 @@ Quick code Here is a brief example of how you use PyAnsys Math: -.. code:: python +.. code:: python3 import ansys.math.core.math as pymath @@ -75,7 +75,9 @@ Here is a brief example of how you use PyAnsys Math: print(w) -.. code:: output +.. rst-class:: sphx-glr-script-out + + .. code-block:: none UDWZKD : Size : 5 @@ -90,6 +92,7 @@ For comprehensive PyAnsys Math examples, see :ref:`ref_pymath_examples`. :maxdepth: 1 getting_started/index - api_ref/index + user_guide/index + api/index examples/index contributing/index diff --git a/doc/source/user_guide/arrays.rst b/doc/source/user_guide/arrays.rst new file mode 100644 index 00000000..a57b120b --- /dev/null +++ b/doc/source/user_guide/arrays.rst @@ -0,0 +1,50 @@ + +Handling arrays between PyAnsys Math and Python +=============================================== + + +Sending arrays to PyAnsys Math +------------------------------ + +.. code:: python3 + + import numpy as np + import ansys.math.core.math as pymath + + # Start PyAnsys Math as a service. + mm = pymath.AnsMath() + + a = np.random.random((2, 3)) + a_pymath = mm.matrix(a, name="A") + + print(a_pymath) + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + A: + [1,1]: 4.018e-01 [1,2]: 4.635e-01 [1,3]: 3.682e-01 + [2,1]: 9.711e-01 [2,2]: 7.601e-02 [2,3]: 8.833e-01 + + + +Transfer a PyAnsys Math matrix to NumPy +--------------------------------------- + +.. code:: python3 + + a_python = a_pymath.asarray() + print((a == a_python).all()) + + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + True + + + + + diff --git a/doc/source/user_guide/index.rst b/doc/source/user_guide/index.rst new file mode 100644 index 00000000..12341342 --- /dev/null +++ b/doc/source/user_guide/index.rst @@ -0,0 +1,31 @@ +.. _ref_user_guide: + +User guide +========== + +Overview +-------- + +You can use the ``AnsMath()`` method to launch an instance of PyAnsys Math. + +.. code:: python3 + + import ansys.math.core.math as pymath + + # Start PyAnsys Math. + mm = pymath.AnsMath() + print(mm) + +.. rst-class:: sphx-glr-script-out + + .. code-block:: none + + APDLMATH PARAMETER STATUS- ( 0 PARAMETERS DEFINED) + + Name Type Mem. (MB) Dims Workspace + +.. toctree:: + :hidden: + :maxdepth: 1 + + arrays.rst \ No newline at end of file diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 98b34861..71c624ca 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -1494,8 +1494,20 @@ def dot(self, vec) -> float: self._mapdl.run(f"*DOT,{self.id},{vec.id},py_val") return self._mapdl.scalar_param("py_val") - def asarray(self) -> np.ndarray: - """Return this vector as a NumPy array. + def asarray(self, dtype=None) -> np.ndarray: + """Return the vector as a NumPy array. + + Parameters + ---------- + dtype : numpy.dtype, optional + NumPy data type to upload the array as. The options are `np.double `_, + `np.int32 `_, and `np.int64 `_. The default is the current array + type. + + Returns + ------- + np.ndarray + NumPy array with the defined data type. Examples -------- @@ -1504,8 +1516,12 @@ def asarray(self) -> np.ndarray: >>> v = mm.ones(10) >>> v.asarray() [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] + >>> v.asarray(dtype=np.int32) + [1 1 1 1 1 1 1 1 1 1] + """ - return self._mapdl._vec_data(self.id) + vec_data = self._mapdl._vec_data(self.id) + return vec_data.astype(dtype) if dtype else vec_data def __array__(self): """Allow NumPy to access this object as if it was an array.""" @@ -1567,7 +1583,7 @@ def sym(self) -> bool: return True def asarray(self, dtype=None) -> np.ndarray: - """Return the vector as a NumPy array. + """Return the matrix as a NumPy array. Parameters ---------- @@ -1585,11 +1601,11 @@ def asarray(self, dtype=None) -> np.ndarray: -------- >>> import ansys.math.core.math as pymath >>> mm = pymath.AnsMath() - >>> v = mm.ones(10) + >>> v = mm.ones(2,2) >>> v.asarray() - [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] - >>> v.asarray(dtype=np.int) - [1 1 1 1 1 1 1 1 1 1] + array([[1., 1.], [1., 1.]]) + >>> v.asarray(dtype=np.int32) + array([[1, 1], [1, 1]]) """ if dtype: