From 99e07068996a8bc012feb8432d84f6e21c3c0311 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:35:07 +0100 Subject: [PATCH 01/10] fix: avoid gRPC logging when solving. --- src/ansys/mapdl/core/mapdl_extended.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ansys/mapdl/core/mapdl_extended.py b/src/ansys/mapdl/core/mapdl_extended.py index a12ba23392..b8d2c1a569 100644 --- a/src/ansys/mapdl/core/mapdl_extended.py +++ b/src/ansys/mapdl/core/mapdl_extended.py @@ -2123,6 +2123,15 @@ def cmlist(self, *args, **kwargs): return ComponentListing(super().cmlist(*args, **kwargs)) + @wraps(_MapdlCore.solve) + def solve(self, action="", **kwargs): + self._ctrl("set_verb", 0) + if hasattr(self, "logger") and self.logger is not None: + self.logger.debug("Disabling gRPC logging when solving") + + # TODO: Implement a get verbose option on server side + return super().solve(action=action, **kwargs) + class _MapdlExtended(_MapdlCommandExtended): """Extend Mapdl class with new functions""" From f6d968f13e94d119b06fd82d47bfa560b76165ae Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:06:20 +0100 Subject: [PATCH 02/10] fix: remove all calls to set_verb. --- src/ansys/mapdl/core/mapdl_extended.py | 9 --------- tests/test_mapdl.py | 5 ----- 2 files changed, 14 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl_extended.py b/src/ansys/mapdl/core/mapdl_extended.py index b8d2c1a569..a12ba23392 100644 --- a/src/ansys/mapdl/core/mapdl_extended.py +++ b/src/ansys/mapdl/core/mapdl_extended.py @@ -2123,15 +2123,6 @@ def cmlist(self, *args, **kwargs): return ComponentListing(super().cmlist(*args, **kwargs)) - @wraps(_MapdlCore.solve) - def solve(self, action="", **kwargs): - self._ctrl("set_verb", 0) - if hasattr(self, "logger") and self.logger is not None: - self.logger.debug("Disabling gRPC logging when solving") - - # TODO: Implement a get verbose option on server side - return super().solve(action=action, **kwargs) - class _MapdlExtended(_MapdlCommandExtended): """Extend Mapdl class with new functions""" diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index 2c2634a401..34ee64b2c6 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -2428,11 +2428,6 @@ def test_not_correct_et_element(mapdl, cleared): mapdl.keyopt(1, 222) -def test_ctrl(mapdl, cleared): - mapdl._ctrl("set_verb", 5) # Setting verbosity on the server - mapdl._ctrl("set_verb", 0) # Returning to non-verbose - - def test_cleanup_loggers(mapdl, cleared): assert mapdl.logger is not None assert mapdl.logger.hasHandlers() From ef57e1a76c4c3f1f8c83160ab05d302426e082a9 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:17:29 +0100 Subject: [PATCH 03/10] feat: running verify at connect --- src/ansys/mapdl/core/mapdl_grpc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index a15982ce12..a7aba75913 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -931,6 +931,8 @@ 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 + self._run("/verify", mute=True) + with self.run_as_routine("POST26"): self.numvar(200, mute=True) From fe432c7f9bf3b67a43485942807320cfcc49e570 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:21:00 +0000 Subject: [PATCH 04/10] fix: detecting comments as parameters sets when they have =. --- src/ansys/mapdl/core/mapdl_core.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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) From 6a798852c497ab669e0600ab165cb1f423fc8363 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:38:53 +0000 Subject: [PATCH 05/10] chore: adding changelog file 3608.fixed.md [dependabot-skip] --- doc/changelog.d/3608.fixed.md | 1 + 1 file changed, 1 insertion(+) 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..363a847010 --- /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 From ee28abfcdd05f5cf10c913d824097717373fead7 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:51:14 +0000 Subject: [PATCH 06/10] chore: adding changelog file 3608.fixed.md [dependabot-skip] --- doc/changelog.d/3608.fixed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.d/3608.fixed.md b/doc/changelog.d/3608.fixed.md index 363a847010..46f20d76a2 100644 --- a/doc/changelog.d/3608.fixed.md +++ b/doc/changelog.d/3608.fixed.md @@ -1 +1 @@ -Fix/avoid-verbose-grpc-interface-when-solving \ No newline at end of file +fix: avoid verbose grpc interface when solving \ No newline at end of file From 3f626cce5c78e4ef6c4e270a36925758150fabd2 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:49:00 +0100 Subject: [PATCH 07/10] feat: making sure we are running /verify in no routine. --- src/ansys/mapdl/core/mapdl_grpc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index a7aba75913..bfdec52f31 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -931,7 +931,8 @@ 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 - self._run("/verify", mute=True) + with self.run_as_routine("Begin level"): + self._run("/verify", mute=False) with self.run_as_routine("POST26"): self.numvar(200, mute=True) From ff4a8ba288d33c6d7ed8b6007658ad2653dbdfa2 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:37:25 +0100 Subject: [PATCH 08/10] feat: running /verify if using 'mapdl._ctr('set_verb',0)' --- src/ansys/mapdl/core/mapdl_grpc.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index bfdec52f31..0ebd1618c3 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -1614,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 From 30f6db5c1db61cf6fef19c3ca0acad5182c1e199 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:42:37 +0100 Subject: [PATCH 09/10] tests: adding test for checking we are using /verify --- tests/test_mapdl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index 34ee64b2c6..e9a4e64ffe 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -2428,6 +2428,17 @@ def test_not_correct_et_element(mapdl, cleared): mapdl.keyopt(1, 222) +def test_ctrl(mapdl, cleared): + 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.run("/verify") # mocking might skip running this inside mapdl._ctrl + + def test_cleanup_loggers(mapdl, cleared): assert mapdl.logger is not None assert mapdl.logger.hasHandlers() From 1d63ba09ca3a767b0330e7c6c1d5135c53e363be Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:56:41 +0100 Subject: [PATCH 10/10] tests: making sure the /verify is executed properly after finish --- tests/conftest.py | 2 ++ tests/test_mapdl.py | 1 + 2 files changed, 3 insertions(+) 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 e9a4e64ffe..ed2d611c0b 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -2436,6 +2436,7 @@ def test_ctrl(mapdl, cleared): assert "/verify" in mck_run.call_args_list[0].args[0] + mapdl.finish() mapdl.run("/verify") # mocking might skip running this inside mapdl._ctrl