Skip to content
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

feat: refactoring launcher module #3649

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
62cf01e
feat: initial refactor. Still missing unit testing on new functions.
germa89 Jan 10, 2025
a5eeedb
chore: merge remote-tracking branch 'origin/main' into refactor/launcher
germa89 Jan 10, 2025
d4ce97e
chore: adding changelog file 3649.miscellaneous.md [dependabot-skip]
pyansys-ci-bot Jan 10, 2025
f57b73b
refactor: rename files
germa89 Jan 10, 2025
f6bb7f8
Merge branch 'refactor/launcher' of https://github.com/ansys/pymapdl …
germa89 Jan 10, 2025
cb2b78e
fix: codacity suggestions
germa89 Jan 10, 2025
1feea58
fix: vulnerabilities
germa89 Jan 10, 2025
d7239a3
fix: missing import
germa89 Jan 10, 2025
c537165
Merge branch 'main' into refactor/launcher
germa89 Jan 14, 2025
840a1a9
Merge branch 'main' into refactor/launcher
germa89 Jan 15, 2025
02d2d61
fix: test message
germa89 Jan 15, 2025
e482ab6
chore: merge remote-tracking branch 'origin/main' into refactor/launcher
germa89 Jan 15, 2025
df93cb3
ci: increase timeout for local
germa89 Jan 15, 2025
36ab642
chore: adding changelog file 3649.maintenance.md [dependabot-skip]
pyansys-ci-bot Jan 15, 2025
9bd866c
ci: adding profiling to pytest
germa89 Jan 16, 2025
b2a7b0e
chore: adding changelog file 3649.dependencies.md [dependabot-skip]
pyansys-ci-bot Jan 16, 2025
bebd49f
fix: plugin registering
germa89 Jan 16, 2025
9263f27
chore: merge remote-tracking branch 'origin/main' into refactor/launcher
germa89 Jan 16, 2025
b5106e1
tests: added unit tests for connect_to_mapdl
germa89 Jan 16, 2025
ca87253
test: testing launch local grpc
germa89 Jan 16, 2025
3a53c83
feat: typing
germa89 Jan 16, 2025
6717331
refactor: move pim tests to its place
germa89 Jan 16, 2025
205f80e
fix: small fixes
germa89 Jan 16, 2025
2b5c8c9
refactor: moving tools tests to test_tools
germa89 Jan 16, 2025
ad4fe52
ci: adding graphviz to dependencies for profiling plotting
germa89 Jan 17, 2025
789cfe5
ci: adding prof file to gitignore
germa89 Jan 17, 2025
aa2ee11
fix: wrong callers
germa89 Jan 17, 2025
fb2ccfb
refactor: test to avoid launch_mapdl
germa89 Jan 21, 2025
e549887
test: remove unnecessary test
germa89 Jan 21, 2025
d52b886
Merge remote-tracking branch 'origin/main' into refactor/launcher
germa89 Jan 21, 2025
c9b82db
chore: adding changelog file 3649.maintenance.md [dependabot-skip]
pyansys-ci-bot Jan 21, 2025
282812c
test: remove redundant tests
germa89 Jan 22, 2025
3c0359b
ci: marking test as flacky. Ref https://github.com/ansys/pymapdl/issu…
germa89 Jan 22, 2025
15d4657
Merge branch 'main' into refactor/launcher
germa89 Jan 23, 2025
dc28563
feat: starting to write launch_mapdl_on_cluster_locally
germa89 Jan 27, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ jobs:
runs-on: ubuntu-22.04
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
timeout-minutes: 120
strategy:
fail-fast: false
matrix: ${{fromJson(needs.build-test-local-minimal-matrix.outputs.matrix)}}
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3649.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: refactoring launcher module
4 changes: 3 additions & 1 deletion src/ansys/mapdl/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@

