Skip to content

Raising error if using non allowed argument #2010

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

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 11 additions & 3 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,16 @@ def launch_mapdl(
verbose_mapdl = False

# These parameters are partially used for unit testing
set_no_abort = kwargs.get("set_no_abort", True)
set_no_abort = kwargs.pop("set_no_abort", True)

# Extract arguments:
force_intel = kwargs.pop("force_intel", False)
broadcast = kwargs.pop("log_broadcast", False)

# Raising error if using non-allowed arguments
if kwargs:
ms_ = ", ".join([f"'{each}'" for each in kwargs.keys()])
raise ValueError(f"The following arguments are not recognaised: {ms_}")

if ip is None:
ip = os.environ.get("PYMAPDL_IP", LOCALHOST)
Expand Down Expand Up @@ -1494,7 +1503,7 @@ def launch_mapdl(

#
additional_switches = _validate_MPI(
additional_switches, exec_file, kwargs.pop("force_intel", False)
additional_switches, exec_file, force_intel=force_intel
)

additional_switches = _check_license_argument(license_type, additional_switches)
Expand Down Expand Up @@ -1540,7 +1549,6 @@ def launch_mapdl(
" with:\n\npip install ansys_corba"
) from None

broadcast = kwargs.get("log_broadcast", False)
mapdl = MapdlCorba(
loglevel=loglevel,
log_apdl=log_apdl,
Expand Down
35 changes: 30 additions & 5 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ def setup_logger(loglevel="INFO", log_file=True, mapdl_instance=None):
return setup_logger.log


_ALLOWED_START_PARM = [
"additional_switches",
"exec_file",
"ip",
"jobname",
"local",
"nproc",
"override",
"port",
"print_com",
"process",
"ram",
"run_location",
"start_timeout" "timeout",
]


def _sanitize_start_parm(start_parm):
for each_key in start_parm:
if each_key not in _ALLOWED_START_PARM:
raise ValueError(f"The argument '{each_key}' is not recognaised.")


class _MapdlCore(Commands):
"""Contains methods in common between all Mapdl subclasses"""

Expand Down Expand Up @@ -193,18 +216,20 @@ def __init__(
self._log_filehandler = None
self._version = None # cached version
self._local = local
self._jobname = start_parm.get("jobname", "file")
self._cleanup = True
self._vget_arr_counter = 0
self._start_parm = start_parm
self._path = start_parm.get("run_location", None)
self._print_com = print_com # print the command /COM input.
self._cached_routine = None
self._geometry = None
self._kylov = None
self._krylov = None
self._on_docker = None
self._platform = None

_sanitize_start_parm(start_parm)
self._start_parm = start_parm
self._jobname = start_parm.get("jobname", "file")
self._path = start_parm.get("run_location", None)
self._print_com = print_com # print the command /COM input.

# Setting up loggers
self._log = logger.add_instance_logger(
self.name, self, level=loglevel
Expand Down
9 changes: 4 additions & 5 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ def __init__(
self._channel = channel

# connect and validate to the channel
process = start_parm.pop("process", None)
self._mapdl_process = process
self._mapdl_process = start_parm.pop("process", None)

# Queueing the stds
if self._mapdl_process:
Expand Down Expand Up @@ -2514,12 +2513,12 @@ def krylov(self):
:class:`Krylov class <ansys.mapdl.core.krylov.KrylovSolver>`

"""
if self._kylov is None:
if self._krylov is None:
from ansys.mapdl.core.krylov import KrylovSolver

self._kylov = KrylovSolver(self)
self._krylov = KrylovSolver(self)

return self._kylov
return self._krylov

@property
def db(self):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,13 @@ def test_is_ubuntu():
)
def test_get_default_ansys():
assert get_default_ansys() is not None


def test_launch_mapdl_non_recognaised_arguments():
with pytest.raises(ValueError, match="my_fake_argument"):
launch_mapdl(my_fake_argument="my_fake_value")


def test_mapdl_non_recognaised_arguments():
with pytest.raises(ValueError, match="my_fake_argument"):
pymapdl.Mapdl(my_fake_argument="my_fake_value")