Skip to content

Commit

Permalink
fix: console launching (#3586)
Browse files Browse the repository at this point in the history
* fix: console launching and at least one test.

* chore: adding changelog file 3586.fixed.md [dependabot-skip]

* chore: adding changelog file 3586.fixed.md [dependabot-skip]

* ci: adding ci/cd for console

* ci: changing coverage files

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Dec 13, 2024
1 parent 43ed236 commit 076d722
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 16 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,114 @@ jobs:
path: ./${{ matrix.mapdl-version }}-minimal.xml


build-test-ubuntu-console:
name: "Local-min-console: ${{ matrix.mapdl-version }}"
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
needs: [smoke-tests, build-test-local-minimal-matrix]
timeout-minutes: 75
strategy:
fail-fast: false
matrix: ${{fromJson(needs.build-test-local-minimal-matrix.outputs.matrix)}}
container:
image: ghcr.io/ansys/mapdl:${{ matrix.mapdl-version }}
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
ON_LOCAL: true
ON_UBUNTU: true
TESTING_MINIMAL: true
ON_CONSOLE: true

steps:
- name: "Install Git and checkout project"
uses: actions/[email protected]
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- name: "Get if running student version"
id: student_check
run: |
if [[ "${{ matrix.mapdl-version }}" == *"student"* ]];
then export ON_STUDENT=true; export TAG_STUDENT="student";
else export ON_STUDENT=false; export TAG_STUDENT="non-student";
fi
echo "ON_STUDENT: $ON_STUDENT"
echo "TAG_STUDENT: $TAG_STUDENT"
echo "ON_STUDENT=$(echo $ON_STUDENT)" >> $GITHUB_OUTPUT
echo "TAG_STUDENT=$(echo $TAG_STUDENT)" >> $GITHUB_OUTPUT
- name: "Installing missing package"
run: |
sudo apt-get update
sudo apt-get install -y libgomp1
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: "Checking Python"
run: |
python --version
python -m pip install --upgrade pip
- name: "Install ansys-mapdl-core"
run: |
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: "Unit testing requirements installation"
run: |
python -m pip install pytest pytest-rerunfailures pytest-cov pytest-random-order
- name: "Unit testing"
env:
ANSYSLMD_LICENSE_FILE: "1055@${{ secrets.LICENSE_SERVER }}"
ON_STUDENT: ${{ steps.student_check.outputs.ON_STUDENT }}
run: |
echo "ON_UBUNTU: $ON_UBUNTU"
echo "ON_STUDENT: $ON_STUDENT"
# Because there is no 'ansys-tools-path' we need to input the
# executable path with the env var: PYMAPDL_MAPDL_EXEC.
if [[ "${{ matrix.mapdl-version }}" == *"latest-ubuntu"* ]] ; then
version=${{ env.LATEST_VERSION }}
else
version=$(echo "${{ matrix.mapdl-version }}" | head -c 5 | tail -c 4 | tr -d '.')
fi;
echo "Version: $version"
export PYMAPDL_MAPDL_EXEC=/ansys_inc/v"$version"/ansys/bin/ansys"$version"
echo "$PYMAPDL_MAPDL_EXEC"
unset PYMAPDL_START_INSTANCE
pytest -k "console" \
${{ env.PYTEST_ARGUMENTS }} \
--cov-report=xml:${{ matrix.mapdl-version }}-minimal-console.xml
- uses: codecov/codecov-action@v5
name: "Upload coverage to Codecov"
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
root_dir: ${{ github.workspace }}
name: ${{ matrix.mapdl-version }}-minimal-console.xml
flags: ubuntu,local,${{ matrix.mapdl-version }},minimal,console,${{ steps.student_check.outputs.TAG_STUDENT }},dmp

- name: "Upload coverage artifacts"
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.mapdl-version }}-minimal-console.xml
path: ./${{ matrix.mapdl-version }}-minimal-console.xml


test-windows:
# Skipped
if: github.repository == ''
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3586.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: console launching
4 changes: 4 additions & 0 deletions src/ansys/mapdl/core/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import weakref

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core.errors import MapdlExitedError


def update_information_first(update=False):
Expand Down Expand Up @@ -122,6 +123,9 @@ def _update(self):
self._mapdl._log.debug("Information class: Updated")

def __repr__(self):
if self._mapdl.is_console and self._mapdl.exited:
return "MAPDL exited"

if not self._stats:
self._update()

