Skip to content
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

Implementing unique session id #1912

Merged
merged 62 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
54b4372
First implementation of session_id
germa89 Mar 13, 2023
2ebdb90
Raising warning if lenght of string is GT 32 chars
germa89 Mar 13, 2023
fabd762
Merge branch 'fix/raise-warning-if-string-is-longer-than-32-chars' in…
germa89 Mar 13, 2023
704d962
Moving everything to the gRPC interface
germa89 Mar 13, 2023
9214dae
Adding unit tests
germa89 Mar 13, 2023
e50725f
Updating CICD
germa89 Mar 13, 2023
50ba295
Activating flag.
germa89 Mar 13, 2023
0658467
Fixing docstring
germa89 Mar 13, 2023
65e05c4
Merge branch 'fix/raise-warning-if-string-is-longer-than-32-chars' in…
germa89 Mar 13, 2023
047c136
Avoiding muting
germa89 Mar 13, 2023
c2d5f3f
Merge branch 'main' into feat/unique_session_id
germa89 Mar 13, 2023
7d6a26d
Fixing CI tests
germa89 Mar 13, 2023
7cb6e29
fixing wref attribute
germa89 Mar 13, 2023
82c0130
fixing call
germa89 Mar 13, 2023
0a291c2
Disabling muting
germa89 Mar 13, 2023
16d771f
Avoiding muting
germa89 Mar 13, 2023
742e2f8
Avoiding muting when connecting to a session
germa89 Mar 13, 2023
373f3bc
Using env vars for the pytest arguments.
germa89 Mar 14, 2023
71e0d3a
Forcing output
germa89 Mar 14, 2023
393879a
Using force output for getting mapdl session id.
germa89 Mar 14, 2023
4070222
Merge branch 'main' into feat/unique_session_id
germa89 Mar 14, 2023
d73262c
Avoiding recursion error
germa89 Mar 14, 2023
e6287b5
Avoid force_output
germa89 Mar 14, 2023
89f713b
Fixing test
germa89 Mar 14, 2023
8f5879f
Fixing wrong order of error catching
germa89 Mar 14, 2023
2e727c1
Getting read of an error
germa89 Mar 14, 2023
2ba46f9
Fixing raising many errors at test
germa89 Mar 14, 2023
19f2c7a
fixing double raises
germa89 Mar 14, 2023
9665723
Merge branch 'main' into feat/unique_session_id
germa89 Mar 14, 2023
c314b4f
Removing comments
germa89 Mar 14, 2023
507cca5
Renaming variables to avoid privates.
germa89 Mar 14, 2023
064ab28
Merge branch 'main' into feat/unique_session_id
germa89 Mar 14, 2023
ae02445
adding check id to startget
germa89 Mar 14, 2023
2924b37
Merge branch 'main' into feat/unique_session_id
germa89 Apr 24, 2023
86654be
Merge branch 'main' into feat/unique_session_id
akaszynski Apr 24, 2023
2f0adec
Apply suggestions from code review
akaszynski Apr 24, 2023
20898e5
Merge branch 'main' into feat/unique_session_id
germa89 Apr 25, 2023
a5f2a37
fixing typo
germa89 Apr 25, 2023
8407ad8
Merge branch 'main' into feat/unique_session_id
akaszynski Apr 25, 2023
21a9262
Merge branch 'main' into feat/unique_session_id
germa89 May 3, 2023
14dc0ff
Merge branch 'main' into feat/unique_session_id
germa89 May 5, 2023
bf823b0
Merge branch 'main' into feat/unique_session_id
germa89 May 5, 2023
a85a06c
Merge branch 'main' into feat/unique_session_id
germa89 Jun 16, 2023
d6dd597
Merge branch 'main' into feat/unique_session_id
germa89 Jun 22, 2023
2320f27
Merge branch 'main' into feat/unique_session_id
germa89 Jul 3, 2023
d22c334
Removing outdated arg
germa89 Jul 3, 2023
aaacd49
Replacing `_RUNNING_TESTS` by `RUNNING_TESTS`
germa89 Jul 3, 2023
85333b7
fixing not creating session id after failed example
germa89 Jul 3, 2023
f51869d
Force recreating session when using clean.
germa89 Jul 3, 2023
db7fec1
test
germa89 Jul 3, 2023
e6df5cd
Undoing ci pytest configuration changes
germa89 Jul 4, 2023
91909ea
Update tests/conftest.py
germa89 Jul 4, 2023
a16effe
fixing missing import
germa89 Jul 4, 2023
d3f3f08
Improving `running_test` context manager.
germa89 Jul 4, 2023
952f4ea
Merge branch 'feat/unique_session_id' of https://github.com/pyansys/p…
germa89 Jul 4, 2023
a40c226
Merge branch 'main' into feat/unique_session_id
germa89 Jul 4, 2023
ce4dbd0
fixing bracket test
germa89 Jul 5, 2023
d9e9e46
Merge branch 'main' into feat/unique_session_id
germa89 Jul 12, 2023
fadef4f
Bypassing error
germa89 Jul 14, 2023
8481df1
Adding more static typing
germa89 Jul 14, 2023
7277c2a
fixing tests
germa89 Jul 14, 2023
734c1fa
Merge branch 'main' into feat/unique_session_id
germa89 Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/ansys/mapdl/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
LOG = Logger(level=logging.ERROR, to_file=False, to_stdout=True)
LOG.debug("Loaded logging module as LOG")


BUILDING_GALLERY = False
RUNNING_TESTS = False

if RUNNING_TESTS: # pragma: no cover
LOG.debug("Running tests on Pytest")

_LOCAL_PORTS = []


