Skip to content

Commit a7d4359

Browse files
fix: timeout for file checking (#3642)
* fix: increase timeout for checking output file * feat: implement global defaults OS dependent. * feat: adding logging * fix: increase timeout for checking output file * feat: implement global defaults OS dependent. * feat: adding logging * chore: adding changelog file 3642.fixed.md [dependabot-skip] * fix: wrong variable * tests: adding tests * ci: not hiding log --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent a4354c7 commit a7d4359

File tree

5 files changed

+83
-22
lines changed

5 files changed

+83
-22
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ jobs:
151151
python-package-name: ${{ env.PACKAGE_NAME }}
152152
dev-mode: ${{ github.ref != 'refs/heads/main' }}
153153
upload-reports: True
154+
hide-log: false
155+
154156

155157
docs-build:
156158
name: "Build documentation"

doc/changelog.d/3642.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: timeout for file checking

src/ansys/mapdl/core/mapdl_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,7 @@ def _check_mapdl_os(self):
29192919
self._platform = "windows"
29202920
else: # pragma: no cover
29212921
raise MapdlRuntimeError("Unknown platform: {}".format(platform))
2922+
self.logger.debug(f"MAPDL is running on {self._platform} OS.")
29222923

29232924
def _check_on_docker(self):
29242925
"""Check if MAPDL is running on docker."""

src/ansys/mapdl/core/mapdl_grpc.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119

120120
SESSION_ID_NAME = "__PYMAPDL_SESSION_ID__"
121121

122+
DEFAULT_TIME_STEP_STREAM = None
123+
DEFAULT_TIME_STEP_STREAM_NT = 500
124+
DEFAULT_TIME_STEP_STREAM_POSIX = 100
125+
122126
# Retry policy for gRPC calls.
123127
SERVICE_DEFAULT_CONFIG = {
124128
# see https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy-capabilities
@@ -1069,7 +1073,8 @@ def _send_command(self, cmd: str, mute: bool = False) -> Optional[str]:
10691073
def _send_command_stream(self, cmd, verbose=False) -> str:
10701074
"""Send a command and expect a streaming response"""
10711075
request = pb_types.CmdRequest(command=cmd)
1072-
metadata = [("time_step_stream", "100")]
1076+
time_step = self._get_time_step_stream()
1077+
metadata = [("time_step_stream", str(time_step))]
10731078
stream = self._stub.SendCommandS(request, metadata=metadata)
10741079
response = []
10751080
for item in stream:
@@ -1775,13 +1780,14 @@ def input(
17751780
execution time.
17761781
17771782
Due to stability issues, the default time_step_stream is
1778-
dependent on verbosity. The defaults are:
1783+
dependent on the OS MAPDL is running on. The defaults are:
17791784
1780-
- ``verbose=True``: ``time_step_stream=500``
1781-
- ``verbose=False``: ``time_step_stream=50``
1785+
- Windows: ``time_step_stream=500``
1786+
- Linux: ``time_step_stream=100``
17821787
17831788
These defaults will be ignored if ``time_step_stream`` is
1784-
manually set.
1789+
manually set. See the *Examples* section to learn how to change
1790+
the default value globally.
17851791
17861792
orig_cmd : str, optional
17871793
Original command. There are some cases, were input is
@@ -1831,6 +1837,11 @@ def input(
18311837
>>> with mapdl.non_interactive:
18321838
mapdl.run("/input,inputtrigger,inp") # This inputs 'myinput.inp'
18331839
1840+
You can also change them globably using:
1841+
1842+
>>> from ansys.mapdl.core import mapdl_grpc
1843+
>>> mapdl_grpc.DEFAULT_TIME_STEP_STREAM=100 # in milliseconds
1844+
18341845
"""
18351846
# Checking compatibility
18361847
# Checking the user is not reusing old api:
@@ -1911,18 +1922,14 @@ def input(
19111922
# are unclear
19121923
filename = self._get_file_path(fname, progress_bar)
19131924

1914-
if time_step_stream is not None:
1915-
if time_step_stream <= 0:
1916-
raise ValueError("``time_step_stream`` must be greater than 0``")
1925+
time_step_stream = self._get_time_step_stream(time_step_stream)
19171926

1918-
if verbose:
1919-
if time_step_stream is None:
1920-
time_step_stream = 500
1921-
metadata = [
1922-
("time_step_stream", str(time_step_stream)),
1923-
("chunk_size", str(chunk_size)),
1924-
]
1927+
metadata = [
1928+
("time_step_stream", str(time_step_stream)),
1929+
("chunk_size", str(chunk_size)),
1930+
]
19251931

1932+
if verbose:
19261933
request = pb_types.InputFileRequest(filename=filename)
19271934
strouts = self._stub.InputFileS(request, metadata=metadata)
19281935
responses = []
@@ -1934,13 +1941,8 @@ def input(
19341941
response = "\n".join(responses)
19351942
return response.strip()
19361943

1937-
# otherwise, not verbose
1938-
if time_step_stream is None:
1939-
time_step_stream = 50
1940-
metadata = [
1941-
("time_step_stream", str(time_step_stream)),
1942-
("chunk_size", str(chunk_size)),
1943-
]
1944+
##
1945+
# Otherwise, not verbose
19441946

19451947
# since we can't directly run /INPUT, we have to write a
19461948
# temporary input file that tells MAPDL to read the input
@@ -2014,6 +2016,31 @@ def input(
20142016

20152017
return output
20162018

2019+
def _get_time_step_stream(
2020+
self, time_step: Optional[Union[int, float]] = None
2021+
) -> str:
2022+
"""Return the time step for checking if MAPDL is done writing the
2023+
output to the file which later will be returned as response
2024+
"""
2025+
if time_step is None:
2026+
if DEFAULT_TIME_STEP_STREAM is not None:
2027+
time_step = DEFAULT_TIME_STEP_STREAM
2028+
elif self.platform == "windows":
2029+
time_step = DEFAULT_TIME_STEP_STREAM_NT
2030+
elif self.platform == "linux":
2031+
time_step = DEFAULT_TIME_STEP_STREAM_POSIX
2032+
else:
2033+
raise ValueError(
2034+
f"The MAPDL platform ('{self.platform}') is not recognaised."
2035+
)
2036+
2037+
else:
2038+
if time_step <= 0:
2039+
raise ValueError("``time_step`` argument must be greater than 0``")
2040+
2041+
self.logger.debug(f"The time_step argument is set to: {time_step}")
2042+
return time_step
2043+
20172044
def _get_file_path(self, fname: str, progress_bar: bool = False) -> str:
20182045
"""Find files in the Python and MAPDL working directories.
20192046

tests/test_grpc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import re
2626
import shutil
2727
import sys
28+
from unittest.mock import patch
2829

2930
import grpc
3031
import pytest
@@ -682,3 +683,32 @@ def _null_close_process():
682683
mapdl.prep7(mapdl)
683684

684685
mapdl._exited = False # Restoring
686+
687+
688+
@pytest.mark.parametrize("platform", ["linux", "windows", "error"])
689+
def test__get_time_step_stream(mapdl, platform):
690+
with patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.platform", platform):
691+
from ansys.mapdl.core import mapdl_grpc
692+
693+
if platform == "linux":
694+
DEFAULT_TIME_STEP_STREAM = mapdl_grpc.DEFAULT_TIME_STEP_STREAM_POSIX
695+
elif platform == "windows":
696+
DEFAULT_TIME_STEP_STREAM = mapdl_grpc.DEFAULT_TIME_STEP_STREAM_NT
697+
else:
698+
with pytest.raises(ValueError, match="The MAPDL platform"):
699+
mapdl._get_time_step_stream()
700+
701+
return # Early exit
702+
703+
assert DEFAULT_TIME_STEP_STREAM == mapdl._get_time_step_stream()
704+
705+
mapdl_grpc.DEFAULT_TIME_STEP_STREAM = 200
706+
assert mapdl_grpc.DEFAULT_TIME_STEP_STREAM == mapdl._get_time_step_stream()
707+
mapdl_grpc.DEFAULT_TIME_STEP_STREAM = None
708+
709+
assert 700 == mapdl._get_time_step_stream(700)
710+
711+
with pytest.raises(
712+
ValueError, match="``time_step`` argument must be greater than 0``"
713+
):
714+
mapdl._get_time_step_stream(-700)

0 commit comments

Comments
 (0)