Skip to content

Commit 9eb459a

Browse files
authored
Adding avoid non interactive non-documented argument (#1747)
* Adding avoid_non_interactive * copying output to avoid overwriting last-response. * Fixing test * Documenting kwargs in notes section * Writing the kwargs arguments in the parameter section. More coherent. * Adding note. * Fixing italic text
1 parent 5f01a85 commit 9eb459a

File tree

5 files changed

+65
-10
lines changed

5 files changed

+65
-10
lines changed

doc/source/user_guide/troubleshoot.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ either Windows or Linux.
171171
printenv | grep ANSYSLMD_LICENSE_FILE
172172
173173
174-
.. _missing_dependencies_on_linux:
175-
174+
.. _vpn_issues_troubleshooting:
176175

177176
Virtual private network (VPN) issues
178177
====================================
@@ -211,6 +210,8 @@ On Windows, you can find the license configuration file that points to the licen
211210
212211
213212
213+
.. _missing_dependencies_on_linux:
214+
214215
Missing dependencies on Linux
215216
=============================
216217

src/ansys/mapdl/core/launcher.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,16 +1416,42 @@ def launch_mapdl(
14161416
14171417
export PYMAPDL_MAPDL_VERSION=22.2
14181418
1419+
kwargs : dict, optional
1420+
These keyword arguments are interface specific or for
1421+
development purposes. See Notes for more details.
1422+
1423+
set_no_abort : :class:`bool`
1424+
*(Development use only)*
1425+
Sets MAPDL to not abort at the first error within /BATCH mode.
1426+
Defaults to ``True``.
1427+
1428+
force_intel : :class:`bool`
1429+
*(Development use only)*
1430+
Forces the use of Intel message pass interface (MPI) in versions between
1431+
Ansys 2021R0 and 2022R2, where because of VPNs issues this MPI is deactivated
1432+
by default. See :ref:`vpn_issues_troubleshooting` for more information.
1433+
Defaults to ``False``.
1434+
1435+
log_broadcast : :class:`bool`
1436+
*(Only for CORBA mode)*
1437+
Enables a logger to record broadcasted commands.
1438+
Defaults to ``False``.
1439+
14191440
Returns
14201441
-------
14211442
ansys.mapdl.core.mapdl._MapdlCore
14221443
An instance of Mapdl. Type depends on the selected ``mode``.
14231444
14241445
Notes
14251446
-----
1447+
1448+
**Ansys Student Version**
1449+
14261450
If an Ansys Student version is detected, PyMAPDL will launch MAPDL in
14271451
shared-memory parallelism (SMP) mode unless another option is specified.
14281452
1453+
**Additional switches**
1454+
14291455
These are the MAPDL switch options as of 2020R2 applicable for
14301456
running MAPDL as a service via gRPC. Excluded switches such as
14311457
``"-j"`` either not applicable or are set via keyword arguments.

src/ansys/mapdl/core/mapdl.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,8 +2737,18 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
27372737
to ``False``, will not write command to log, even if APDL
27382738
command logging is enabled.
27392739
2740-
kwargs : Optional keyword arguments
2741-
These keyword arguments are interface specific.
2740+
kwargs : dict, optional
2741+
These keyword arguments are interface specific or for
2742+
development purposes.
2743+
2744+
avoid_non_interactive : :class:`bool`
2745+
*(Development use only)*
2746+
Avoids the non-interactive mode for this specific command.
2747+
Defaults to ``False``.
2748+
2749+
verbose : :class:`bool`
2750+
Prints the command to the screen before running it.
2751+
Defaults to ``False``.
27422752
27432753
Returns
27442754
-------
@@ -2747,6 +2757,9 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
27472757
27482758
Notes
27492759
-----
2760+
2761+
**Running non-interactive commands**
2762+
27502763
When two or more commands need to be run non-interactively
27512764
(i.e. ``*VWRITE``) use
27522765
@@ -2777,7 +2790,10 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
27772790
if "\n" in command or "\r" in command:
27782791
raise ValueError("Use ``input_strings`` for multi-line commands")
27792792

2780-
if self._store_commands:
2793+
# check if we want to avoid the current non-interactive context.
2794+
avoid_non_interactive = kwargs.pop("avoid_non_interactive", False)
2795+
2796+
if self._store_commands and not avoid_non_interactive:
27812797
# If we are using NBLOCK on input, we should not strip the string
27822798
self._stored_commands.append(command)
27832799
return

src/ansys/mapdl/core/parameters.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def type(self) -> int:
280280
@supress_logging
281281
def _parm(self):
282282
"""Current MAPDL parameters"""
283-
params = interp_star_status(self._mapdl.starstatus())
283+
params = interp_star_status(self._mapdl.starstatus(avoid_non_interactive=True))
284284

285285
if self.show_leading_underscore_parameters:
286286
_params = interp_star_status(self._mapdl.starstatus("_PRM"))
@@ -418,8 +418,9 @@ def _get_parameter_array(self, parm_name, shape):
418418
self._mapdl.run(format_str)
419419

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

422-
if "**" not in self._mapdl.last_response[st:]:
423+
if "**" not in output:
423424
escaped = True
424425
break
425426

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

432-
arr_flat = np.fromstring(self._mapdl.last_response[st:], sep="\n").reshape(
433-
shape
434-
)
433+
arr_flat = np.fromstring(output, sep="\n").reshape(shape)
435434

436435
if len(shape) == 3:
437436
if shape[2] == 1:

tests/test_mapdl.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,3 +1714,16 @@ def test_deprecation_allow_ignore_errors_mapping(mapdl):
17141714

17151715
mapdl.ignore_errors = False
17161716
assert mapdl.allow_ignore == mapdl.ignore_errors
1717+
1718+
1719+
def test_avoid_non_interactive(mapdl):
1720+
1721+
with mapdl.non_interactive:
1722+
mapdl.com("comment A")
1723+
mapdl.com("comment B", avoid_non_interactive=True)
1724+
mapdl.com("comment C")
1725+
1726+
stored_commands = mapdl._stored_commands
1727+
assert any(["comment A" in cmd for cmd in stored_commands])
1728+
assert all(["comment B" not in cmd for cmd in stored_commands])
1729+
assert any(["comment C" in cmd for cmd in stored_commands])

0 commit comments

Comments
 (0)