Expand Down Expand Up @@ -64,9 +71,6 @@

_HAS_ANSYS = _check_has_ansys()

BUILDING_GALLERY = False
RUNNING_TESTS = False

VERSION_MAP = {
(0, 0, 0): "2020R2",
(0, 3, 0): "2021R1",
Expand Down
7 changes: 7 additions & 0 deletions src/ansys/mapdl/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def __init__(self, msg=""):
MapdlRuntimeError.__init__(self, msg)


class DifferentSessionConnectionError(RuntimeError):
"""Provides the error when connecting to the MAPDL instance fails."""

def __init__(self, msg=""):
RuntimeError.__init__(self, msg)


# handler for protect_grpc
def handler(sig, frame): # pragma: no cover
"""Pass signal to custom interrupt handler."""
Expand Down
69 changes: 44 additions & 25 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
MapdlRuntimeError,
)
from ansys.mapdl.core.inline_functions import Query
from ansys.mapdl.core.mapdl_types import KwargDict, MapdlFloat
from ansys.mapdl.core.misc import (
Information,
allow_pickable_points,
Expand Down Expand Up @@ -837,6 +838,8 @@ def clear(self, *args, **kwargs):
>>> mapdl.clear()

"""
if self.is_grpc:
self._create_session()
self.run("/CLE,NOSTART", mute=True)

@supress_logging
Expand Down Expand Up @@ -2247,7 +2250,7 @@ def _distributed_result_file(self):
elif os.path.isfile(rst_file):
return rst_file

def _get(self, *args, **kwargs):
def _get(self, *args, **kwargs) -> MapdlFloat:
"""Simply use the default get method"""
return self.get(*args, **kwargs)

Expand Down Expand Up @@ -2341,15 +2344,15 @@ def get_value(
entity: str = "",
entnum: str = "",
item1: str = "",
it1num: Union[str, int, float] = "",
it1num: MapdlFloat = "",
item2: str = "",
it2num: Union[str, int, float] = "",
item3: Union[str, int, float] = "",
it3num: Union[str, int, float] = "",
item4: Union[str, int, float] = "",
it4num: Union[str, int, float] = "",
**kwargs: Dict[Any, Any],
):
it2num: MapdlFloat = "",
item3: MapdlFloat = "",
it3num: MapdlFloat = "",
item4: MapdlFloat = "",
it4num: MapdlFloat = "",
**kwargs: KwargDict,
) -> Union[float, str]:
"""Runs the MAPDL GET command and returns a Python value.

This method uses :func:`Mapdl.get`.
Expand Down Expand Up @@ -2449,14 +2452,14 @@ def get(
entity: str = "",
entnum: str = "",
item1: str = "",
it1num: Union[str, int, float] = "",
it1num: MapdlFloat = "",
item2: str = "",
it2num: Union[str, int, float] = "",
item3: Union[str, int, float] = "",
it3num: Union[str, int, float] = "",
item4: Union[str, int, float] = "",
it4num: Union[str, int, float] = "",
**kwargs: Dict[Any, Any],
it2num: MapdlFloat = "",
item3: MapdlFloat = "",
it3num: MapdlFloat = "",
item4: MapdlFloat = "",
it4num: MapdlFloat = "",
**kwargs: KwargDict,
) -> Union[float, str]:
"""Retrieves a value and stores it as a scalar parameter or part of an array parameter.

Expand Down Expand Up @@ -2980,6 +2983,13 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
>>> mapdl.prep7()

"""
if self._session_id is not None:
self._check_session_id()
else:
# For some reason the session hasn't been created
if self.is_grpc:
self._create_session()

if mute is None:
if hasattr(self, "mute"):
mute = self.mute
Expand Down Expand Up @@ -3052,6 +3062,10 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
verbose = kwargs.get("verbose", False)
text = self._run(command, verbose=verbose, mute=mute)

if command[:4].upper() == "/CLE" and self.is_grpc:
# We have reset the database, so we need to create a new session id
self._create_session()

if mute:
return

Expand Down Expand Up @@ -3426,12 +3440,12 @@ def get_array(
entity: str = "",
entnum: str = "",
item1: str = "",
it1num: Union[str, int, float] = "",
it1num: MapdlFloat = "",
item2: str = "",
it2num: Union[str, int, float] = "",
kloop: Union[str, int, float] = "",
**kwargs: Dict[Any, Any],
) -> NDArray:
it2num: MapdlFloat = "",
kloop: MapdlFloat = "",
**kwargs: KwargDict,
) -> NDArray[np.float64]:
"""Uses the ``*VGET`` command to Return an array from ANSYS as a
Python array.

Expand Down Expand Up @@ -3513,13 +3527,13 @@ def _get_array(
entity: str = "",
entnum: str = "",
item1: str = "",
it1num: Union[str, int, float] = "",
it1num: MapdlFloat = "",
item2: str = "",
it2num: Union[str, int, float] = "",
kloop: Union[str, int, float] = "",
it2num: MapdlFloat = "",
kloop: MapdlFloat = "",
dtype: DTypeLike = None,
**kwargs,
) -> NDArray:
) -> NDArray[np.float64]:
"""Uses the VGET command to get an array from ANSYS"""
parm_name = kwargs.pop("parm", None)

Expand Down Expand Up @@ -4198,6 +4212,11 @@ def _raise_output_errors(self, response):
[each for each in error_message.splitlines() if each]
)

# Trimming empty lines
error_message = "\n".join(
[each for each in error_message.splitlines() if each]
)

# Checking for permitted error.
for each_error in _PERMITTED_ERRORS:
permited_error_message = re.search(each_error, error_message)
Expand Down
Loading