From 820c71953b9f77eae39a4fcdcba5ae14dc8141a7 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 7 Jun 2023 12:35:54 +0200 Subject: [PATCH 01/27] Fixing `mat` and `vec` --- src/ansys/math/core/math.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 71c624ca..4cf6b1a8 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -165,7 +165,7 @@ def status(self): """ print(self._status) - def vec(self, size=0, dtype=np.double, init="zeros", name=None, asarray=False): + def vec(self, size=0, dtype=np.double, init=None, name=None, asarray=False): """Create a vector. Parameters @@ -209,7 +209,7 @@ def vec(self, size=0, dtype=np.double, init="zeros", name=None, asarray=False): return vec - def mat(self, nrow=1, ncol=1, dtype=np.double, init="zeros", name=None, asarray=False): + def mat(self, nrow=1, ncol=1, dtype=np.double, init=None, name=None, asarray=False): """Create a matrix. Parameters From 8792bb572685ce4b0ca7014b8f43476db3635145 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 7 Jun 2023 12:56:06 +0200 Subject: [PATCH 02/27] Fixing `vec` --- src/ansys/math/core/math.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 4cf6b1a8..16918d74 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -252,7 +252,9 @@ def mat(self, nrow=1, ncol=1, dtype=np.double, init=None, name=None, asarray=Fal mat.rand() elif init == "ones": mat.ones() - elif init != "zeros": + elif init == "zeros": + mat.zeros() + elif init is not None: raise ValueError(f"Invalid initialization method '{init}'.") else: info = self._mapdl._data_info(name) From c4fe512fdb8881ae49292d848552719061bd8022 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:08:17 +0200 Subject: [PATCH 03/27] Fixing `PRSMEMB.full` issue --- examples/eigen_solve.py | 6 +++--- examples/scipy_sparse_matrix.py | 3 ++- examples/solve_sparse_matrix.py | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/eigen_solve.py b/examples/eigen_solve.py index 201b7ec0..5ff38bda 100644 --- a/examples/eigen_solve.py +++ b/examples/eigen_solve.py @@ -31,9 +31,9 @@ # get the stiff (``k``) and mass (``m``) matrices from the FULL file. out = mm._mapdl.input(vmfiles["vm153"]) - -k = mm.stiff(fname="PRSMEMB.full") -m = mm.mass(fname="PRSMEMB.full") +fullfile = mm._mapdl.jobname + ".full" +k = mm.stiff(fname=fullfile) +m = mm.mass(fname=fullfile) ############################################################################### diff --git a/examples/scipy_sparse_matrix.py b/examples/scipy_sparse_matrix.py index cba3ce77..df7f0d7e 100644 --- a/examples/scipy_sparse_matrix.py +++ b/examples/scipy_sparse_matrix.py @@ -26,7 +26,8 @@ # get the stiff (``k``) matrix from the FULL file. out = mm._mapdl.input(vmfiles["vm153"]) -k = mm.stiff(fname="PRSMEMB.full") +fullfile = mm._mapdl.jobname + ".full" +k = mm.stiff(fname=fullfile) ################################################################################ # Copy AnsMath sparse matrix to SciPy CSR matrix and plot diff --git a/examples/solve_sparse_matrix.py b/examples/solve_sparse_matrix.py index 996aca61..97100aed 100644 --- a/examples/solve_sparse_matrix.py +++ b/examples/solve_sparse_matrix.py @@ -27,7 +27,7 @@ # After a solve command, the ``FULL`` file contains the assembled stiffness # matrix, mass matrix, and load vector. # -out = mm._mapdl.input(vmfiles["vm153"]) +out = mm._mapdl.input(vmfiles["vm152"]) ############################################################################### # List files in current directory @@ -47,7 +47,8 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Print the dimensions of the sparse matrix. -k = mm.stiff(fname="PRSMEMB.full", name="K") +fullfile = mm._mapdl.jobname + ".full" +k = mm.stiff(fname=fullfile, name="K") k ################################################################################ @@ -74,8 +75,7 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Extract the load vector from the FULL file and print the norm of this # vector. - -b = mm.rhs(fname="PRSMEMB.full", name="B") +b = mm.rhs(fname=fullfile, name="B") b.norm() ############################################################################### From cba410ac05b282e4ab0879afa164ecb218b2fdca Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:44:14 +0200 Subject: [PATCH 04/27] Updating `conf.py` --- doc/source/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 863cfbec..e6d4272a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -120,9 +120,9 @@ # Intersphinx mapping intersphinx_mapping = { - "python": ("https://docs.python.org/dev", None), - "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), - "numpy": ("https://numpy.org/devdocs", None), + "python": ("https://docs.python.org/3", None), + "scipy": ("https://docs.scipy.org/doc/scipy/", None), + "numpy": ("https://numpy.org/doc/stable/", None), # kept here as an example # "matplotlib": ("https://matplotlib.org/stable", None), # "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), From c16fea756b0239d72f16cdb04696998cd52e1ade Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Wed, 7 Jun 2023 17:31:04 +0200 Subject: [PATCH 05/27] Adding unit tests for `vec` and `mat` functions --- src/ansys/math/core/math.py | 2 +- tests/test_math.py | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 16918d74..fa08ecc4 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -252,7 +252,7 @@ def mat(self, nrow=1, ncol=1, dtype=np.double, init=None, name=None, asarray=Fal mat.rand() elif init == "ones": mat.ones() - elif init == "zeros": + elif init == "zeros" or init is None: mat.zeros() elif init is not None: raise ValueError(f"Invalid initialization method '{init}'.") diff --git a/tests/test_math.py b/tests/test_math.py index fbeb8323..42ffcf95 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -107,13 +107,11 @@ def test_vec(mm): assert isinstance(arr, np.ndarray) -def test_vec_from_name(mm): - vec0 = mm.vec(10) +@pytest.mark.parametrize("vecval", [np.zeros(10), np.array([1.0, 2.0, 8.0, 5.0, 6.2]), np.ones(3)]) +def test_vec_from_name(mm, vecval): + vec0 = mm.set_vec(vecval) vec1 = mm.vec(name=vec0.id) - assert np.allclose(vec0, vec1) - - vec1 = mm.vec(name=vec0.id, asarray=True) - assert isinstance(vec1, np.ndarray) + assert np.allclose(vecval, vec1.asarray()) def test_vec__mul__(mm): @@ -348,6 +346,20 @@ def test_mat_from_name_sparse(mm): assert np.allclose(mat0, mat1) +@pytest.mark.parametrize( + "matval", + [ + np.zeros((5, 5)), + np.array([[1.0, 2.0, 8.0, 5.0, 6.2], [5.1, 3.8, 8.2, 4.5, 2.0]]), + np.ones((3, 4)), + ], +) +def test_mat_from_name_sparse(mm, matval): + mat0 = mm.matrix(matval) + mat1 = mm.mat(name=mat0.id) + assert np.allclose(matval, mat1.asarray()) + + def test_mat_invalid_dtype(mm): with pytest.raises(ValueError): mm.mat(10, 10, dtype=np.uint8) From 4943055d706968bc95240f4634e1d29fa4d63313 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:10:47 +0200 Subject: [PATCH 06/27] Updating a module import --- src/ansys/math/core/math.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index fa08ecc4..05e0408d 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -13,12 +13,11 @@ DEFAULT_CHUNKSIZE, DEFAULT_FILE_CHUNK_SIZE, ) -from ansys.mapdl.core.errors import ANSYSDataTypeError, protect_grpc +from ansys.mapdl.core.errors import ANSYSDataTypeError, protect_grpc, VersionError from ansys.mapdl.core.launcher import launch_mapdl from ansys.mapdl.core.misc import load_file from ansys.mapdl.core.parameters import interp_star_status from ansys.tools.versioning import requires_version -from ansys.tools.versioning.exceptions import VersionError from ansys.tools.versioning.utils import server_meets_version import numpy as np From f6a30423a77425295e5842eb1aad9253c8243ecd Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:16:21 +0200 Subject: [PATCH 07/27] Code spell checks --- src/ansys/math/core/math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 05e0408d..14ce600d 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -13,7 +13,7 @@ DEFAULT_CHUNKSIZE, DEFAULT_FILE_CHUNK_SIZE, ) -from ansys.mapdl.core.errors import ANSYSDataTypeError, protect_grpc, VersionError +from ansys.mapdl.core.errors import ANSYSDataTypeError, VersionError, protect_grpc from ansys.mapdl.core.launcher import launch_mapdl from ansys.mapdl.core.misc import load_file from ansys.mapdl.core.parameters import interp_star_status From d819e158146850ed5cc21d7c1d29819e467e322b Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:58:12 +0200 Subject: [PATCH 08/27] Fixing import in unit tests --- tests/test_math.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_math.py b/tests/test_math.py index 42ffcf95..ce182650 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -2,10 +2,9 @@ import os import re -from ansys.mapdl.core.errors import ANSYSDataTypeError +from ansys.mapdl.core.errors import ANSYSDataTypeError, VersionError from ansys.mapdl.core.launcher import get_start_instance from ansys.mapdl.core.misc import random_string -from ansys.tools.versioning.exceptions import VersionError from ansys.tools.versioning.utils import server_meets_version import numpy as np import pytest From 1d52cb7f1ef341977d1617447a5aff38a58c77fa Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:04:39 +0200 Subject: [PATCH 09/27] Fixing intersphinx mapping --- doc/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index e6d4272a..a68dfce0 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -120,7 +120,7 @@ # Intersphinx mapping intersphinx_mapping = { - "python": ("https://docs.python.org/3", None), + "python": ("https://docs.python.org/3/", None), "scipy": ("https://docs.scipy.org/doc/scipy/", None), "numpy": ("https://numpy.org/doc/stable/", None), # kept here as an example From 02af4c261b65114db7e6560fa04097b284aaec77 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:16:32 +0200 Subject: [PATCH 10/27] Adding extensions --- doc/source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index a68dfce0..3f3976d6 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -85,10 +85,12 @@ extensions = [ "jupyter_sphinx", "notfound.extension", # for the not found page. + "numpydoc", "sphinx.ext.autodoc", "sphinx.ext.autosummary", - "numpydoc", "sphinx.ext.coverage", + "sphinx.ext.extlinks", + "sphinx.ext.linkcode", "sphinx.ext.intersphinx", "sphinx_copybutton", "sphinx_gallery.gen_gallery", From 4f0c3cc3157de55151393f748c5e2a40d11c5cff Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:27:07 +0200 Subject: [PATCH 11/27] Updating links --- doc/source/links.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/links.rst b/doc/source/links.rst index 2a2df9ac..3d4cb5c2 100644 --- a/doc/source/links.rst +++ b/doc/source/links.rst @@ -15,7 +15,7 @@ .. _grpc: https://grpc.io/ .. _numpy_docs: https://numpy.org/doc/stable/ .. _precommit: https://pre-commit.com/ -.. _scipy_docs: https://docs.scipy.org/doc/scipy/reference/ +.. _scipy_docs: https://docs.scipy.org/doc/scipy/ .. #Other projects .. _dpf_post_docs: https://post.docs.pyansys.com/ From 0f44e37f32e752ae0288919b032f38586108ed5e Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:36:54 +0200 Subject: [PATCH 12/27] Calling `VERSION_MAP` --- src/ansys/math/core/math.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 14ce600d..dd70e2a6 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -13,6 +13,7 @@ DEFAULT_CHUNKSIZE, DEFAULT_FILE_CHUNK_SIZE, ) +from ansys.mapdl.core import VERSION_MAP from ansys.mapdl.core.errors import ANSYSDataTypeError, VersionError, protect_grpc from ansys.mapdl.core.launcher import launch_mapdl from ansys.mapdl.core.misc import load_file @@ -1172,7 +1173,7 @@ def _set_mat(self, mname, arr, sym=False, dtype=None, chunk_size=DEFAULT_CHUNKSI else: # must be dense matrix self._send_dense(mname, arr, dtype, chunk_size) - @requires_version((0, 4, 0)) + @requires_version((0, 4, 0), VERSION_MAP) def _send_dense(self, mname, arr, dtype, chunk_size): """Send a dense NumPy array/matrix to MAPDL.""" if dtype is not None: From d0a35e703c52c941a54921ea372afa1e2d139b06 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:51:40 +0200 Subject: [PATCH 13/27] Code style checks --- src/ansys/math/core/math.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index dd70e2a6..94231016 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -8,14 +8,18 @@ from ansys.api.mapdl.v0 import ansys_kernel_pb2 as anskernel from ansys.api.mapdl.v0 import mapdl_pb2 as pb_types +from ansys.mapdl.core import VERSION_MAP, launch_mapdl from ansys.mapdl.core.common_grpc import ( ANSYS_VALUE_TYPE, DEFAULT_CHUNKSIZE, DEFAULT_FILE_CHUNK_SIZE, ) -from ansys.mapdl.core import VERSION_MAP -from ansys.mapdl.core.errors import ANSYSDataTypeError, VersionError, protect_grpc -from ansys.mapdl.core.launcher import launch_mapdl +from ansys.mapdl.core.errors import ( + ANSYSDataTypeError, + MapdlRuntimeError, + VersionError, + protect_grpc, +) from ansys.mapdl.core.misc import load_file from ansys.mapdl.core.parameters import interp_star_status from ansys.tools.versioning import requires_version @@ -1419,10 +1423,10 @@ def __init__(self, id_, mapdl, dtype=np.double, init=None): @property def size(self): - """Number of items in the vector.""" + """Number of items in this vector.""" sz = self._mapdl.scalar_param(f"{self.id}_DIM") if sz is None: - raise RuntimeError("This vector has been deleted within MAPDL.") + raise MapdlRuntimeError("This vector has been deleted within MAPDL.") return int(sz) def __repr__(self): From ecd736131869186116444ce0509fdd8deba3a833 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:13:32 +0200 Subject: [PATCH 14/27] Fixing `_server_version` calls --- tests/test_math.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_math.py b/tests/test_math.py index ce182650..26ea0d24 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -698,7 +698,7 @@ def test_factorize_inplace_arg(mm): def test_mult(mapdl, mm): rand_ = np.random.rand(100, 100) - if not server_meets_version(mapdl._server_version, (0, 4, 0)): + if not mm._server_version[1] >= 4: with pytest.raises(VersionError): AA = mm.matrix(rand_, name="AA") @@ -719,7 +719,7 @@ def test__parm(mm): mat = sparse.random(sz, sz, density=0.05, format="csr") rand_ = np.random.rand(100, 100) - if not server_meets_version(mm._mapdl._server_version, (0, 4, 0)): + if not mm._server_version[1] >= 4: with pytest.raises(VersionError): AA = mm.matrix(rand_, name="AA") From 43bf7d994e160708d0149bd438fc09d75e2d64a1 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:18:19 +0200 Subject: [PATCH 15/27] Code style checks --- tests/test_math.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_math.py b/tests/test_math.py index 26ea0d24..22fe369d 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -5,7 +5,6 @@ from ansys.mapdl.core.errors import ANSYSDataTypeError, VersionError from ansys.mapdl.core.launcher import get_start_instance from ansys.mapdl.core.misc import random_string -from ansys.tools.versioning.utils import server_meets_version import numpy as np import pytest from scipy import sparse From 9cb109cee04012a26f0217e6c74ef414b3ee6683 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:32:09 +0200 Subject: [PATCH 16/27] Upgrading `server_version` requirements --- tests/test_math.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/test_math.py b/tests/test_math.py index 22fe369d..212a9d59 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -323,27 +323,12 @@ def test_load_matrix_from_file_incorrect_name(mm, cube_solve): with pytest.raises(TypeError, match=r"``name`` parameter must be a string"): mm.load_matrix_from_file(name=1245) - -def test_mat_from_name(mm): - mat0 = mm.mat(10, 10, init="ones") # The test has to be done with a - # value other than the default one. - mat1 = mm.mat(name=mat0.id) - assert np.allclose(mat0, mat1) - - def test_mat_asarray(mm): mat0 = mm.mat(10, 10, asarray=True) mat1 = mm.mat(10, 10) assert np.allclose(mat0, mat1.asarray()) -def test_mat_from_name_sparse(mm): - scipy_mat = sparse.random(5, 5, density=1, format="csr") - mat0 = mm.matrix(scipy_mat) - mat1 = mm.mat(name=mat0.id) - assert np.allclose(mat0, mat1) - - @pytest.mark.parametrize( "matval", [ @@ -352,12 +337,26 @@ def test_mat_from_name_sparse(mm): np.ones((3, 4)), ], ) -def test_mat_from_name_sparse(mm, matval): +def test_mat_array_from_name(mm, matval): mat0 = mm.matrix(matval) mat1 = mm.mat(name=mat0.id) assert np.allclose(matval, mat1.asarray()) +def test_mat_mapdl_from_name(mm): + mat0 = mm.mat(10, 10, init="ones") # The test has to be done with a + # value other than the default one. + mat1 = mm.mat(name=mat0.id) + assert np.allclose(mat0, mat1) + + +def test_mat_from_name_sparse(mm): + scipy_mat = sparse.random(5, 5, density=1, format="csr") + mat0 = mm.matrix(scipy_mat) + mat1 = mm.mat(name=mat0.id) + assert np.allclose(mat0, mat1) + + def test_mat_invalid_dtype(mm): with pytest.raises(ValueError): mm.mat(10, 10, dtype=np.uint8) @@ -697,7 +696,7 @@ def test_factorize_inplace_arg(mm): def test_mult(mapdl, mm): rand_ = np.random.rand(100, 100) - if not mm._server_version[1] >= 4: + if not mm._server_version[1] > 4: with pytest.raises(VersionError): AA = mm.matrix(rand_, name="AA") @@ -718,7 +717,7 @@ def test__parm(mm): mat = sparse.random(sz, sz, density=0.05, format="csr") rand_ = np.random.rand(100, 100) - if not mm._server_version[1] >= 4: + if not mm._server_version[1] > 4: with pytest.raises(VersionError): AA = mm.matrix(rand_, name="AA") From 5b988b1f9f92b3c8197a83dd11e9a536950f4b2d Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:33:59 +0200 Subject: [PATCH 17/27] code styles --- tests/test_math.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_math.py b/tests/test_math.py index 212a9d59..813d9909 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -323,6 +323,7 @@ def test_load_matrix_from_file_incorrect_name(mm, cube_solve): with pytest.raises(TypeError, match=r"``name`` parameter must be a string"): mm.load_matrix_from_file(name=1245) + def test_mat_asarray(mm): mat0 = mm.mat(10, 10, asarray=True) mat1 = mm.mat(10, 10) From 0f83a4a4b2f64a5f672b344b7b9f23927921307b Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 15:30:08 +0200 Subject: [PATCH 18/27] Fixing unit tests --- src/ansys/math/core/math.py | 2 +- tests/test_math.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 94231016..78b2f3f2 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -1457,7 +1457,7 @@ def __mul__(self, vec): Hadamard product between this vector and the other vector. """ if not server_meets_version(self._mapdl._server_version, (0, 4, 0)): # pragma: no cover - raise VersionError("``AnsVec`` requires MAPDL version 2021 R2 or later.") + raise VersionError("``AnsVec`` requires MAPDL version 2021R2") if not isinstance(vec, AnsVec): raise TypeError("The object to be multiplied must be an AnsMath vector.") diff --git a/tests/test_math.py b/tests/test_math.py index 813d9909..02b098bb 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -2,9 +2,11 @@ import os import re -from ansys.mapdl.core.errors import ANSYSDataTypeError, VersionError +from ansys.mapdl.core.errors import ANSYSDataTypeError from ansys.mapdl.core.launcher import get_start_instance from ansys.mapdl.core.misc import random_string +from ansys.tools.versioning.exceptions import VersionError +from ansys.tools.versioning.utils import server_meets_version import numpy as np import pytest from scipy import sparse @@ -697,7 +699,7 @@ def test_factorize_inplace_arg(mm): def test_mult(mapdl, mm): rand_ = np.random.rand(100, 100) - if not mm._server_version[1] > 4: + if not server_meets_version(mm._server_version, (0, 4, 0)): with pytest.raises(VersionError): AA = mm.matrix(rand_, name="AA") @@ -718,7 +720,7 @@ def test__parm(mm): mat = sparse.random(sz, sz, density=0.05, format="csr") rand_ = np.random.rand(100, 100) - if not mm._server_version[1] > 4: + if not server_meets_version(mm._server_version, (0, 4, 0)): with pytest.raises(VersionError): AA = mm.matrix(rand_, name="AA") From 1454ef0bbd3aa7961f0a5cde9ca8e458ca4ee271 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 15:55:35 +0200 Subject: [PATCH 19/27] Fixing unit tests --- tests/test_math.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/test_math.py b/tests/test_math.py index 02b098bb..9de45358 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -2,7 +2,7 @@ import os import re -from ansys.mapdl.core.errors import ANSYSDataTypeError +from ansys.mapdl.core.errors import ANSYSDataTypeError, MapdlRuntimeError from ansys.mapdl.core.launcher import get_start_instance from ansys.mapdl.core.misc import random_string from ansys.tools.versioning.exceptions import VersionError @@ -332,6 +332,13 @@ def test_mat_asarray(mm): assert np.allclose(mat0, mat1.asarray()) +def test_mat_from_name_mapdl(mm): + mat0 = mm.mat(10, 10, init="ones") # The test has to be done with a + # value other than the default one. + mat1 = mm.mat(name=mat0.id) + assert np.allclose(mat0, mat1) + + @pytest.mark.parametrize( "matval", [ @@ -340,17 +347,14 @@ def test_mat_asarray(mm): np.ones((3, 4)), ], ) -def test_mat_array_from_name(mm, matval): - mat0 = mm.matrix(matval) - mat1 = mm.mat(name=mat0.id) - assert np.allclose(matval, mat1.asarray()) - - -def test_mat_mapdl_from_name(mm): - mat0 = mm.mat(10, 10, init="ones") # The test has to be done with a - # value other than the default one. - mat1 = mm.mat(name=mat0.id) - assert np.allclose(mat0, mat1) +def test_mat_from_name_dense(mm, matval): + if not server_meets_version(mm._server_version, (0, 4, 0)): + with pytest.raises(VersionError): + mat0 = mm.matrix(matval) + else: + mat0 = mm.matrix(matval) + mat1 = mm.mat(name=mat0.id) + assert np.allclose(matval, mat1.asarray()) def test_mat_from_name_sparse(mm): @@ -633,7 +637,7 @@ def test_invalid_sparse_name(mm): def test_free(mm): my_mat = mm.ones(10) mm.free() - with pytest.raises(RuntimeError, match="This vector has been deleted"): + with pytest.raises(MapdlRuntimeError, match="This vector has been deleted"): my_mat.size From 4c8e77de54065a2ddd7bc650a29d76c8440d8fdc Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:02:09 +0200 Subject: [PATCH 20/27] Trying to fix doc issue --- doc/source/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 3f3976d6..43a9b3b2 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -122,9 +122,9 @@ # Intersphinx mapping intersphinx_mapping = { - "python": ("https://docs.python.org/3/", None), - "scipy": ("https://docs.scipy.org/doc/scipy/", None), - "numpy": ("https://numpy.org/doc/stable/", None), + "python": ("https://docs.python.org/3", None), + "scipy": ("https://docs.scipy.org/doc/scipy", None), + "numpy": ("https://numpy.org/doc/stable", None), # kept here as an example # "matplotlib": ("https://matplotlib.org/stable", None), # "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), From 3726f8328cd6892318b5a9bbb8be57a2ba36a846 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:13:19 +0200 Subject: [PATCH 21/27] Trying to fix doc --- doc/source/conf.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 43a9b3b2..948f954d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -125,11 +125,6 @@ "python": ("https://docs.python.org/3", None), "scipy": ("https://docs.scipy.org/doc/scipy", None), "numpy": ("https://numpy.org/doc/stable", None), - # kept here as an example - # "matplotlib": ("https://matplotlib.org/stable", None), - # "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), - # "pyvista": ("https://docs.pyvista.org/", None), - # "grpc": ("https://grpc.github.io/grpc/python/", None), } suppress_warnings = ["label.*"] From 24d69f4fb2c6bd7e630337d9b9a3279e3fa89824 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:28:29 +0200 Subject: [PATCH 22/27] Fixing doc --- doc/source/conf.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 948f954d..cfc9fddd 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -89,8 +89,6 @@ "sphinx.ext.autodoc", "sphinx.ext.autosummary", "sphinx.ext.coverage", - "sphinx.ext.extlinks", - "sphinx.ext.linkcode", "sphinx.ext.intersphinx", "sphinx_copybutton", "sphinx_gallery.gen_gallery", From ee3773edf245ab73eecd5af4d8cd284f72e76f65 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:36:59 +0200 Subject: [PATCH 23/27] Trying to localize the error --- doc/source/conf.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index cfc9fddd..a36ee318 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -118,12 +118,12 @@ "thumbnail_size": (350, 350), } -# Intersphinx mapping -intersphinx_mapping = { - "python": ("https://docs.python.org/3", None), - "scipy": ("https://docs.scipy.org/doc/scipy", None), - "numpy": ("https://numpy.org/doc/stable", None), -} +# # Intersphinx mapping +# intersphinx_mapping = { +# "python": ("https://docs.python.org/3", None), +# "scipy": ("https://docs.scipy.org/doc/scipy", None), +# "numpy": ("https://numpy.org/doc/stable", None), +# } suppress_warnings = ["label.*"] # numpydoc configuration From ac896bca5bd0476d7917457ee79475f22439c3b2 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:47:12 +0200 Subject: [PATCH 24/27] Trying to fix intersphinx --- doc/source/conf.py | 12 ++++++------ pyproject.toml | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index a36ee318..cfc9fddd 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -118,12 +118,12 @@ "thumbnail_size": (350, 350), } -# # Intersphinx mapping -# intersphinx_mapping = { -# "python": ("https://docs.python.org/3", None), -# "scipy": ("https://docs.scipy.org/doc/scipy", None), -# "numpy": ("https://numpy.org/doc/stable", None), -# } +# Intersphinx mapping +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), + "scipy": ("https://docs.scipy.org/doc/scipy", None), + "numpy": ("https://numpy.org/doc/stable", None), +} suppress_warnings = ["label.*"] # numpydoc configuration diff --git a/pyproject.toml b/pyproject.toml index 39f2b059..f8d37a5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dependencies = [ "pyansys-tools-versioning>=0.3.3", "numpy>=1.14.0", "importlib-metadata>=4.0,<5; python_version<='3.8'", + "scipy>=1.3.0", # for sparse (consider optional?) ] [project.optional-dependencies] From 3dabd7a13a231f4526dccfc141e2064857717144 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:11:28 +0200 Subject: [PATCH 25/27] Removing changes in `conf.py` --- doc/source/conf.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index cfc9fddd..d5059426 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -120,9 +120,14 @@ # Intersphinx mapping intersphinx_mapping = { - "python": ("https://docs.python.org/3", None), - "scipy": ("https://docs.scipy.org/doc/scipy", None), - "numpy": ("https://numpy.org/doc/stable", None), + "python": ("https://docs.python.org/dev", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), + "numpy": ("https://numpy.org/devdocs", None), + # kept here as an example + # "matplotlib": ("https://matplotlib.org/stable", None), + # "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), + # "pyvista": ("https://docs.pyvista.org/", None), + # "grpc": ("https://grpc.github.io/grpc/python/", None), } suppress_warnings = ["label.*"] From f7ec02533eab841b9e3c09112fd8a62c24fa0ec5 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:37:08 +0200 Subject: [PATCH 26/27] Changes from German's review --- src/ansys/math/core/math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/math/core/math.py b/src/ansys/math/core/math.py index 78b2f3f2..94231016 100644 --- a/src/ansys/math/core/math.py +++ b/src/ansys/math/core/math.py @@ -1457,7 +1457,7 @@ def __mul__(self, vec): Hadamard product between this vector and the other vector. """ if not server_meets_version(self._mapdl._server_version, (0, 4, 0)): # pragma: no cover - raise VersionError("``AnsVec`` requires MAPDL version 2021R2") + raise VersionError("``AnsVec`` requires MAPDL version 2021 R2 or later.") if not isinstance(vec, AnsVec): raise TypeError("The object to be multiplied must be an AnsMath vector.") From 65e3fcc04f2990e906fe32b87d5c6cfcd4a60539 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:44:03 +0200 Subject: [PATCH 27/27] Modifying tool.coverage.run source --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f8d37a5e..d17640c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,7 +85,7 @@ default_section = "THIRDPARTY" src_paths = ["doc", "src", "tests"] [tool.coverage.run] -source = ["src"] +source = ["ansys/pyansys-math"] [tool.coverage.report] show_missing = true