Skip to content

Commit

Permalink
Merge pull request #1044 from Libensemble/study/performance
Browse files Browse the repository at this point in the history
small adjusts to start performance studies
  • Loading branch information
jlnav committed Aug 2, 2023
2 parents e6e4e2d + 2838107 commit 42ad8e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
6 changes: 1 addition & 5 deletions libensemble/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging
import os
import platform
import pstats
import socket
import sys
import time
Expand Down Expand Up @@ -132,10 +131,7 @@ def manager_main(
if libE_specs.get("profile"):
pr.disable()
profile_stats_fname = "manager.prof"

with open(profile_stats_fname, "w") as f:
ps = pstats.Stats(pr, stream=f).sort_stats("cumulative")
ps.print_stats()
pr.dump_stats(profile_stats_fname)

return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
nworkers, is_manager, libE_specs, _ = parse_args()

libE_specs["profile"] = True
libE_specs["safe_mode"] = False
libE_specs["kill_canceled_sims"] = False

sim_specs = {
"sim_f": sim_f,
Expand All @@ -48,7 +50,7 @@

persis_info = add_unique_random_streams({}, nworkers + 1)

exit_criteria = {"gen_max": 501}
exit_criteria = {"sim_max": 1e5}

# Perform the run
H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs)
Expand All @@ -58,7 +60,7 @@
print("\nlibEnsemble with random sampling has generated enough points")

assert "manager.prof" in os.listdir(), "Expected manager profile not found after run"
os.remove("manager.prof")
# os.remove("manager.prof")

prof_files = [f"worker_{i+1}.prof" for i in range(nworkers)]

Expand All @@ -67,11 +69,11 @@

for file in prof_files:
assert file in os.listdir(), "Expected profile {file} not found after run"
with open(file, "r") as f:
data = f.read().split()
num_worker_funcs_profiled = sum(["worker" in i for i in data])
assert num_worker_funcs_profiled >= 8, (
"Insufficient number of " + "worker functions profiled: " + str(num_worker_funcs_profiled)
)

os.remove(file)
# with open(file, "r") as f:
# data = f.read().split()
# num_worker_funcs_profiled = sum(["worker" in i for i in data])
# assert num_worker_funcs_profiled >= 8, (
# "Insufficient number of " + "worker functions profiled: " + str(num_worker_funcs_profiled)
# )

# os.remove(file)
6 changes: 1 addition & 5 deletions libensemble/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import cProfile
import logging
import logging.handlers
import pstats
import socket
from itertools import count
from pathlib import Path
Expand Down Expand Up @@ -114,10 +113,7 @@ def worker_main(
if libE_specs.get("profile"):
pr.disable()
profile_state_fname = "worker_%d.prof" % (workerID)

with open(profile_state_fname, "w") as f:
ps = pstats.Stats(pr, stream=f).sort_stats("cumulative")
ps.print_stats()
pr.dump_stats(profile_state_fname)


######################################################################
Expand Down

0 comments on commit 42ad8e7

Please sign in to comment.