# override default launcher when on pyansys.com
if "ANSJUPHUB_VER" in os.environ: # pragma: no cover
from ansys.mapdl.core.jupyter import launch_mapdl_on_cluster as launch_mapdl
from ansys.mapdl.core.launcher.jupyter import (
launch_mapdl_on_cluster as launch_mapdl,
)
else:
from ansys.mapdl.core.launcher import launch_mapdl

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/cli/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def stop(port: int, pid: Optional[int], all: bool) -> None:
"""
import psutil

from ansys.mapdl.core.launcher import is_ansys_process
from ansys.mapdl.core.launcher.tools import is_ansys_process

PROCESS_OK_STATUS = [
# List of all process status, comment out the ones that means that
Expand Down
68 changes: 68 additions & 0 deletions src/ansys/mapdl/core/launcher/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (C) 2016 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import warnings

from ansys.mapdl.core import _HAS_ATP, LOG

LOCALHOST = "127.0.0.1"
MAPDL_DEFAULT_PORT = 50052

ON_WSL = os.name == "posix" and (
os.environ.get("WSL_DISTRO_NAME") or os.environ.get("WSL_INTEROP")
)

if ON_WSL:
LOG.info("On WSL: Running on WSL detected.")
LOG.debug("On WSL: Allowing 'start_instance' and 'ip' arguments together.")


from ansys.mapdl.core.launcher.console import launch_mapdl_console
from ansys.mapdl.core.launcher.grpc import launch_mapdl_grpc
from ansys.mapdl.core.launcher.hpc import launch_mapdl_on_cluster_locally
from ansys.mapdl.core.launcher.launcher import launch_mapdl
from ansys.mapdl.core.launcher.remote import connect_to_mapdl
from ansys.mapdl.core.launcher.tools import (
close_all_local_instances,
get_default_ansys,
get_default_ansys_path,
get_default_ansys_version,
)

if _HAS_ATP:
from functools import wraps

from ansys.tools.path import find_mapdl, get_mapdl_path
from ansys.tools.path import version_from_path as _version_from_path

@wraps(_version_from_path)
def version_from_path(*args, **kwargs):
"""Wrap ansys.tool.path.version_from_path to raise a warning if the
executable couldn't be found"""
if kwargs.pop("launch_on_hpc", False):
try:
return _version_from_path(*args, **kwargs)
except RuntimeError:
warnings.warn("PyMAPDL could not find the ANSYS executable. ")
else:
return _version_from_path(*args, **kwargs)
107 changes: 107 additions & 0 deletions src/ansys/mapdl/core/launcher/console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright (C) 2016 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import Optional, Union

from ansys.mapdl.core import LOG
from ansys.mapdl.core.launcher.local import processing_local_arguments
from ansys.mapdl.core.launcher.tools import generate_start_parameters
from ansys.mapdl.core.licensing import LicenseChecker
from ansys.mapdl.core.mapdl_console import MapdlConsole


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


def launch_mapdl_console(
exec_file: Optional[str] = None,
run_location: Optional[str] = None,
jobname: str = "file",
*,
nproc: Optional[int] = None,
ram: Optional[Union[int, str]] = None,
override: bool = False,
loglevel: str = "ERROR",
additional_switches: str = "",
start_timeout: Optional[int] = None,
log_apdl: Optional[Union[bool, str]] = None,
):
########################################
# Processing arguments
# --------------------
#
# processing arguments
args = processing_local_arguments(locals())

# Check for a valid connection mode
if args.get("mode", "console") != "console":
raise ValueError("Invalid 'mode'.")

start_parm = generate_start_parameters(args)

# Early exit for debugging.
if args["_debug_no_launch"]:
# Early exit, just for testing
return args # type: ignore

########################################
# Local launching
# ---------------
#
# Check the license server
if args["license_server_check"]:
LOG.debug("Checking license server.")
lic_check = LicenseChecker(timeout=args["start_timeout"])
lic_check.start()

LOG.debug("Starting MAPDL")
########################################
# Launch MAPDL on console mode
# ----------------------------
#
start_parm = check_console_start_parameters(start_parm)
mapdl = MapdlConsole(
loglevel=args["loglevel"],
log_apdl=args["log_apdl"],
use_vtk=args["use_vtk"],
**start_parm,
)

# Stop license checker
if args["license_server_check"]:
LOG.debug("Stopping check on license server.")
lic_check.stop()

return mapdl
Loading