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

perf: reduce-testing-time #3427

Merged
merged 24 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e606a62
feat: packing locals in launch_mapdl for debugging
germa89 Sep 23, 2024
d66bcb5
perf: reducing testing time of licensing
germa89 Sep 23, 2024
abdf809
chore: adding changelog file 3427.added.md
pyansys-ci-bot Sep 23, 2024
73695d4
perf: improving testing on pool.
germa89 Sep 23, 2024
b732969
perf: checking just sending the message or not.
germa89 Sep 23, 2024
52270f9
fix: find_version test
germa89 Sep 23, 2024
e86de49
feat: using cache for path
Sep 23, 2024
03d3204
refactor: moving call later.
Sep 23, 2024
fdc2982
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 23, 2024
121bdff
chore: empty commit to trigger CICD
Sep 23, 2024
7f1d6f9
fix: rename job to pull-request
Sep 23, 2024
d4c015c
Merge branch 'perf/reduce-testing-time' of https://github.com/ansys/p…
germa89 Sep 23, 2024
638a36b
Merge branch 'main' into perf/reduce-testing-time
germa89 Sep 24, 2024
594ee18
feat: cache directory at starting
germa89 Sep 24, 2024
61c33f8
feat: adding 'fake_exit' to mapdl.exit
germa89 Sep 24, 2024
05bd04d
feat: adding early exit in flush_stored
germa89 Sep 24, 2024
224b0f0
fix: test
germa89 Sep 24, 2024
2ec8b2b
revert: "feat: adding early exit in flush_stored"
germa89 Sep 25, 2024
2a84c40
fix: wrong indentation and adding early exit.
germa89 Sep 25, 2024
70cc6d0
fix: adding early exit to _flush_stored in mapdlgrpc.
germa89 Sep 25, 2024
8d00cdd
test: reducing testing time in test_only_one_instance
germa89 Sep 25, 2024
762240a
fix: test key
germa89 Sep 25, 2024
b10ff10
fix: test instance name
germa89 Sep 25, 2024
5e037e6
fix: test instance name
germa89 Sep 25, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ jobs:
uses: ansys/actions/branch-name-style@v7


