Skip to content

Commit

Permalink
Merge branch 'main' into fix/removing-skip-regression-test-option
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Nov 8, 2023
2 parents 341409f + 428fba2 commit 4960a02
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .ci/start_mapdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ docker run \
-p $PYMAPDL_DB_PORT:50055 \
--shm-size=1gb \
-e I_MPI_SHM_LMT=shm \
--oom-kill-disable \
--memory=6656MB \
--memory-swap=16896MB \
$MAPDL_IMAGE \
-$DISTRIBUTED_MODE -np 2 > log.txt &
grep -q 'Server listening on' <(timeout 60 tail -f log.txt)
3 changes: 3 additions & 0 deletions .ci/start_mapdl_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ docker run \
-e I_MPI_SHM_LMT=shm \
-w /jobs \
-u=0:0 \
--oom-kill-disable \
--memory=6656MB \
--memory-swap=16896MB \
$MAPDL_IMAGE /ansys_inc/v222/ansys/bin/mapdl -grpc -dir /jobs -$DISTRIBUTED_MODE -np 2 > log.txt &
grep -q 'Server listening on' <(timeout 60 tail -f log.txt)
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ jobs:
commit_long_sha: ${{ steps.attatch-to-pr.outputs.commit_long_sha }}
container:
image: ghcr.io/ansys/mapdl:v22.2-ubuntu
options: "-u=0:0 --entrypoint /bin/bash"
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
credentials:
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -596,7 +596,7 @@ jobs:
timeout-minutes: 55
container:
image: ghcr.io/ansys/mapdl:v22.2-ubuntu
options: "-u=0:0 --entrypoint /bin/bash"
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
credentials:
username: ${{ secrets.GH_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down
43 changes: 40 additions & 3 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,20 @@ def __enter__(self):
self._parent()._store_commands = True

def __exit__(self, *args):
self._parent()._log.debug("Exiting non-interactive mode")
self._parent()._flush_stored()
self._parent()._store_commands = False

if args[0] is not None:
# An exception was raised, let's exit now without flushing
self._parent()._log.debug(
"An exception was found in the `non_interactive` environment. "
"Hence the commands are not flushed."
)
return None
else:
# No exception so let's flush.
self._parent()._log.debug("Exiting non-interactive mode")
self._parent()._flush_stored()

class _save_selection:
"""Save the selection and returns to it when exiting"""

Expand Down Expand Up @@ -3827,7 +3837,20 @@ def get_array(
-0.00178402, -0.01234851, 0.01234851, -0.01234851])
"""
arr = self._get_array(entity, entnum, item1, it1num, item2, it2num, kloop)
parm_name = kwargs.get("parm", None)

if self._store_commands:
raise MapdlRuntimeError(
"Cannot use `mapdl.get_array` when in `non_interactive` mode, "
"since it does not return anything until the `non_interactive` context "
"manager is finished.\n"
"Exit `non_interactive` mode before using this method.\n\n"
"Alternatively you can use `mapdl.vget` to specify the name of the MAPDL parameter where to store the retrieved value."
)

arr = self._get_array(
entity, entnum, item1, it1num, item2, it2num, kloop, **kwargs
)

# edge case where corba refuses to return the array
ntry = 0
Expand All @@ -3853,6 +3876,16 @@ def _get_array(
"""Uses the VGET command to get an array from ANSYS"""
parm_name = kwargs.pop("parm", None)

if self._store_commands and not parm_name:
raise MapdlRuntimeError(

Check warning on line 3880 in src/ansys/mapdl/core/mapdl.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl.py#L3879-L3880

Added lines #L3879 - L3880 were not covered by tests
"Cannot use `mapdl._get_array` when in `non_interactive` mode, "
"since it does not return anything until the `non_interactive` context "
"manager is finished.\n"
"Exit `non_interactive` mode before using this method.\n\n"
"Alternatively you can use `mapdl.vget` or use the `parm` kwarg in "
"`mapdl._get_array` to specify the name of the MAPDL parameter where to store the retrieved value. In any case, this function will return `None`"
)

if parm_name is None:
parm_name = "__vget_tmp_%d__" % self._vget_arr_counter
self._vget_arr_counter += 1
Expand All @@ -3869,6 +3902,10 @@ def _get_array(
mute=False,
)

if self._store_commands:

Check warning on line 3905 in src/ansys/mapdl/core/mapdl.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl.py#L3905

Added line #L3905 was not covered by tests
# Return early
return None

Check warning on line 3907 in src/ansys/mapdl/core/mapdl.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl.py#L3907

Added line #L3907 was not covered by tests

# check if empty array
if "the dimension number 1 is 0" in out:
return np.empty(0)
Expand Down
6 changes: 4 additions & 2 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,8 +2040,10 @@ def _get(

if self._store_commands:
raise MapdlRuntimeError(
"Cannot use gRPC enabled ``GET`` when in non_interactive mode. "
"Exit non_interactive mode before using this method."
"Cannot use `mapdl.get_value` when in `non_interactive` mode. "
"Exit non_interactive mode before using this method.\n\n"
"Alternatively you can use `mapdl.get` to specify the name of "
"the MAPDL parameter where to store the retrieved value.\n"
)

cmd = f"{entity},{entnum},{item1},{it1num},{item2},{it2num},{item3}, {it3num}, {item4}, {it4num}"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,3 +2117,10 @@ def test_saving_selection_context(mapdl, cube_solve):

assert "nod_selection_4".upper() not in mapdl.cmlist()
assert "nod_selection_4" not in mapdl.components


def test_get_array_non_interactive(mapdl, solved_box):
mapdl.allsel()
with pytest.raises(MapdlRuntimeError):
with mapdl.non_interactive:
mapdl.get_array("asdf", "2")

0 comments on commit 4960a02

Please sign in to comment.