-
Notifications
You must be signed in to change notification settings - Fork 4
Fixing sym
method
#196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fixing sym
method
#196
Changes from all commits
85f1cff
7d23801
5e60d64
d98a031
dd57f9a
18de61d
f5b57f4
801bbc4
edb227e
70e7608
ca0130e
3d36e65
be96664
c26114c
045a85b
ef340c6
369a530
dd646b6
136ea8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixing `sym` method |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ | |
import os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the patch looks good. A few suggestions and comments will be provided below. |
||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pytest | ||
from scipy import sparse | ||
|
||
# import time | ||
|
||
|
@@ -33,15 +35,15 @@ | |
from ansys.mapdl.core._version import SUPPORTED_ANSYS_VERSIONS | ||
from ansys.mapdl.core.errors import MapdlExitedError | ||
from ansys.mapdl.core.launcher import MAPDL_DEFAULT_PORT, get_start_instance | ||
from ansys.tools.path import find_ansys | ||
from ansys.tools.path import find_mapdl | ||
|
||
# Check if MAPDL is installed | ||
# NOTE: checks in this order to get the newest installed version | ||
|
||
|
||
valid_rver = SUPPORTED_ANSYS_VERSIONS.keys() | ||
|
||
EXEC_FILE, rver = find_ansys() | ||
EXEC_FILE, rver = find_mapdl() | ||
if rver: | ||
rver = int(rver * 10) | ||
HAS_GRPC = int(rver) >= 211 or ON_CI | ||
|
@@ -79,8 +81,8 @@ | |
{os_msg} | ||
|
||
If you do have Ansys installed, you may have to patch pymapdl to | ||
automatically find your Ansys installation. Email the developer at: | ||
alexander.kaszynski@ansys.com | ||
automatically find your Ansys installation. Email the developers at: | ||
pyansys.core@ansys.com | ||
clatapie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
""" | ||
|
||
|
@@ -174,3 +176,23 @@ def cube_solve(cleared, mapdl): | |
|
||
# solve first 10 non-trivial modes | ||
out = mapdl.modal_analysis(nmode=10, freqb=1) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def sparse_asym_mat(): | ||
return sparse.random(5000, 5000, density=0.05, format="csr") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider setting a random seed for reproducibility before generating the sparse random matrix. |
||
|
||
|
||
@pytest.fixture(scope="function") | ||
def sparse_sym_mat(sparse_asym_mat): | ||
return sparse_asym_mat + (sparse_asym_mat.T) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def dense_asym_mat(): | ||
return np.random.rand(1000, 1000) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def dense_sym_mat(dense_asym_mat): | ||
return dense_asym_mat + (dense_asym_mat.T) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -204,19 +204,35 @@ def test_shape(mm): | |||||
assert m1.shape == shape | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace the current assert message with a more informative one:
Suggested change
|
||||||
def test_matrix(mm): | ||||||
sz = 5000 | ||||||
mat = sparse.random(sz, sz, density=0.05, format="csr") | ||||||
assert mat.data.nbytes // 1024**2 > 4, "Must test over gRPC message limit" | ||||||
@pytest.mark.parametrize("sparse_mat", ["sparse_asym_mat", "sparse_sym_mat"]) | ||||||
def test_sparse_matrix(mm, sparse_mat, request): | ||||||
sparse_mat = request.getfixturevalue(sparse_mat) | ||||||
assert sparse_mat.data.nbytes // 1024**2 > 4, "Must test over gRPC message limit" | ||||||
|
||||||
name = "TMP_MATRIX" | ||||||
ans_mat = mm.matrix(mat, name) | ||||||
ans_mat = mm.matrix(sparse_mat, name) | ||||||
assert ans_mat.id == name | ||||||
|
||||||
mat_back = ans_mat.asarray() | ||||||
assert np.allclose(mat.data, mat_back.data) | ||||||
assert np.allclose(mat.indices, mat_back.indices) | ||||||
assert np.allclose(mat.indptr, mat_back.indptr) | ||||||
assert np.allclose(sparse_mat.data, mat_back.data) | ||||||
assert np.allclose(sparse_mat.indices, mat_back.indices) | ||||||
assert np.allclose(sparse_mat.indptr, mat_back.indptr) | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize("dense_mat", ["dense_asym_mat", "dense_sym_mat"]) | ||||||
def test_dense_matrix(mm, dense_mat, request): | ||||||
mapdl_version = mm._mapdl.version | ||||||
if mapdl_version < 21.2: | ||||||
pytest.skip("Requires MAPDL 2021 R2 or later.") | ||||||
|
||||||
dense_mat = request.getfixturevalue(dense_mat) | ||||||
|
||||||
name = "TMP_MATRIX" | ||||||
ans_mat = mm.matrix(dense_mat, name) | ||||||
assert ans_mat.id == name | ||||||
clatapie marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
mat_back = ans_mat.asarray() | ||||||
assert np.allclose(dense_mat, mat_back) | ||||||
|
||||||
|
||||||
def test_matrix_fail(mm): | ||||||
|
@@ -742,6 +758,22 @@ def test_invalid_sparse_name(mm): | |||||
mm.matrix(mat, name=1) | ||||||
|
||||||
|
||||||
def test_sym_dmat(mm, dense_sym_mat): | ||||||
dmat = mm.matrix(dense_sym_mat) | ||||||
if not server_meets_version(mm._server_version, (0, 5, 0)): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice addition of tests for symmetric dense and sparse matrices. It helps check if the server version meets the requirements. Please make the suggested changes to the assert messages for better readability and submit the patch for review again. |
||||||
assert dmat.sym() is False | ||||||
else: | ||||||
assert dmat.sym() is True | ||||||
|
||||||
|
||||||
def test_sym_smat(mm, sparse_sym_mat): | ||||||
smat = mm.matrix(sparse_sym_mat) | ||||||
if not server_meets_version(mm._server_version, (0, 5, 0)): | ||||||
assert smat.sym() is False | ||||||
else: | ||||||
assert smat.sym() is True | ||||||
|
||||||
|
||||||
def test_free_all(mm): | ||||||
my_mat1 = mm.ones(10) | ||||||
my_mat2 = mm.ones(10) | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.