Skip to content

Commit

Permalink
Merge branch 'main' into feat/moving-functions-to-mapdl-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Nov 20, 2023
2 parents ae34972 + 286f90e commit b7c8f92
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 29 deletions.
15 changes: 0 additions & 15 deletions .ci/run_vms.py

This file was deleted.

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)
15 changes: 7 additions & 8 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 @@ -502,7 +502,7 @@ jobs:
- name: "Install OS packages"
run: |
apt update
apt install -y libgl1-mesa-glx xvfb
apt install -y libgl1-mesa-glx xvfb libgomp1
- name: "Test virtual framebuffer"
run: |
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 Expand Up @@ -628,12 +628,11 @@ jobs:
python -m pip install . --no-deps
python -m pip install -r minimum_requirements.txt
python -c "from ansys.mapdl import core as pymapdl; print('Import successfull')"
- name: "Running some verification manual examples"
- name: "Installing missing package"
run: |
unset PYMAPDL_START_INSTANCE
export ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}
python .ci/run_vms.py
sudo apt-get update
sudo apt-get install -y libgomp1
- name: "Unit testing requirements installation"
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ repos:

# this validates our github workflow files
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
rev: 0.27.1
hooks:
- id: check-github-workflows
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ coverage:
if_ci_failed: error
if_no_uploads: error
threshold: 4% # Because some tests are flaky.

codecov:
notify:
wait_for_ci: yes
# do not notify until at least 5 builds have been uploaded from the CI pipeline
after_n_builds: 5
comment:
after_n_builds: 5
2 changes: 2 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@
rst_epilog += f.read()

rst_epilog = rst_epilog.replace("%%VERSION%%", "v231")
rst_epilog = rst_epilog.replace("%%PYMAPDLVERSION%%", release)


# Read link all substitutions from file
with open("substitutions.rst") as f:
Expand Down
2 changes: 2 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ Documentation and issues
------------------------
Documentation for the latest stable release of PyMAPDL is hosted at `PyMAPDL documentation
<https://mapdl.docs.pyansys.com/version/stable/>`_.
The same documentation is also `available as PDF <pymapdl_latest_pdf_doc_>`_ in the `Assets` section in the
`latest GitHub package release <pymapdl_latest_github_release_>`_.

In the upper right corner of the documentation's title bar, there is an option for switching from
viewing the documentation for the latest stable release to viewing the documentation for the
Expand Down
3 changes: 3 additions & 0 deletions doc/source/links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
.. _pymapdl_discussion_differences_mapdl_pymapdl: https://github.com/ansys/pymapdl-reader/issues/185
.. _cartpole_example_notebook: https://cartpole.mapdl.docs.pyansys.com/ml-rl-notebook.html
.. _wsl_launching_mapdl: https://github.com/ansys/pymapdl/issues/2315
.. _pymapdl_latest_github_release: https://github.com/ansys/pymapdl/releases/latest
.. _pymapdl_latest_pdf_doc: https://github.com/ansys/pymapdl/releases/download/v%%PYMAPDLVERSION%%.0/pymapdl-Documentation-%%PYMAPDLVERSION%%.0.pdf


.. #Python
.. _using_venv: https://docs.python.org/3/library/venv.html
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(
"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:
# Return early
return None

# 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 @@ -2184,3 +2184,10 @@ def test_vwrite(mapdl):

assert "hello" == content.strip()
os.remove("test_vwrite.txt")


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 b7c8f92

Please sign in to comment.