From 84883a2c7deabfc40af48d0a194a79889b5f2e3e Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Wed, 15 Nov 2023 23:49:09 +1000 Subject: [PATCH 01/37] parallel gyre.in fix --- mesaport/ProjectOps/ops_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 410868f..ac85abb 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -39,13 +39,13 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, """ if gyre_in is not None: gyre_obj = GyreAccess(wdir) - if not os.path.exists(os.join(wdir, "gyre.in")): - gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") + else: + gyre_obj.load(gyre_in=gyre_in, dest=wdir) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(gyre_input_params) From c969ffe81861b71620ce9e39e9315638eb938cc8 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Wed, 15 Nov 2023 23:56:13 +1000 Subject: [PATCH 02/37] parallel gyre.in fix --- mesaport/ProjectOps/ops_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index ac85abb..410868f 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -39,13 +39,13 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, """ if gyre_in is not None: gyre_obj = GyreAccess(wdir) + if not os.path.exists(os.join(wdir, "gyre.in")): + gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") - else: - gyre_obj.load(gyre_in=gyre_in, dest=wdir) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(gyre_input_params) From cf39e482d94def0151cb0442d89e05fb79ae2614 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Wed, 15 Nov 2023 23:57:40 +1000 Subject: [PATCH 03/37] parallel gyre.in fix --- mesaport/ProjectOps/ops_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 410868f..f7c4be9 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -39,7 +39,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, """ if gyre_in is not None: gyre_obj = GyreAccess(wdir) - if not os.path.exists(os.join(wdir, "gyre.in")): + if not os.path.exists(os.path.join(wdir, "gyre.in")): gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] From 789746c7088e28fa3b80abcfb72bcce3518bd3e3 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:00:57 +1000 Subject: [PATCH 04/37] parallel gyre.in fix --- mesaport/ProjectOps/ops_helper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index f7c4be9..712b1d4 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -39,13 +39,15 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, """ if gyre_in is not None: gyre_obj = GyreAccess(wdir) - if not os.path.exists(os.path.join(wdir, "gyre.in")): - gyre_obj.load(gyre_in=gyre_in, dest=wdir) + # if not os.path.exists(os.path.join(wdir, "gyre.in")): + # gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") + else: + shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(gyre_input_params) From 67970827eb3bc2925daa012cfc961e2d8005a877 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:06:49 +1000 Subject: [PATCH 05/37] parallel gyre.in fix --- mesaport/ProjectOps/ops_helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 712b1d4..8f971d7 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -48,6 +48,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, commands = commands.replace("gyre.in", f"gyre{num}.in") else: shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) + gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(gyre_input_params) From 99c5ffccdaa6c2f2812c07d408c213bdf110ba91 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:16:46 +1000 Subject: [PATCH 06/37] parallel gyre.in fix --- mesaport/ProjectOps/ops_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 8f971d7..1a8b2e2 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -50,7 +50,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - gyre_obj.set(gyre_input_params) + gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) evo_terminated = False termination_code = None From 09b3c75812ef8a28ef3322be16e6ff77f0e43052 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:21:08 +1000 Subject: [PATCH 07/37] parallel gyre.in fix --- mesaport/ProjectOps/project_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index b4362f2..068a410 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -381,7 +381,7 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr repeat(silent), repeat(runlog), repeat(None), files, repeat(data_format), repeat(True), repeat(gyre_in), - gyre_input_params, repeat(None), repeat(env)) + gyre_input_params, repeat(None), repeat(os.environ.copy())) if n_cores is None: n_cores = psutil.cpu_count(logical=True) Pool = mp.Pool From 2750ba326c4122082e4fb74572ce065d1ac66cf6 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:26:45 +1000 Subject: [PATCH 08/37] test --- mesaport/ProjectOps/ops_helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 1a8b2e2..53026a4 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -1,6 +1,6 @@ import subprocess import shlex -import sys, os, glob +import sys, os, glob, time import shutil from rich import print @@ -46,6 +46,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") + time.sleep(1) else: shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") From 880fa4c75abe27fee79cfd5b41bfacc935a01db3 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:29:29 +1000 Subject: [PATCH 09/37] test --- mesaport/ProjectOps/ops_helper.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 53026a4..e99dcaf 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -104,12 +104,6 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, sys.stdout.write(errline) logfile.write( "\n\n"+("*"*100)+"\n\n" ) _data, error = proc.communicate() - if gyre_in is not None: - working_dir = wdir.replace("LOGS", "") - with open(f'{working_dir}/gyre.log', 'a+') as f: - f.write(f"Done with {filename}.\n") - if parallel: - os.remove(gyre_in) if proc.returncode or error: print('The process raised an error:', proc.returncode, error) return False @@ -125,6 +119,11 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, age = age_ return termination_code, age else: + working_dir = wdir.replace("LOGS", "") + with open(f'{working_dir}/gyre.log', 'a+') as f: + f.write(f"Done with {filename}.\n") + if parallel: + os.remove(gyre_in) return True def process_outline(outline): From 0953fe6261e27bb114501bfd15398a8c889f6e5f Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:35:43 +1000 Subject: [PATCH 10/37] test --- mesaport/ProjectOps/ops_helper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index e99dcaf..ae244bf 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -43,12 +43,14 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] - shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) + # shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) + subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, f'gyre{num}.in')}")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") time.sleep(1) else: - shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) + # shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) + subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, 'gyre.in')}")) gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) From 5462c0f926d1fad38b79e9670d6637cc430d7f38 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:38:14 +1000 Subject: [PATCH 11/37] test --- mesaport/ProjectOps/ops_helper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index ae244bf..28df5d1 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -44,13 +44,12 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, if parallel: num = filename.split(".")[0] # shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) - subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, f'gyre{num}.in')}")) + subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, f'gyre{num}.in')}"), shell=True).wait() gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") - time.sleep(1) else: # shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) - subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, 'gyre.in')}")) + subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, 'gyre.in')}"), shell=True).wait() gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) From 80a16913fb3866abb1475eb2d332e9f44f9ac076 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:40:16 +1000 Subject: [PATCH 12/37] test --- mesaport/ProjectOps/ops_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 28df5d1..e203e03 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -44,12 +44,12 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, if parallel: num = filename.split(".")[0] # shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) - subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, f'gyre{num}.in')}"), shell=True).wait() + subprocess.Popen(f"cp {gyre_in} {os.path.join(wdir, f'gyre{num}.in')}", shell=True).wait() gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") else: # shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) - subprocess.Popen(shlex.split(f"cp {gyre_in} {os.path.join(wdir, 'gyre.in')}"), shell=True).wait() + subprocess.Popen(f"cp {gyre_in} {os.path.join(wdir, 'gyre.in')}", shell=True).wait() gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) From 229405fb904cc89d3ae66db8485c0d5dcd0315c1 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:45:01 +1000 Subject: [PATCH 13/37] test --- mesaport/Access/gyre_access.py | 1 - mesaport/ProjectOps/ops_helper.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/mesaport/Access/gyre_access.py b/mesaport/Access/gyre_access.py index 8d93b23..504bdd7 100644 --- a/mesaport/Access/gyre_access.py +++ b/mesaport/Access/gyre_access.py @@ -32,7 +32,6 @@ def __init__(self, path, binary=False, target=''): self.binary = binary self.target = target self.projectDir = os.path.abspath(path) - self.gyre_in = None def check_env(self): """ diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index e203e03..65741d3 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -120,6 +120,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, age = age_ return termination_code, age else: + del gyre_obj working_dir = wdir.replace("LOGS", "") with open(f'{working_dir}/gyre.log', 'a+') as f: f.write(f"Done with {filename}.\n") From 38d294aa1221867ad852dc735659a9a1a9cfe6cd Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:50:15 +1000 Subject: [PATCH 14/37] test --- mesaport/ProjectOps/ops_helper.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 65741d3..e0ee2a7 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -43,16 +43,14 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] - # shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) - subprocess.Popen(f"cp {gyre_in} {os.path.join(wdir, f'gyre{num}.in')}", shell=True).wait() + shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") else: - # shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) - subprocess.Popen(f"cp {gyre_in} {os.path.join(wdir, 'gyre.in')}", shell=True).wait() + shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) + # gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) evo_terminated = False termination_code = None @@ -120,7 +118,6 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, age = age_ return termination_code, age else: - del gyre_obj working_dir = wdir.replace("LOGS", "") with open(f'{working_dir}/gyre.log', 'a+') as f: f.write(f"Done with {filename}.\n") From 95b42617f126a5677266beef192549809af63c1b Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:51:59 +1000 Subject: [PATCH 15/37] test --- mesaport/ProjectOps/ops_helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index e0ee2a7..0b883aa 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -43,14 +43,14 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] - shutil.copy(gyre_in, os.path.join(wdir, f"gyre{num}.in")) + shutil.copy2(gyre_in, os.path.join(wdir, f"gyre{num}.in")) gyre_in = os.path.join(wdir, f"gyre{num}.in") commands = commands.replace("gyre.in", f"gyre{num}.in") else: - shutil.copy(gyre_in, os.path.join(wdir, f"gyre.in")) + shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - # gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) + gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) evo_terminated = False termination_code = None From 0f1d768c25448f85dc401ec8b4c0276fa5f8be85 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:53:56 +1000 Subject: [PATCH 16/37] test --- mesaport/ProjectOps/ops_helper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 0b883aa..575b22f 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -43,8 +43,11 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: num = filename.split(".")[0] - shutil.copy2(gyre_in, os.path.join(wdir, f"gyre{num}.in")) - gyre_in = os.path.join(wdir, f"gyre{num}.in") + new_gyre_in = os.path.join(wdir, f"gyre{num}.in") + if os.path.exists(new_gyre_in): + os.remove(new_gyre_in) + shutil.copy2(gyre_in, new_gyre_in) + gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") else: shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) From 851a26dd7a866f8302934d1421acb8b51cf10796 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:57:02 +1000 Subject: [PATCH 17/37] test --- mesaport/ProjectOps/ops_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 575b22f..60eb15e 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -38,7 +38,6 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, Pass os.environ.copy() to use the current environment. Or pass a dictionary with the environment variables to be used. """ if gyre_in is not None: - gyre_obj = GyreAccess(wdir) # if not os.path.exists(os.path.join(wdir, "gyre.in")): # gyre_obj.load(gyre_in=gyre_in, dest=wdir) if parallel: @@ -52,6 +51,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, else: shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") + gyre_obj = GyreAccess(wdir) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) From b1e088a5cc04ee65d11e01cf170e38f2b396114c Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 00:59:05 +1000 Subject: [PATCH 18/37] test --- mesaport/ProjectOps/ops_helper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 60eb15e..7b86eb7 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -45,11 +45,13 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, new_gyre_in = os.path.join(wdir, f"gyre{num}.in") if os.path.exists(new_gyre_in): os.remove(new_gyre_in) - shutil.copy2(gyre_in, new_gyre_in) + # shutil.copy2(gyre_in, new_gyre_in) + shutil.copyfile(gyre_in, new_gyre_in) gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") else: - shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) + # shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) + shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") gyre_obj = GyreAccess(wdir) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) From 2231c504f86ef4c5f0c0c9efd4ecda44931bf40a Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:00:00 +1000 Subject: [PATCH 19/37] test --- mesaport/ProjectOps/ops_helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 7b86eb7..8db74f9 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -53,9 +53,9 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") - gyre_obj = GyreAccess(wdir) - gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) + # gyre_obj = GyreAccess(wdir) + # gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) + # gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) evo_terminated = False termination_code = None From 25555915736ece06bf8394ade56e111274702aa8 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:04:38 +1000 Subject: [PATCH 20/37] test --- mesaport/Access/gyre_access.py | 6 +++--- mesaport/ProjectOps/ops_helper.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mesaport/Access/gyre_access.py b/mesaport/Access/gyre_access.py index 504bdd7..c3dfb8a 100644 --- a/mesaport/Access/gyre_access.py +++ b/mesaport/Access/gyre_access.py @@ -134,7 +134,7 @@ def modify_gyre_params(self, wdir, filename, data_format, gyre_in="gyre.in", dif self.writetoGyreFile(wdir, parameter="summary_file", value=f"'{filename.split('.')[0]}-freqs-nad.dat'", default_section="&nad_output", gyre_in=gyre_in) - def set(self, arg, gyre_in="gyre.in"): + def set(self, arg, wdir, gyre_in="gyre.in"): """Sets the value of a parameter in the inlist file. Args: @@ -142,11 +142,11 @@ def set(self, arg, gyre_in="gyre.in"): """ if isinstance(arg, dict): for key, value in arg.items(): - self.writetoGyreFile(self.projectDir, key, access_helper.toFortranType(value), gyre_in=gyre_in) + self.writetoGyreFile(wdir, key, access_helper.toFortranType(value), gyre_in=gyre_in) elif isinstance(arg, list): for item in arg: for key, value in item.items(): - self.writetoGyreFile(self.projectDir, key, access_helper.toFortranType(value), gyre_in=gyre_in) + self.writetoGyreFile(wdir, key, access_helper.toFortranType(value), gyre_in=gyre_in) elif arg is None: pass else: diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 8db74f9..2d0d332 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -53,9 +53,9 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") - # gyre_obj = GyreAccess(wdir) - # gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - # gyre_obj.set(arg=gyre_input_params, gyre_in=gyre_in) + gyre_obj = GyreAccess(wdir) + gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) + gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) evo_terminated = False termination_code = None From 667b7665315d5b554b2b4f576db989ba2d19c4e9 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:08:36 +1000 Subject: [PATCH 21/37] test --- mesaport/ProjectOps/ops_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 2d0d332..f8458bf 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -1,6 +1,7 @@ import subprocess import shlex import sys, os, glob, time +import numpy as np import shutil from rich import print @@ -45,14 +46,13 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, new_gyre_in = os.path.join(wdir, f"gyre{num}.in") if os.path.exists(new_gyre_in): os.remove(new_gyre_in) - # shutil.copy2(gyre_in, new_gyre_in) shutil.copyfile(gyre_in, new_gyre_in) gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") else: - # shutil.copy2(gyre_in, os.path.join(wdir, f"gyre.in")) shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") + time.sleep(np.random.random()*5) gyre_obj = GyreAccess(wdir) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) From b927c8dd1432b187141f23e2f2b52f3bfe168201 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:20:05 +1000 Subject: [PATCH 22/37] test --- mesaport/Access/gyre_access.py | 6 +----- mesaport/ProjectOps/ops_helper.py | 6 ++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mesaport/Access/gyre_access.py b/mesaport/Access/gyre_access.py index c3dfb8a..6265151 100644 --- a/mesaport/Access/gyre_access.py +++ b/mesaport/Access/gyre_access.py @@ -20,7 +20,7 @@ """ class GyreAccess: - def __init__(self, path, binary=False, target=''): + def __init__(self): """ Args: path (str): The path to the GYRE input file. @@ -28,10 +28,6 @@ def __init__(self, path, binary=False, target=''): target (str): The target to be used. """ self.check_env() - self.path = path - self.binary = binary - self.target = target - self.projectDir = os.path.abspath(path) def check_env(self): """ diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index f8458bf..3033e6f 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -52,10 +52,12 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, else: shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") - time.sleep(np.random.random()*5) - gyre_obj = GyreAccess(wdir) + time.sleep(np.random.random()*2) + gyre_obj = GyreAccess() gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) + time.sleep(np.random.random()*2) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) + time.sleep(np.random.random()*2) evo_terminated = False termination_code = None From c93d2b80c2cd8b178c03f5801f164cf9debf108c Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:29:48 +1000 Subject: [PATCH 23/37] test --- mesaport/ProjectOps/ops_helper.py | 1 + mesaport/ProjectOps/project_ops.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 3033e6f..d8da8bb 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -49,6 +49,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, shutil.copyfile(gyre_in, new_gyre_in) gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") + runlog = runlog.replace("runlog", f"runlog{num}") else: shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index 068a410..f7e39b5 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -401,7 +401,21 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr executor.map(ops_helper.run_subprocess, *args) except Exception as e: + filenames = glob.glob(os.path.join(LOGS_dir, f"gyre*.log")) + with open(runlog, 'a+') as outfile: + for fname in filenames: + with open(fname) as infile: + for line in infile: + outfile.write(line) + shutil.rmtree(fname) raise e + filenames = glob.glob(os.path.join(LOGS_dir, f"gyre*.log")) + with open(runlog, 'a+') as outfile: + for fname in filenames: + with open(fname) as infile: + for line in infile: + outfile.write(line) + shutil.rmtree(fname) res = True else: for i, file in enumerate(files): From 8e4c2695bdee4314692488f47d97cc4e62f1613f Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:31:55 +1000 Subject: [PATCH 24/37] test --- mesaport/ProjectOps/ops_helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index d8da8bb..0864dc0 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -53,12 +53,12 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, else: shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") - time.sleep(np.random.random()*2) + time.sleep(np.random.random()*5) gyre_obj = GyreAccess() gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - time.sleep(np.random.random()*2) + time.sleep(np.random.random()*5) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) - time.sleep(np.random.random()*2) + time.sleep(np.random.random()*5) evo_terminated = False termination_code = None From a363710167de30b1c199ce25c56f58efc3397986 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:32:29 +1000 Subject: [PATCH 25/37] test --- mesaport/ProjectOps/ops_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 0864dc0..fd6666f 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -49,7 +49,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, shutil.copyfile(gyre_in, new_gyre_in) gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") - runlog = runlog.replace("runlog", f"runlog{num}") + runlog = runlog.replace("gyre.log", f"gyre{num}.log") else: shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) gyre_in = os.path.join(wdir, f"gyre.in") From 03f633a7f47722054a1c1c445fef67a977405763 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 01:42:54 +1000 Subject: [PATCH 26/37] test --- mesaport/ProjectOps/ops_helper.py | 40 ++++++++++++++++++++---------- mesaport/ProjectOps/project_ops.py | 2 +- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index fd6666f..93a60c3 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -5,6 +5,9 @@ import shutil from rich import print +from threading import Lock +file_operation_lock = Lock() + from ..Access.support import * from ..Access.access_helper import toFortranType, toPythonType from ..Access import MesaAccess, GyreAccess @@ -39,26 +42,37 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, Pass os.environ.copy() to use the current environment. Or pass a dictionary with the environment variables to be used. """ if gyre_in is not None: - # if not os.path.exists(os.path.join(wdir, "gyre.in")): - # gyre_obj.load(gyre_in=gyre_in, dest=wdir) + gyre_obj = GyreAccess() if parallel: num = filename.split(".")[0] new_gyre_in = os.path.join(wdir, f"gyre{num}.in") - if os.path.exists(new_gyre_in): - os.remove(new_gyre_in) - shutil.copyfile(gyre_in, new_gyre_in) + + with file_operation_lock: + # Ensure thread-safe file operations + if os.path.exists(new_gyre_in): + os.remove(new_gyre_in) + shutil.copyfile(gyre_in, new_gyre_in) + + # Update gyre_in to the new file gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") runlog = runlog.replace("gyre.log", f"gyre{num}.log") + + time.sleep(np.random.random() * 10) + + gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) + gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) + + time.sleep(np.random.random() * 10) else: - shutil.copyfile(gyre_in, os.path.join(wdir, f"gyre.in")) - gyre_in = os.path.join(wdir, f"gyre.in") - time.sleep(np.random.random()*5) - gyre_obj = GyreAccess() - gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - time.sleep(np.random.random()*5) - gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) - time.sleep(np.random.random()*5) + with file_operation_lock: + new_gyre_in = os.path.join(wdir, "gyre.in") + shutil.copyfile(gyre_in, new_gyre_in) + gyre_in = new_gyre_in + gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) + gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) + + evo_terminated = False termination_code = None diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index f7e39b5..29e4854 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -407,7 +407,7 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr with open(fname) as infile: for line in infile: outfile.write(line) - shutil.rmtree(fname) + os.remove(fname) raise e filenames = glob.glob(os.path.join(LOGS_dir, f"gyre*.log")) with open(runlog, 'a+') as outfile: From b049dcb9d209afcbba351a86dece3069ede17971 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:07:02 +1000 Subject: [PATCH 27/37] test --- mesaport/ProjectOps/ops_helper.py | 9 ++------- mesaport/ProjectOps/project_ops.py | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 93a60c3..c61ccb7 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -52,18 +52,13 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, if os.path.exists(new_gyre_in): os.remove(new_gyre_in) shutil.copyfile(gyre_in, new_gyre_in) + gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) + gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) # Update gyre_in to the new file gyre_in = new_gyre_in commands = commands.replace("gyre.in", f"gyre{num}.in") runlog = runlog.replace("gyre.log", f"gyre{num}.log") - - time.sleep(np.random.random() * 10) - - gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) - gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) - - time.sleep(np.random.random() * 10) else: with file_operation_lock: new_gyre_in = os.path.join(wdir, "gyre.in") diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index 29e4854..97c80d4 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -415,7 +415,7 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr with open(fname) as infile: for line in infile: outfile.write(line) - shutil.rmtree(fname) + os.remove(fname) res = True else: for i, file in enumerate(files): From 8884bdf7b1ac804c1df72444184c292da2f422cb Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:09:16 +1000 Subject: [PATCH 28/37] test --- mesaport/ProjectOps/ops_helper.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index c61ccb7..e4cc735 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -51,8 +51,11 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # Ensure thread-safe file operations if os.path.exists(new_gyre_in): os.remove(new_gyre_in) + time.sleep(2) shutil.copyfile(gyre_in, new_gyre_in) + time.sleep(2) gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) + time.sleep(2) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) # Update gyre_in to the new file From a98514649a6bd1233140aad697c7c094f9493cbc Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:10:50 +1000 Subject: [PATCH 29/37] test --- mesaport/ProjectOps/ops_helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index e4cc735..609ad60 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -51,11 +51,11 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # Ensure thread-safe file operations if os.path.exists(new_gyre_in): os.remove(new_gyre_in) - time.sleep(2) + with file_operation_lock: shutil.copyfile(gyre_in, new_gyre_in) - time.sleep(2) + with file_operation_lock: gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) - time.sleep(2) + with file_operation_lock: gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) # Update gyre_in to the new file From 6025ea9a2a35c51815c6441af449b04af635b65f Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:20:52 +1000 Subject: [PATCH 30/37] test --- mesaport/ProjectOps/ops_helper.py | 12 +++++------- mesaport/ProjectOps/project_ops.py | 5 +++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 609ad60..35ac725 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -47,15 +47,13 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, num = filename.split(".")[0] new_gyre_in = os.path.join(wdir, f"gyre{num}.in") - with file_operation_lock: - # Ensure thread-safe file operations - if os.path.exists(new_gyre_in): - os.remove(new_gyre_in) - with file_operation_lock: - shutil.copyfile(gyre_in, new_gyre_in) + # with file_operation_lock: + # # Ensure thread-safe file operations + # if os.path.exists(new_gyre_in): + # os.remove(new_gyre_in) + # shutil.copyfile(gyre_in, new_gyre_in) with file_operation_lock: gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) - with file_operation_lock: gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) # Update gyre_in to the new file diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index 97c80d4..af63b30 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -372,6 +372,11 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr if parallel: gyre_input_params = gyre_input_params if gyre_input_params is not None else repeat(None) os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE' + ## copy gyre.in to gyre1.in, gyre2.in, etc. for parallel runs + for i, file in enumerate(files): + num = file.split(".")[0] + new_gyre_in = os.path.join(wdir, f"gyre{num}.in") + shutil.copyfile(gyre_in, new_gyre_in) # commands, wdir, # silent=True, runlog='', # status=None, filename="", From c1df3520f598f680ff6f98f895dc1ef3b3582906 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:26:04 +1000 Subject: [PATCH 31/37] test --- mesaport/ProjectOps/ops_helper.py | 11 ++++------- mesaport/ProjectOps/project_ops.py | 10 ++++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 35ac725..c4f4643 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -5,9 +5,6 @@ import shutil from rich import print -from threading import Lock -file_operation_lock = Lock() - from ..Access.support import * from ..Access.access_helper import toFortranType, toPythonType from ..Access import MesaAccess, GyreAccess @@ -44,6 +41,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, if gyre_in is not None: gyre_obj = GyreAccess() if parallel: + from threading import Lock num = filename.split(".")[0] new_gyre_in = os.path.join(wdir, f"gyre{num}.in") @@ -52,7 +50,7 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # if os.path.exists(new_gyre_in): # os.remove(new_gyre_in) # shutil.copyfile(gyre_in, new_gyre_in) - with file_operation_lock: + with Lock(): gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) @@ -61,9 +59,8 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, commands = commands.replace("gyre.in", f"gyre{num}.in") runlog = runlog.replace("gyre.log", f"gyre{num}.log") else: - with file_operation_lock: - new_gyre_in = os.path.join(wdir, "gyre.in") - shutil.copyfile(gyre_in, new_gyre_in) + new_gyre_in = os.path.join(wdir, "gyre.in") + shutil.copyfile(gyre_in, new_gyre_in) gyre_in = new_gyre_in gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=gyre_in) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=gyre_in) diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index af63b30..3f58dc9 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -373,10 +373,12 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr gyre_input_params = gyre_input_params if gyre_input_params is not None else repeat(None) os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE' ## copy gyre.in to gyre1.in, gyre2.in, etc. for parallel runs - for i, file in enumerate(files): - num = file.split(".")[0] - new_gyre_in = os.path.join(wdir, f"gyre{num}.in") - shutil.copyfile(gyre_in, new_gyre_in) + from threading import Lock + with Lock(): + for i, file in enumerate(files): + num = file.split(".")[0] + new_gyre_in = os.path.join(wdir, f"gyre{num}.in") + shutil.copyfile(gyre_in, new_gyre_in) # commands, wdir, # silent=True, runlog='', # status=None, filename="", From d6877a54cb26e8a6c7c0572be8f71cddb1e9413e Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:27:18 +1000 Subject: [PATCH 32/37] test --- mesaport/ProjectOps/project_ops.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index 3f58dc9..480d82d 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -374,10 +374,10 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE' ## copy gyre.in to gyre1.in, gyre2.in, etc. for parallel runs from threading import Lock - with Lock(): - for i, file in enumerate(files): - num = file.split(".")[0] - new_gyre_in = os.path.join(wdir, f"gyre{num}.in") + for i, file in enumerate(files): + num = file.split(".")[0] + new_gyre_in = os.path.join(wdir, f"gyre{num}.in") + with Lock(): shutil.copyfile(gyre_in, new_gyre_in) # commands, wdir, # silent=True, runlog='', From 2617f76b4081bd300849ecc6b9321ef6f4e63e8b Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:28:16 +1000 Subject: [PATCH 33/37] test --- mesaport/ProjectOps/project_ops.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mesaport/ProjectOps/project_ops.py b/mesaport/ProjectOps/project_ops.py index 480d82d..af63b30 100644 --- a/mesaport/ProjectOps/project_ops.py +++ b/mesaport/ProjectOps/project_ops.py @@ -373,12 +373,10 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr gyre_input_params = gyre_input_params if gyre_input_params is not None else repeat(None) os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE' ## copy gyre.in to gyre1.in, gyre2.in, etc. for parallel runs - from threading import Lock for i, file in enumerate(files): num = file.split(".")[0] new_gyre_in = os.path.join(wdir, f"gyre{num}.in") - with Lock(): - shutil.copyfile(gyre_in, new_gyre_in) + shutil.copyfile(gyre_in, new_gyre_in) # commands, wdir, # silent=True, runlog='', # status=None, filename="", From 14154dfa7efc5a5ec8b173e239597824e7816538 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:29:41 +1000 Subject: [PATCH 34/37] test --- mesaport/ProjectOps/ops_helper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index c4f4643..01556c9 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -5,6 +5,9 @@ import shutil from rich import print +from threading import Lock +file_operation_lock = Lock() + from ..Access.support import * from ..Access.access_helper import toFortranType, toPythonType from ..Access import MesaAccess, GyreAccess @@ -41,7 +44,6 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, if gyre_in is not None: gyre_obj = GyreAccess() if parallel: - from threading import Lock num = filename.split(".")[0] new_gyre_in = os.path.join(wdir, f"gyre{num}.in") @@ -50,8 +52,9 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # if os.path.exists(new_gyre_in): # os.remove(new_gyre_in) # shutil.copyfile(gyre_in, new_gyre_in) - with Lock(): + with file_operation_lock: gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) + with file_operation_lock: gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) # Update gyre_in to the new file From b9f82f73b94c791023f442723f1f0407377fec93 Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:32:20 +1000 Subject: [PATCH 35/37] test --- mesaport/Access/gyre_access.py | 44 +++++++++++++++++-------------- mesaport/ProjectOps/ops_helper.py | 10 +++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/mesaport/Access/gyre_access.py b/mesaport/Access/gyre_access.py index 6265151..06c71fc 100644 --- a/mesaport/Access/gyre_access.py +++ b/mesaport/Access/gyre_access.py @@ -5,6 +5,9 @@ from . import access_helper from .support.utils import cwd +from threading import Lock +file_operation_lock = Lock() + """ This module defines the `GyreAccess` class, which handles GYRE input file operations. @@ -91,28 +94,29 @@ def writetoGyreFile(self, wdir, parameter, value, default_section=None, gyre_in= raise(f"Parameter {parameter} not found in any GYRE input files.") this_section = False with cwd(wdir): - with open(gyre_in, "r") as file: - lines = file.readlines() - with open(gyre_in, "w+") as f: - indent = " " - for line in lines: - edited = False - if default_section in line: - this_section = True - if this_section: - if parameter in line: - if parameter == line.split("=")[0].strip(): - f.write(line.replace(line.split("=")[1], f" {value} ! Changed\n")) + with file_operation_lock: + with open(gyre_in, "r") as file: + lines = file.readlines() + with open(gyre_in, "w+") as f: + indent = " " + for line in lines: + edited = False + if default_section in line: + this_section = True + if this_section: + if parameter in line: + if parameter == line.split("=")[0].strip(): + f.write(line.replace(line.split("=")[1], f" {value} ! Changed\n")) + edited = True + this_section = False + elif line[0] == "/": + f.write(indent) + f.write(f"{parameter} = {value} ! Added\n") + f.write("/") edited = True this_section = False - elif line[0] == "/": - f.write(indent) - f.write(f"{parameter} = {value} ! Added\n") - f.write("/") - edited = True - this_section = False - if not edited: - f.write(line) + if not edited: + f.write(line) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 01556c9..254df75 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -5,9 +5,6 @@ import shutil from rich import print -from threading import Lock -file_operation_lock = Lock() - from ..Access.support import * from ..Access.access_helper import toFortranType, toPythonType from ..Access import MesaAccess, GyreAccess @@ -52,10 +49,9 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, # if os.path.exists(new_gyre_in): # os.remove(new_gyre_in) # shutil.copyfile(gyre_in, new_gyre_in) - with file_operation_lock: - gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) - with file_operation_lock: - gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) + + gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) + gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) # Update gyre_in to the new file gyre_in = new_gyre_in From c8d6e4548a2ec62fbbc8a3ac529984ce75e0345a Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:39:41 +1000 Subject: [PATCH 36/37] test --- mesaport/Access/gyre_access.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesaport/Access/gyre_access.py b/mesaport/Access/gyre_access.py index 06c71fc..152ac42 100644 --- a/mesaport/Access/gyre_access.py +++ b/mesaport/Access/gyre_access.py @@ -31,6 +31,7 @@ def __init__(self): target (str): The target to be used. """ self.check_env() + self.default_sections = self.gyreDefaults() def check_env(self): """ @@ -87,7 +88,7 @@ def writetoGyreFile(self, wdir, parameter, value, default_section=None, gyre_in= sections (list): A list with the sections of the inlist file. """ if default_section is None: - for section, values in self.gyreDefaults().items(): + for section, values in self.default_sections.items(): if parameter in values: default_section = section if default_section is None: From 239e2359d4a525929f222b458ad0ea0fc3e1983a Mon Sep 17 00:00:00 2001 From: gautam-404 Date: Thu, 16 Nov 2023 02:42:46 +1000 Subject: [PATCH 37/37] test --- mesaport/ProjectOps/ops_helper.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mesaport/ProjectOps/ops_helper.py b/mesaport/ProjectOps/ops_helper.py index 254df75..8d9779f 100644 --- a/mesaport/ProjectOps/ops_helper.py +++ b/mesaport/ProjectOps/ops_helper.py @@ -43,15 +43,9 @@ def run_subprocess(commands, wdir, silent=True, runlog='', status=None, if parallel: num = filename.split(".")[0] new_gyre_in = os.path.join(wdir, f"gyre{num}.in") - - # with file_operation_lock: - # # Ensure thread-safe file operations - # if os.path.exists(new_gyre_in): - # os.remove(new_gyre_in) - # shutil.copyfile(gyre_in, new_gyre_in) - gyre_obj.modify_gyre_params(wdir, filename, data_format, gyre_in=new_gyre_in) gyre_obj.set(arg=gyre_input_params, wdir=wdir, gyre_in=new_gyre_in) + time.sleep(1) # Update gyre_in to the new file gyre_in = new_gyre_in