commit-name:
pull-request-name:
if: github.event_name == 'pull_request'
name: Check the name of the commit
name: Check the name of the pull-request
runs-on: ubuntu-latest
steps:
- name: Check commit name
- name: Check pull-request name
uses: ansys/actions/commit-style@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3427.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perf: reduce-testing-time
76 changes: 18 additions & 58 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1663,21 +1663,7 @@ def launch_mapdl(
return

if _debug_no_launch:
return pack_parameters(
port,
ip,
add_env_vars,
replace_env_vars,
cleanup_on_exit,
loglevel,
set_no_abort,
remove_temp_dir_on_exit,
log_apdl,
use_vtk,
start_parm,
start_instance,
version,
) # type: ignore
return pack_parameters(locals()) # type: ignore

mapdl = MapdlGrpc(
ip=ip,
Expand Down Expand Up @@ -1821,21 +1807,7 @@ def launch_mapdl(
elif mode == "grpc":
if _debug_no_launch:
# Early exit, just for testing
return pack_parameters(
port,
ip,
add_env_vars,
replace_env_vars,
cleanup_on_exit,
loglevel,
set_no_abort,
remove_temp_dir_on_exit,
log_apdl,
use_vtk,
start_parm,
start_instance,
version,
) # type: ignore
return pack_parameters(locals()) # type: ignore

port, actual_run_location, process = launch_grpc(
port=port,
Expand Down Expand Up @@ -2283,34 +2255,22 @@ def get_value(
return exec_file, jobname, nproc, ram, additional_switches


def pack_parameters(
port,
ip,
add_env_vars,
replace_env_vars,
cleanup_on_exit,
loglevel,
set_no_abort,
remove_temp_dir_on_exit,
log_apdl,
use_vtk,
start_parm,
start_instance,
version,
):
def pack_parameters(locals_var):
# pack all the arguments in a dict for debugging purposes
# We prefer to explicitly output the desired output
dict_ = {}
dict_["port"] = port
dict_["ip"] = ip
dict_["add_env_vars"] = add_env_vars
dict_["replace_env_vars"] = replace_env_vars
dict_["cleanup_on_exit"] = cleanup_on_exit
dict_["loglevel"] = loglevel
dict_["set_no_abort"] = set_no_abort
dict_["remove_temp_dir_on_exit"] = remove_temp_dir_on_exit
dict_["log_apdl"] = log_apdl
dict_["use_vtk"] = use_vtk
dict_["start_parm"] = start_parm
dict_["start_instance"] = start_instance
dict_["version"] = version
dict_["port"] = locals_var["port"]
dict_["ip"] = locals_var["ip"]
dict_["add_env_vars"] = locals_var["add_env_vars"]
dict_["replace_env_vars"] = locals_var["replace_env_vars"]
dict_["cleanup_on_exit"] = locals_var["cleanup_on_exit"]
dict_["loglevel"] = locals_var["loglevel"]
dict_["set_no_abort"] = locals_var["set_no_abort"]
dict_["remove_temp_dir_on_exit"] = locals_var["remove_temp_dir_on_exit"]
dict_["log_apdl"] = locals_var["log_apdl"]
dict_["use_vtk"] = locals_var["use_vtk"]
dict_["start_parm"] = locals_var["start_parm"]
dict_["start_instance"] = locals_var["start_instance"]
dict_["version"] = locals_var["version"]
dict_["additional_switches"] = locals_var["additional_switches"]
return dict_
47 changes: 29 additions & 18 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
self._start_parm: Dict[str, Any] = start_parm
self._jobname: str = start_parm.get("jobname", "file")
self._path: Union[str, pathlib.Path] = start_parm.get("run_location", None)
self._path_cache = None # Cache
self._print_com: bool = print_com # print the command /COM input.
self.check_parameter_names = start_parm.get("check_parameter_names", True)

Expand Down Expand Up @@ -510,10 +511,14 @@
# new line to fix path issue, see #416
self._path = repr(self._path)[1:-1]
else: # pragma: no cover
raise IOError(
f"The directory returned by /INQUIRE is not valid ('{self._path}')."
)
if self._path_cache:
return self._path_cache
else:
raise IOError(
f"The directory returned by /INQUIRE is not valid ('{self._path}')."
)

self._path_cache = self._path # update
return self._path

@directory.setter
Expand Down Expand Up @@ -1895,7 +1900,13 @@
Overridden by gRPC.

"""
if not self._stored_commands:
self._log.debug("There is no commands to be flushed.")
self._store_commands = False
return

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_core.py#L1903-L1906

Added lines #L1903 - L1906 were not covered by tests

self._log.debug("Flushing stored commands")

rnd_str = random_string()
tmp_out = os.path.join(tempfile.gettempdir(), f"tmp_{rnd_str}.out")
self._stored_commands.insert(0, f"/OUTPUT, {tmp_out}")
Expand All @@ -1904,25 +1915,25 @@
if self._apdl_log:
self._apdl_log.write(commands + "\n")

self._store_commands = False
self._stored_commands = []
self._store_commands = False
self._stored_commands = []

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_core.py#L1918-L1919

Added lines #L1918 - L1919 were not covered by tests

# write to a temporary input file
self._log.debug(
"Writing the following commands to a temporary " "apdl input file:\n%s",
commands,
)
# write to a temporary input file
self._log.debug(

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_core.py#L1922

Added line #L1922 was not covered by tests
"Writing the following commands to a temporary " "apdl input file:\n%s",
commands,
)

tmp_inp = os.path.join(tempfile.gettempdir(), f"tmp_{random_string()}.inp")
with open(tmp_inp, "w") as f:
f.writelines(commands)
tmp_inp = os.path.join(tempfile.gettempdir(), f"tmp_{random_string()}.inp")
with open(tmp_inp, "w") as f:
f.writelines(commands)

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_core.py#L1927-L1929

Added lines #L1927 - L1929 were not covered by tests

# interactive result
_ = self.input(tmp_inp, write_to_log=False)
# interactive result
_ = self.input(tmp_inp, write_to_log=False)

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_core.py#L1932

Added line #L1932 was not covered by tests

time.sleep(0.1) # allow MAPDL to close the file
if os.path.isfile(tmp_out):
self._response = "\n" + open(tmp_out).read()
time.sleep(0.1) # allow MAPDL to close the file
if os.path.isfile(tmp_out):
self._response = "\n" + open(tmp_out).read()

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_core.py#L1934-L1936

Added lines #L1934 - L1936 were not covered by tests

if self._response is None: # pragma: no cover
self._log.warning("Unable to read response from flushed commands")
Expand Down
28 changes: 18 additions & 10 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@
with self.run_as_routine("POST26"):
self.numvar(200, mute=True)

self.inquire("", "DIRECTORY")
self.show(self._file_type_for_plots)
self.version # Caching version
self.file_type_for_plots # Setting /show,png and caching it.
Expand Down Expand Up @@ -1038,7 +1039,7 @@
continue

@protect_from(ValueError, "I/O operation on closed file.")
def exit(self, save=False, force=False):
def exit(self, save=False, force=False, **kwargs):
"""Exit MAPDL.

Parameters
Expand Down Expand Up @@ -1069,8 +1070,6 @@
elif self._exited:
# Already exited.
return
else:
mapdl_path = self.directory

if save:
self._log.debug("Saving MAPDL database")
Expand All @@ -1094,17 +1093,21 @@
self._exiting = True
self._log.debug("Exiting MAPDL")

if self._local:
self._cache_pids() # Recache processes
if not kwargs.pop("fake_exit", False):
# This cannot should not be faked
if self._local:
mapdl_path = self.directory
self._cache_pids() # Recache processes

if os.name == "nt":
if os.name == "nt":
self._kill_server()

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

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1103

Added line #L1103 was not covered by tests
self._close_process()
self._remove_lock_file(mapdl_path)
else:
self._kill_server()
self._close_process()
self._remove_lock_file(mapdl_path)
else:
self._kill_server()

self._exited = True
self._exiting = False

if self._remote_instance: # pragma: no cover
# No cover: The CI is working with a single MAPDL instance
Expand Down Expand Up @@ -2031,6 +2034,11 @@
"""Writes stored commands to an input file and runs the input
file. Used with non_interactive.
"""
if not self._stored_commands:
self._log.debug("There is no commands to be flushed.")
self._store_commands = False
return

self._log.debug("Flushing stored commands")

commands = "\n".join(self._stored_commands)
Expand Down
8 changes: 6 additions & 2 deletions src/ansys/mapdl/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(
self._n_instances = n_instances

# Getting debug arguments
_debug_no_launch = kwargs.pop("_debug_no_launch", None)
_debug_no_launch = kwargs.get("_debug_no_launch", None)

if run_location is None:
run_location = create_temp_dir()
Expand Down Expand Up @@ -338,7 +338,6 @@ def __init__(
"exec_file": exec_file,
"n_instances": n_instances,
}
return

# Converting ip or hostname to ip
self._ips = [socket.gethostbyname(each) for each in self._ips]
Expand All @@ -357,6 +356,11 @@ def __init__(
)
for i, (ip, port) in enumerate(zip(ips, ports))
]

# Early exit due to debugging
if _debug_no_launch:
return

if wait:
[thread.join() for thread in threads]

Expand Down
Loading
Loading