Skip to content

Commit

Permalink
Merge branch 'main' into fix/avoid-error-when-retriving-routine
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Dec 10, 2024
2 parents 6fe1f69 + 27c6ec9 commit 7957545
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3608.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: avoid verbose grpc interface when solving
9 changes: 3 additions & 6 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,8 @@ def run(

command = command.strip()

is_comment = command.startswith("!") or command.upper().startswith("/COM")

# always reset the cache
self._reset_cache()

Expand Down Expand Up @@ -2261,7 +2263,7 @@ def run(
# simply return the contents of the file
return self.list(*command.split(",")[1:])

if "=" in command:
if "=" in command and not is_comment:
# We are storing a parameter.
param_name = command.split("=")[0].strip()

Expand Down Expand Up @@ -2873,11 +2875,6 @@ 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
8 changes: 8 additions & 0 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,9 @@ def _set_no_abort(self):
def _run_at_connect(self):
"""Run house-keeping commands when initially connecting to MAPDL."""
# increase the number of variables allowed in POST26 to the maximum
with self.run_as_routine("Begin level"):
self._run("/verify", mute=False)

with self.run_as_routine("POST26"):
self.numvar(200, mute=True)

Expand Down Expand Up @@ -1611,6 +1614,11 @@ def _ctrl(self, cmd: str, opt1: str = ""):
return

resp = self._stub.Ctrl(request)

if cmd.lower() == "set_verb" and str(opt1) == "0":
warn("Disabling gRPC verbose ('_ctr') by issuing also '/VERIFY' command.")
self.run("/verify")

if hasattr(resp, "response"):
return resp.response

Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ def run_before_and_after_tests(

yield # this is where the testing happens

mapdl.prep7()

# Check resetting state
assert prev == mapdl.is_local
assert not mapdl.exited, "MAPDL is exited after the test. It should have not!"
Expand Down
11 changes: 9 additions & 2 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2429,8 +2429,15 @@ def test_not_correct_et_element(mapdl, cleared):


def test_ctrl(mapdl, cleared):
mapdl._ctrl("set_verb", 5) # Setting verbosity on the server
mapdl._ctrl("set_verb", 0) # Returning to non-verbose
with patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.run") as mck_run:

mapdl._ctrl("set_verb", 5) # Setting verbosity on the server
mapdl._ctrl("set_verb", 0) # Returning to non-verbose

assert "/verify" in mck_run.call_args_list[0].args[0]

mapdl.finish()
mapdl.run("/verify") # mocking might skip running this inside mapdl._ctrl


def test_cleanup_loggers(mapdl, cleared):
Expand Down

0 comments on commit 7957545

Please sign in to comment.