Expand Down
18 changes: 18 additions & 0 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ def launch_mapdl(
#
from ansys.mapdl.core.mapdl_console import MapdlConsole

start_parm = check_console_start_parameters(start_parm)
mapdl = MapdlConsole(
loglevel=args["loglevel"],
log_apdl=args["log_apdl"],
Expand Down Expand Up @@ -2101,6 +2102,7 @@ def generate_start_parameters(args: Dict[str, Any]) -> Dict[str, Any]:
start_parm["timeout"] = args["start_timeout"]

start_parm["launched"] = True
start_parm.pop("mode")

LOG.debug(f"Using start parameters {start_parm}")
return start_parm
Expand Down Expand Up @@ -2871,3 +2873,19 @@ def submitter(
stderr=stderr,
env=env_vars,
) # nosec B603 B607


def check_console_start_parameters(start_parm):
valid_args = [
"exec_file",
"run_location",
"jobname",
"nproc",
"additional_switches",
"start_timeout",
]
for each in list(start_parm.keys()):
if each not in valid_args:
start_parm.pop(each)

return start_parm
5 changes: 4 additions & 1 deletion src/ansys/mapdl/core/mapdl_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,18 @@ def __init__(
self._continue_on_error = False
self._process = None
self._name = None
self._session_id = None
self._cleanup = None

self._launch(start_parm)
super().__init__(
loglevel=loglevel,
use_vtk=use_vtk,
log_apdl=log_apdl,
print_com=print_com,
mode="console",
**start_parm,
)
self._mode = "console"

def _launch(self, start_parm):
"""Connect to MAPDL process using pexpect"""
Expand Down
6 changes: 5 additions & 1 deletion src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"jobid",
"jobname",
"launch_on_hpc",
"mode",
"nproc",
"override",
"port",
Expand Down Expand Up @@ -252,7 +253,7 @@ def __init__(
self._store_commands: bool = False
self._stored_commands = []
self._response = None
self._mode = None
self._mode = start_parm.get("mode", None)
self._mapdl_process = None
self._launched: bool = start_parm.get("launched", False)
self._stderr = None
Expand Down Expand Up @@ -1290,6 +1291,9 @@ def inner_wrapper(*args, **kwargs):

def _wrap_xsel_commands(self):
# Wrapping XSEL commands.
if self.is_console:
return

def wrap_xsel_function(func):
if hasattr(func, "__func__"):
func.__func__.__doc__ = inject_docs(
Expand Down
1 change: 1 addition & 0 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def __init__(
log_apdl=log_apdl,
log_file=log_file,
print_com=print_com,
mode="grpc",
**start_parm,
)
self._mode: Literal["grpc"] = "grpc"
Expand Down
15 changes: 4 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def requires_dependency(dependency: str):
# ------------------
#

if has_dependency("ansys-tools-package"):
from ansys.tools.path import find_mapdl, get_available_ansys_installations
if has_dependency("ansys-tools-path"):
from ansys.tools.path import find_mapdl


if has_dependency("pyvista"):
Expand Down Expand Up @@ -537,14 +537,7 @@ def mapdl_console(request):
raise MapdlRuntimeError(
'"--console" testing option unavailable. ' "Only Linux is supported."
)
ansys_base_paths = get_available_ansys_installations()

# find a valid version of console
console_path = None
for version in ansys_base_paths:
version = abs(version)
if version < 211:
console_path = find_mapdl(str(version))[0]
console_path = find_mapdl()[0]

if console_path is None:
raise MapdlRuntimeError(
Expand All @@ -553,7 +546,7 @@ def mapdl_console(request):
"Valid versions are up to 2020R2."
)

mapdl = launch_mapdl(console_path, log_apdl=LOG_APDL)
mapdl = launch_mapdl(console_path, mode="console", log_apdl=LOG_APDL)
from ansys.mapdl.core.mapdl_console import MapdlConsole

assert isinstance(mapdl, MapdlConsole)
Expand Down
12 changes: 9 additions & 3 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import pytest

from conftest import has_dependency, requires
from conftest import clear, has_dependency, requires

# skip entire module unless --console is enabled
pytestmark = requires("console")
Expand All @@ -48,6 +48,11 @@
from ansys.mapdl.core.errors import MapdlRuntimeError


@pytest.fixture(scope="function")
def cleared(mapdl_console):
clear(mapdl_console)


@pytest.fixture(scope="function")
def make_block(mapdl_console, cleared):
mapdl_console.block(0, 1, 0, 1, 0, 1)
Expand All @@ -74,7 +79,7 @@ def test_empty(mapdl_console, cleared):


def test_str(mapdl_console, cleared):
assert "ANSYS Mechanical" in str(mapdl_console)
assert "Ansys Mechanical" in str(mapdl_console)


def test_version(mapdl_console, cleared):
Expand Down Expand Up @@ -127,6 +132,7 @@ def test_chaining(mapdl_console, cleared):


def test_e(mapdl_console, cleared):
mapdl.prep7()
mapdl_console.et("", 183)
n0 = mapdl_console.n("", 0, 0, 0)
n1 = mapdl_console.n("", 1, 0, 0)
Expand Down Expand Up @@ -362,7 +368,7 @@ def test_nodes(tmpdir, cleared, mapdl_console):
basename = "tmp.nodes"
filename = str(tmpdir.mkdir("tmpdir").join(basename))
mapdl_console.nwrite(filename)
mapdl_console.download(basename, filename)
# mapdl_console.download(basename, filename)

assert np.allclose(mapdl_console.mesh.nodes, np.loadtxt(filename)[:, 1:])
assert mapdl_console.mesh.n_node == 11
Expand Down

0 comments on commit 076d722

Please sign in to comment.