Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam-404 committed Mar 8, 2024
1 parent b568afe commit 3bbd88d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
47 changes: 25 additions & 22 deletions mesaport/ProjectOps/ops_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import shutil
from rich import print
import traceback

from ..Access.support import *
from ..Access.access_helper import toFortranType, toPythonType
Expand Down Expand Up @@ -39,29 +40,31 @@ 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()
if parallel:
# profile_num = filename.split('/')[-1].split(f".{data_format}")[0]
profile_stem = Path(filename).stem
new_gyre_in = os.path.join(wdir, f"gyre{profile_stem}.in")
print(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
commands = commands.replace("gyre.in", f"gyre{profile_stem}.in")
runlog = os.path.join(wdir, f"gyre{profile_stem}.log")
print(runlog)

else:
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)
try:
gyre_obj = GyreAccess()
if parallel:
# profile_num = filename.split('/')[-1].split(f".{data_format}")[0]
profile_stem = Path(filename).stem
new_gyre_in = os.path.join(wdir, f"gyre{profile_stem}.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
commands = commands.replace("gyre.in", f"gyre{profile_stem}.in")
runlog = os.path.join(wdir, f"gyre{profile_stem}.log")
print(runlog)
else:
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)
except Exception as e:
print(traceback.format_exc())
print(f"Error: {e}")
return False


evo_terminated = False
Expand Down
9 changes: 6 additions & 3 deletions mesaport/ProjectOps/project_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr
for _ in pool.istarmap(ops_helper.run_subprocess, zip(*args)):
progressbar.advance(task)
except Exception as e:
traceback.print_exc()
print(traceback.format_exc())
print(f"Error: {e}")
pool.terminate()
else:
try:
Expand All @@ -411,7 +412,8 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr
try:
executor.map(ops_helper.run_subprocess, *args)
except Exception as e:
traceback.print_exc()
print(traceback.format_exc())
print(f"Error: {e}")
executor.shutdown(wait=False)
except Exception as e:
filenames = glob.glob(os.path.join(LOGS_dir, f"gyreprofile*.log"))
Expand All @@ -421,7 +423,8 @@ def runGyre(self, gyre_in, files='all', wdir=None, data_format="GYRE", silent=Tr
for line in infile:
outfile.write(line)
os.remove(fname)
traceback.print_exc()
print(traceback.format_exc())
print(f"Error: {e}")
filenames = glob.glob(os.path.join(LOGS_dir, f"gyreprofile*.log"))
with open(runlog, 'a+') as outfile:
for fname in filenames:
Expand Down

0 comments on commit 3bbd88d

Please sign in to comment.