Skip to content

fix: adding console testing #3791

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 17 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ jobs:
with:
latest-version: "252"
mapdl-version: ${{ matrix.mapdl-version }}
testing-minimal: true
testing-minimal: false
on-console: true
pytest-arguments: '-k console'
file-name: "${{ matrix.mapdl-version }}-minimal-console"
tags: "local,minimal,console"

file-name: "${{ matrix.mapdl-version }}-console"
tags: "local,console"


test-windows:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3791.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: adding console testing
4 changes: 3 additions & 1 deletion src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,9 @@ def inject_additional_switches(args: dict[str, Any]) -> dict[str, Any]:

if envvaras:
if args.get("additional_switches"):
args["additional_switches"] += f" {envvaras}"
LOG.warning(
"Skipping injecting additional switches from env var if the function argument is used."
)
else:
args["additional_switches"] = envvaras

Expand Down
33 changes: 30 additions & 3 deletions src/ansys/mapdl/core/mapdl_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
rb"executed\?",
# errors
rb"SHOULD INPUT PROCESSING BE SUSPENDED\?",
rb"ANSYS Traceback",
rb"eMPIChildJob",
# prompts
rb"ENTER FORMAT for",
]
Expand All @@ -59,6 +61,7 @@
ERROR_IDX = ready_items.index(rb"SHOULD INPUT PROCESSING BE SUSPENDED\?")
PROMPT_IDX = ready_items.index(rb"ENTER FORMAT for")


nitems = len(ready_items)
expect_list = []
for item in ready_items:
Expand Down Expand Up @@ -86,13 +89,13 @@ def launch_pexpect(
nproc,
additional_switches,
)
process = pexpect.spawn(command, cwd=run_location)
process = pexpect.spawn(command, cwd=run_location, use_poll=True)
process.delaybeforesend = None

try:
index = process.expect(["BEGIN:", "CONTINUE"], timeout=start_timeout)
except: # capture failure
raise RuntimeError(process.before.decode("utf-8"))
except Exception as err: # capture failure
raise RuntimeError(process.before.decode("utf-8") or err)

