Skip to content

Commit

Permalink
enable mproc for pre-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Nov 2, 2024
1 parent 07b1dd1 commit 8d6a496
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pyxtal/optimize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ def handler(signum, frame):
# Set the timeout signal
cwd = os.getcwd()
timeout = int(args[-1])
logger.info(f"Rank-{args[-2]} entering optimizer_with_timeout")
#logger.info(f"Rank-{args[-2]} entering optimizer_with_timeout")
signal.signal(signal.SIGALRM, handler)
signal.alarm(timeout)
logger.info(f"Rank-{args[-2]} after signal")
#logger.info(f"Rank-{args[-2]} after signal")

try:
logger.info(f"Rank-{args[-2]} running optimizer_par for PID {os.getpid()}")
result = optimizer_par(*args[:-2])
logger.info(f"Rank-{args[-2]} finished optimizer_par for PID {os.getpid()} successfully")
logger.info(f"Rank-{args[-2]} finished optimizer_par for PID {os.getpid()}")
signal.alarm(0) # Disable the alarm
return result
except TimeoutError:
logger.info(f"Rank-{args[-1]} Process {os.getpid()} timed out after {timeout} seconds.")
logger.info(f"Rank-{args[-2]} Process {os.getpid()} timed out after {timeout} seconds.")
os.chdir(cwd)
return None # or some other placeholder for timeout results

# Update process_task to accept a logger
def process_task(args):
logger = logging.getLogger()
logger.info(f"Rank {args[-2]} start process_task.")
#logger.info(f"Rank {args[-2]} start process_task.")
result = run_optimizer_with_timeout(args, logger)
return result

Expand Down Expand Up @@ -786,7 +786,8 @@ def print_matches(self, header=None):
matches = sorted(
self.matches, key=lambda x: -x[4]) # similarity
else:
matches = sorted(self.matches, key=lambda x: x[4]) # rmsd
print(self.matches)
matches = sorted(self.matches, key=lambda x: x[3]) # eng

for match_data in matches:
d1, match = None, None
Expand All @@ -813,7 +814,7 @@ def print_matches(self, header=None):

if e is not None:
rank = len(all_engs[all_engs < (e - 1e-3)]) + 1
strs += f"{rank:d}/{self.N_struc:d} {tag:s}"
strs += f" {rank:d}/{self.N_struc:d} {tag:s}"
ranks.append(rank)

print(strs)
Expand Down Expand Up @@ -1084,11 +1085,10 @@ def generate_args_lists():
+ "-p" + str(id) for id in _ids]
_xtals = [xtals[id][0] for id in range(id1, id2)]
mutates = [False if qrs else xtal is not None for xtal in _xtals]
my_args = [_xtals, _ids, mutates, job_tags, *args, self.timeout]
my_args = [_xtals, _ids, mutates, job_tags, *args, self.rank, self.timeout]
yield tuple(my_args) # Yield args instead of appending to a list

gen_results = []
#for result in pool.imap_unordered(process_task, args_lists):
for result in pool.imap_unordered(process_task, generate_args_lists()):
if result is not None:
for _res in result:
Expand Down
2 changes: 2 additions & 0 deletions pyxtal/optimize/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def optimizer_par(
use_hall,
skip_ani,
check_stable,
pre_opt,
):
"""
A routine used for parallel structure optimization
Expand Down Expand Up @@ -406,6 +407,7 @@ def optimizer_par(
use_hall,
skip_ani,
check_stable,
pre_opt,
)
results.append((id, xtal, match))
return results
Expand Down

0 comments on commit 8d6a496

Please sign in to comment.