From 27c6ec9605cce7e105f779d5c94950bcf7bc3df8 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:01:33 +0100 Subject: [PATCH] fix: avoid verbose grpc interface when solving (#3608) * fix: avoid gRPC logging when solving. * fix: remove all calls to set_verb. * feat: running verify at connect * fix: detecting comments as parameters sets when they have =. * chore: adding changelog file 3608.fixed.md [dependabot-skip] * chore: adding changelog file 3608.fixed.md [dependabot-skip] * feat: making sure we are running /verify in no routine. * feat: running /verify if using 'mapdl._ctr('set_verb',0)' * tests: adding test for checking we are using /verify * tests: making sure the /verify is executed properly after finish --------- Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> --- doc/changelog.d/3608.fixed.md | 1 + src/ansys/mapdl/core/mapdl_core.py | 9 +++------ src/ansys/mapdl/core/mapdl_grpc.py | 8 ++++++++ tests/conftest.py | 2 ++ tests/test_mapdl.py | 11 +++++++++-- 5 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 doc/changelog.d/3608.fixed.md diff --git a/doc/changelog.d/3608.fixed.md b/doc/changelog.d/3608.fixed.md new file mode 100644 index 0000000000..46f20d76a2 --- /dev/null +++ b/doc/changelog.d/3608.fixed.md @@ -0,0 +1 @@ +fix: avoid verbose grpc interface when solving \ No newline at end of file diff --git a/src/ansys/mapdl/core/mapdl_core.py b/src/ansys/mapdl/core/mapdl_core.py index ad21da82f5..b04700bb0a 100644 --- a/src/ansys/mapdl/core/mapdl_core.py +++ b/src/ansys/mapdl/core/mapdl_core.py @@ -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() @@ -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() @@ -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) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index a15982ce12..0ebd1618c3 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -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) @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 724929fa6d..157472057d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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!" diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index 2c2634a401..ed2d611c0b 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -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):