if index: # received ... press enter to continue
process.sendline("")
Expand All @@ -113,6 +116,7 @@ def __init__(
log_apdl=None,
use_vtk=True,
print_com=False,
set_no_abort=True,
**start_parm,
):
"""Opens an ANSYS process using pexpect"""
Expand All @@ -122,6 +126,7 @@ def __init__(
self._name = None
self._session_id = None
self._cleanup = None
self.clean_response = True

self._launch(start_parm)
super().__init__(
Expand All @@ -132,6 +137,8 @@ def __init__(
mode="console",
**start_parm,
)
if set_no_abort:
self.nerr(abort=-1, mute=True)

def _launch(self, start_parm):
"""Connect to MAPDL process using pexpect"""
Expand Down Expand Up @@ -169,6 +176,19 @@ def _run(self, command, **kwargs):
while True:
i = self._process.expect_list(expect_list, timeout=None)
response = self._process.before.decode("utf-8")

if self.clean_response:
# Cleaning up responses
response = response.strip().splitlines()
if (
isinstance(response, list)
and len(response) > 0
and response[0].upper() == command.upper()
):
response = response[1:]

response = "\n".join(response)

full_response += response
if i >= CONTINUE_IDX and i < WARNING_IDX: # continue
self._log.debug(
Expand Down Expand Up @@ -335,3 +355,10 @@ def name(self):
if not self._name:
self._name = f"Console_PID_{self._process.pid}"
return self._name

def scalar_param(self, parm_name):
response = self.starstatus(parm_name)
response = response.splitlines()[-1]
if parm_name.upper() not in response:
raise ValueError(f"Parameter {parm_name} not found")
return float(response.split()[1].strip())
122 changes: 122 additions & 0 deletions src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
supress_logging,
)

TMP_VAR = "__tmpvar__"


class _MapdlCommandExtended(_MapdlCore):
"""Class that extended MAPDL capabilities by wrapping or overwriting commands"""
Expand Down Expand Up @@ -2123,6 +2125,126 @@ def cmlist(self, *args, **kwargs):

return ComponentListing(super().cmlist(*args, **kwargs))

@wraps(_MapdlCore.ndinqr)
def ndinqr(self, node, key, **kwargs):
"""Wrap the ``ndinqr`` method to take advantage of the gRPC methods."""
super().ndinqr(node, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.elmiqr)
def elmiqr(self, ielem, key, **kwargs):
"""Wrap the ``elmiqr`` method to take advantage of the gRPC methods."""
super().elmiqr(ielem, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.kpinqr)
def kpinqr(self, knmi, key, **kwargs):
"""Wrap the ``kpinqr`` method to take advantage of the gRPC methods."""
super().kpinqr(knmi, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.lsinqr)
def lsinqr(self, line, key, **kwargs):
"""Wrap the ``lsinqr`` method to take advantage of the gRPC methods."""
super().lsinqr(line, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.arinqr)
def arinqr(self, anmi, key, **kwargs):
"""Wrap the ``arinqr`` method to take advantage of the gRPC methods."""
super().arinqr(anmi, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.vlinqr)
def vlinqr(self, vnmi, key, **kwargs):
"""Wrap the ``vlinqr`` method to take advantage of the gRPC methods."""
super().vlinqr(vnmi, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.rlinqr)
def rlinqr(self, nreal, key, **kwargs):
"""Wrap the ``rlinqr`` method to take advantage of the gRPC methods."""
super().rlinqr(nreal, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.gapiqr)
def gapiqr(self, ngap, key, **kwargs):
"""Wrap the ``gapiqr`` method to take advantage of the gRPC methods."""
super().gapiqr(ngap, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.masiqr)
def masiqr(self, node, key, **kwargs):
"""Wrap the ``masiqr`` method to take advantage of the gRPC methods."""
super().masiqr(node, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.ceinqr)
def ceinqr(self, nce, key, **kwargs):
"""Wrap the ``ceinqr`` method to take advantage of the gRPC methods."""
super().ceinqr(nce, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.cpinqr)
def cpinqr(self, ncp, key, **kwargs):
"""Wrap the ``cpinqr`` method to take advantage of the gRPC methods."""
super().cpinqr(ncp, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.csyiqr)
def csyiqr(self, ncsy, key, **kwargs):
"""Wrap the ``csyiqr`` method to take advantage of the gRPC methods."""
super().csyiqr(ncsy, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.etyiqr)
def etyiqr(self, itype, key, **kwargs):
"""Wrap the ``etyiqr`` method to take advantage of the gRPC methods."""
super().etyiqr(itype, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.foriqr)
def foriqr(self, node, key, **kwargs):
"""Wrap the ``foriqr`` method to take advantage of the gRPC methods."""
super().foriqr(node, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.sectinqr)
def sectinqr(self, nsect, key, **kwargs):
"""Wrap the ``sectinqr`` method to take advantage of the gRPC methods."""
super().sectinqr(nsect, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.mpinqr)
def mpinqr(self, mat, iprop, key, **kwargs):
"""Wrap the ``mpinqr`` method to take advantage of the gRPC methods."""
super().mpinqr(mat, iprop, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.dget)
def dget(self, node, idf, kcmplx, **kwargs):
"""Wrap the ``dget`` method to take advantage of the gRPC methods."""
super().dget(node, idf, kcmplx, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.fget)
def fget(self, node, idf, kcmplx, **kwargs):
"""Wrap the ``fget`` method to take advantage of the gRPC methods."""
super().fget(node, idf, kcmplx, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.erinqr)
def erinqr(self, key, **kwargs):
"""Wrap the ``erinqr`` method to take advantage of the gRPC methods."""
super().erinqr(key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(_MapdlCore.wrinqr)
def wrinqr(self, key, **kwargs):
"""Wrap the ``wrinqr`` method to take advantage of the gRPC methods."""
super().wrinqr(key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)


class _MapdlExtended(_MapdlCommandExtended):
"""Extend Mapdl class with new functions"""
Expand Down
121 changes: 0 additions & 121 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
from ansys.mapdl.core.database import MapdlDb
from ansys.mapdl.core.xpl import ansXpl

TMP_VAR = "__tmpvar__"
VOID_REQUEST = anskernel.EmptyRequest()

# Default 256 MB message length
Expand Down Expand Up @@ -3153,126 +3152,6 @@ def _distributed(self) -> bool:
self.__distributed = self.parameters.numcpu > 1
return self.__distributed

@wraps(MapdlBase.ndinqr)
def ndinqr(self, node, key, **kwargs):
"""Wrap the ``ndinqr`` method to take advantage of the gRPC methods."""
super().ndinqr(node, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.elmiqr)
def elmiqr(self, ielem, key, **kwargs):
"""Wrap the ``elmiqr`` method to take advantage of the gRPC methods."""
super().elmiqr(ielem, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.kpinqr)
def kpinqr(self, knmi, key, **kwargs):
"""Wrap the ``kpinqr`` method to take advantage of the gRPC methods."""
super().kpinqr(knmi, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.lsinqr)
def lsinqr(self, line, key, **kwargs):
"""Wrap the ``lsinqr`` method to take advantage of the gRPC methods."""
super().lsinqr(line, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.arinqr)
def arinqr(self, anmi, key, **kwargs):
"""Wrap the ``arinqr`` method to take advantage of the gRPC methods."""
super().arinqr(anmi, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.vlinqr)
def vlinqr(self, vnmi, key, **kwargs):
"""Wrap the ``vlinqr`` method to take advantage of the gRPC methods."""
super().vlinqr(vnmi, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.rlinqr)
def rlinqr(self, nreal, key, **kwargs):
"""Wrap the ``rlinqr`` method to take advantage of the gRPC methods."""
super().rlinqr(nreal, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.gapiqr)
def gapiqr(self, ngap, key, **kwargs):
"""Wrap the ``gapiqr`` method to take advantage of the gRPC methods."""
super().gapiqr(ngap, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.masiqr)
def masiqr(self, node, key, **kwargs):
"""Wrap the ``masiqr`` method to take advantage of the gRPC methods."""
super().masiqr(node, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.ceinqr)
def ceinqr(self, nce, key, **kwargs):
"""Wrap the ``ceinqr`` method to take advantage of the gRPC methods."""
super().ceinqr(nce, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.cpinqr)
def cpinqr(self, ncp, key, **kwargs):
"""Wrap the ``cpinqr`` method to take advantage of the gRPC methods."""
super().cpinqr(ncp, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.csyiqr)
def csyiqr(self, ncsy, key, **kwargs):
"""Wrap the ``csyiqr`` method to take advantage of the gRPC methods."""
super().csyiqr(ncsy, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.etyiqr)
def etyiqr(self, itype, key, **kwargs):
"""Wrap the ``etyiqr`` method to take advantage of the gRPC methods."""
super().etyiqr(itype, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.foriqr)
def foriqr(self, node, key, **kwargs):
"""Wrap the ``foriqr`` method to take advantage of the gRPC methods."""
super().foriqr(node, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.sectinqr)
def sectinqr(self, nsect, key, **kwargs):
"""Wrap the ``sectinqr`` method to take advantage of the gRPC methods."""
super().sectinqr(nsect, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.mpinqr)
def mpinqr(self, mat, iprop, key, **kwargs):
"""Wrap the ``mpinqr`` method to take advantage of the gRPC methods."""
super().mpinqr(mat, iprop, key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.dget)
def dget(self, node, idf, kcmplx, **kwargs):
"""Wrap the ``dget`` method to take advantage of the gRPC methods."""
super().dget(node, idf, kcmplx, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.fget)
def fget(self, node, idf, kcmplx, **kwargs):
"""Wrap the ``fget`` method to take advantage of the gRPC methods."""
super().fget(node, idf, kcmplx, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.erinqr)
def erinqr(self, key, **kwargs):
"""Wrap the ``erinqr`` method to take advantage of the gRPC methods."""
super().erinqr(key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.wrinqr)
def wrinqr(self, key, **kwargs):
"""Wrap the ``wrinqr`` method to take advantage of the gRPC methods."""
super().wrinqr(key, pname=TMP_VAR, mute=True, **kwargs)
return self.scalar_param(TMP_VAR)

@wraps(MapdlBase.file)
def file(self, fname: str = "", ext: str = "", **kwargs) -> str:
"""Wrap ``MapdlBase.file`` to take advantage of the gRPC methods."""
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def mapdl_console(request):
mode="console",
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
additional_switches="-smp",
)
from ansys.mapdl.core.mapdl_console import MapdlConsole

Expand Down
Loading