Skip to content

Adding avoid non interactive non-documented argument #1747

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

Merged
merged 8 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions doc/source/user_guide/troubleshoot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ either Windows or Linux.
printenv | grep ANSYSLMD_LICENSE_FILE


.. _missing_dependencies_on_linux:

.. _vpn_issues_troubleshooting:

Virtual private network (VPN) issues
====================================
Expand Down Expand Up @@ -210,6 +209,8 @@ On Windows, you can find the license configuration file that points to the licen



.. _missing_dependencies_on_linux:

Missing dependencies on Linux
=============================

Expand Down
26 changes: 26 additions & 0 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,16 +1416,42 @@ def launch_mapdl(

export PYMAPDL_MAPDL_VERSION=22.2

kwargs : dict, optional
These keyword arguments are interface specific or for
development purposes. See Notes for more details.

set_no_abort : :class:`bool`
*(Development use only)*
Sets MAPDL to not abort at the first error within /BATCH mode.
Defaults to ``True``.

force_intel : :class:`bool`
*(Development use only)*
Forces the use of Intel message pass interface (MPI) in versions between
Ansys 2021R0 and 2022R2, where because of VPNs issues this MPI is deactivated
by default. See :ref:`vpn_issues_troubleshooting` for more information.
Defaults to ``False``.

log_broadcast : :class:`bool`
*(Only for CORBA mode)*
Enables a logger to record broadcasted commands.
Defaults to ``False``.

Returns
-------
ansys.mapdl.core.mapdl._MapdlCore
An instance of Mapdl. Type depends on the selected ``mode``.

Notes
-----

**Ansys Student Version**

If an Ansys Student version is detected, PyMAPDL will launch MAPDL in
shared-memory parallelism (SMP) mode unless another option is specified.

**Additional switches**

These are the MAPDL switch options as of 2020R2 applicable for
running MAPDL as a service via gRPC. Excluded switches such as
``"-j"`` either not applicable or are set via keyword arguments.
Expand Down
22 changes: 19 additions & 3 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2737,8 +2737,18 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
to ``False``, will not write command to log, even if APDL
command logging is enabled.

kwargs : Optional keyword arguments
These keyword arguments are interface specific.
kwargs : dict, optional
These keyword arguments are interface specific or for
development purposes.

avoid_non_interactive : :class:`bool`
*(Development use only)*
Avoids the non-interactive mode for this specific command.
Defaults to ``False``.

verbose : :class:`bool`
Prints the command to the screen before running it.
Defaults to ``False``.

Returns
-------
Expand All @@ -2747,6 +2757,9 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:

Notes
-----

**Running non-interactive commands**

When two or more commands need to be run non-interactively
(i.e. ``*VWRITE``) use

Expand Down Expand Up @@ -2777,7 +2790,10 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
if "\n" in command or "\r" in command:
raise ValueError("Use ``input_strings`` for multi-line commands")

if self._store_commands:
# check if we want to avoid the current non-interactive context.
avoid_non_interactive = kwargs.pop("avoid_non_interactive", False)

if self._store_commands and not avoid_non_interactive:
# If we are using NBLOCK on input, we should not strip the string
self._stored_commands.append(command)
return
Expand Down
9 changes: 4 additions & 5 deletions src/ansys/mapdl/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def type(self) -> int:
@supress_logging
def _parm(self):
"""Current MAPDL parameters"""
params = interp_star_status(self._mapdl.starstatus())
params = interp_star_status(self._mapdl.starstatus(avoid_non_interactive=True))

if self.show_leading_underscore_parameters:
_params = interp_star_status(self._mapdl.starstatus("_PRM"))
Expand Down Expand Up @@ -418,8 +418,9 @@ def _get_parameter_array(self, parm_name, shape):
self._mapdl.run(format_str)

st = self._mapdl.last_response.rfind(format_str) + len(format_str) + 1
output = self._mapdl.last_response[st:]

if "**" not in self._mapdl.last_response[st:]:
if "**" not in output:
escaped = True
break

Expand All @@ -429,9 +430,7 @@ def _get_parameter_array(self, parm_name, shape):
"that could not be read using '{format_str}'."
)

arr_flat = np.fromstring(self._mapdl.last_response[st:], sep="\n").reshape(
shape
)
arr_flat = np.fromstring(output, sep="\n").reshape(shape)

if len(shape) == 3:
if shape[2] == 1:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,3 +1714,16 @@ def test_deprecation_allow_ignore_errors_mapping(mapdl):

mapdl.ignore_errors = False
assert mapdl.allow_ignore == mapdl.ignore_errors


def test_avoid_non_interactive(mapdl):

with mapdl.non_interactive:
mapdl.com("comment A")
mapdl.com("comment B", avoid_non_interactive=True)
mapdl.com("comment C")

stored_commands = mapdl._stored_commands
assert any(["comment A" in cmd for cmd in stored_commands])
assert all(["comment B" not in cmd for cmd in stored_commands])
assert any(["comment C" in cmd for cmd in stored_commands])