diff --git a/doc/source/api/mapdl.rst b/doc/source/api/mapdl.rst index d2fa8e5792..943e138a71 100644 --- a/doc/source/api/mapdl.rst +++ b/doc/source/api/mapdl.rst @@ -14,7 +14,6 @@ :toctree: _autosummary Mapdl.add_file_handler - Mapdl.allow_ignore Mapdl.chain_commands Mapdl.directory Mapdl.get diff --git a/doc/source/user_guide/mapdl.rst b/doc/source/user_guide/mapdl.rst index 4635820126..6d3e1c0bfa 100644 --- a/doc/source/user_guide/mapdl.rst +++ b/doc/source/user_guide/mapdl.rst @@ -307,12 +307,12 @@ running a command in the wrong session raises an error: You can change this behavior so ignored commands can be logged as warnings and not raised as exceptions by using the -:func:`Mapdl.allow_ignore() ` function. For +:func:`Mapdl.ignore_errors() ` function. For example: .. code:: python - >>> mapdl.allow_ignore = True + >>> mapdl.ignore_errors = True >>> mapdl.k() # warning silently ignored diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index fef9368d1f..5e81ca606d 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -163,7 +163,7 @@ def __init__( self._show_matplotlib_figures = True # for testing self._query = None self._exited = False - self._allow_ignore = False + self._ignore_errors = False self._apdl_log = None self._store_commands = False self._stored_commands = [] @@ -191,7 +191,6 @@ def __init__( self._vget_arr_counter = 0 self._start_parm = start_parm self._path = start_parm.get("run_location", None) - self._ignore_errors = False self._print_com = print_com # print the command /COM input. self._cached_routine = None self._geometry = None @@ -922,12 +921,22 @@ def allow_ignore(self): This command will be ignored. """ - return self._allow_ignore + warn( + "'allow_ignore' is being deprecated and will be removed in a future release. " + "Use ``mapdl.ignore_errors`` instead.", + DeprecationWarning, + ) + return self._ignore_errors @allow_ignore.setter def allow_ignore(self, value): """Set allow ignore""" - self._allow_ignore = bool(value) + warn( + "'allow_ignore' is being deprecated and will be removed in a future release. " + "Use ``mapdl.ignore_errors`` instead.", + DeprecationWarning, + ) + self._ignore_errors = bool(value) def open_apdl_log(self, filename, mode="w"): """Start writing all APDL commands to an MAPDL input file. @@ -2837,20 +2846,19 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str: self._response = None return self._response - if "is not a recognized" in text: - if not self.allow_ignore: + if not self.ignore_errors: + if "is not a recognized" in text: text = text.replace("This command will be ignored.", "") - text += "\n\nIgnore these messages by setting allow_ignore=True" + text += "\n\nIgnore these messages by setting 'ignore_errors'=True" raise MapdlInvalidRoutineError(text) - if "command is ignored" in text: - if not self.allow_ignore: - text += "\n\nIgnore these messages by setting allow_ignore=True" + if "command is ignored" in text: + text += "\n\nIgnore these messages by setting 'ignore_errors'=True" raise MapdlCommandIgnoredError(text) - # flag errors - if "*** ERROR ***" in self._response and not self._ignore_errors: - self._raise_output_errors(self._response) + # flag errors + if "*** ERROR ***" in self._response: + self._raise_output_errors(self._response) # special returns for certain geometry commands short_cmd = parse_to_short_cmd(command) @@ -2862,12 +2870,33 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str: @property def ignore_errors(self) -> bool: - """ - Flag to ignore MAPDL errors. + """Invalid commands will be ignored rather than exceptions Normally, any string containing "*** ERROR ***" from MAPDL will trigger a ``MapdlRuntimeError``. Set this to ``True`` to ignore these errors. + + For example, a command executed in the wrong processor will + raise an exception when ``ignore_errors=False``. + This is the default behavior. + + Examples + -------- + >>> mapdl.post1() + >>> mapdl.k(1, 0, 0, 0) + Exception: K is not a recognized POST1 command, abbreviation, or macro. + + Ignore these messages by setting ignore_errors=True + + >>> mapdl.ignore_errors = True + 2020-06-08 21:39:58,094 [INFO] : K is not a + recognized POST1 command, abbreviation, or macro. This + command will be ignored. + + *** WARNING *** CP = 0.372 TIME= 21:39:58 + K is not a recognized POST1 command, abbreviation, or macro. + This command will be ignored. + """ return self._ignore_errors diff --git a/tests/conftest.py b/tests/conftest.py index 998e4f859d..3dd4478ea8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -446,7 +446,7 @@ def solved_box(mapdl, cleared): # Define a material (nominal steel in SI) mapdl.mp("EX", 1, 210e9) # Elastic moduli in Pa (kg/(m*s**2)) mapdl.mp("DENS", 1, 7800) # Density in kg/m3 - mapdl.mp("NUXY", 1, 0.3) # Poisson's Ratio + mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio # Fix the left-hand side. mapdl.nsel("S", "LOC", "Z", 0) mapdl.d("ALL", "UX") @@ -490,6 +490,7 @@ def twisted_sheet(mapdl, cleared): mapdl.prep7() mapdl.et(1, "SHELL181") mapdl.mp("EX", 1, 2e5) + mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio mapdl.rectng(0, 1, 0, 1) mapdl.sectype(1, "SHELL") mapdl.secdata(0.1) diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index b64b1e0e48..4ff5151c49 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -1562,6 +1562,7 @@ def test_non_interactive(mapdl, cleared): def test_ignored_command(mapdl, cleared): + mapdl.ignore_errors = False mapdl.prep7(mute=True) mapdl.n(mute=True) with pytest.raises(MapdlCommandIgnoredError, match="command is ignored"): @@ -1681,3 +1682,22 @@ def test_on_docker(mapdl): assert mapdl.on_docker else: assert not mapdl.on_docker + + +def test_deprecation_allow_ignore_warning(mapdl): + with pytest.warns(DeprecationWarning, match="'allow_ignore' is being deprecated"): + mapdl.allow_ignore = True + + +def test_deprecation_allow_ignore_errors_mapping(mapdl): + mapdl.allow_ignore = True + assert mapdl.allow_ignore == mapdl.ignore_errors + + mapdl.allow_ignore = False + assert mapdl.allow_ignore == mapdl.ignore_errors + + mapdl.ignore_errors = True + assert mapdl.allow_ignore == mapdl.ignore_errors + + mapdl.ignore_errors = False + assert mapdl.allow_ignore == mapdl.ignore_errors