Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Removed old cruft from when the executable was called
Browse files Browse the repository at this point in the history
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 15, 2023
1 parent f46be52 commit c64eefd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dump*
*.egg*
swiftest-*
__pycache__*
_cmake*


#Documentation
Expand Down
1 change: 1 addition & 0 deletions buildscripts/build_swiftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ printf "SKBUILD_CONFIGURE_OPTIONS: ${SKBUILD_CONFIGURE_OPTIONS}\n"
printf "*********************************************************\n"

python3 -m pip install build pip
python3 -m pip build
python3 -m pip install . -v

3 changes: 1 addition & 2 deletions swiftest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
"""

from .constants import *
from .simulation_class import Simulation
from ._bindings import driver
from .simulation_class import Simulation
76 changes: 24 additions & 52 deletions swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from swiftest import init_cond
from swiftest import tool
from swiftest import constants
from swiftest._bindings import driver
from swiftest import __file__ as _pyfile
import json
import os
Expand All @@ -25,7 +26,6 @@
from functools import partial
import numpy.typing as npt
import shutil
import shlex
import warnings
import sys
from py.io import StdCaptureFD
Expand All @@ -37,7 +37,16 @@
Tuple,
Any
)
import contextlib

@contextlib.contextmanager
def _cwd(newdir):
olddir = os.getcwd()
os.chdir(newdir)
try:
yield
finally:
os.chdir(olddir)

class Simulation(object):
"""
Expand All @@ -63,7 +72,7 @@ def __init__(self,read_param: bool = False,
file, arguments to Simulation, the general `set_parameter` method, or the specific setters for groups of
similar parameters (e.g. set_init_cond_files, set_simulation_time, etc.). Each parameter has a default value
that can be overridden by an argument to Simulation(). Some argument parameters have equivalent values that
are passed to the `swiftest_driver` Fortran program via a parameter input file. When declaring a new
are passed to the Swiftest driver Fortran function via a parameter input file. When declaring a new
Simulation object, parameters are chosen in the following way, from highest to lowest priority"
1. Arguments to Simulation()
2. The parameter input file given by `param_file` under the following conditions:
Expand Down Expand Up @@ -424,14 +433,9 @@ def _type_scrub(output_data):
post_message += f" dL/L0: {0.0:.5e} dE/|E0|: {0.0:+.5e}"
post_message += f" Wall time / step: {0.0:.5e} s"
pbar = tqdm(total=noutput, desc=pre_message, postfix=post_message, bar_format='{l_bar}{bar}{postfix}')
try:
with _cwd(self.simdir):
capture = StdCaptureFD(out=False, in_=False)
out,err = capture.reset()
# with subprocess.Popen(shlex.split(cmd),
# stdout=subprocess.PIPE,
# stderr=subprocess.PIPE,
# env=env,
# universal_newlines=True) as p:
driver(self.integrator,str(self.param_file), "compact")
for line in out:
if "SWIFTEST STOP" in line:
Expand Down Expand Up @@ -459,18 +463,18 @@ def _type_scrub(output_data):
if "SWIFTEST START" in line:
process_output = True

res = p.communicate()
if p.returncode != 0:
for line in res[1]:
print(line, end='')
warnings.warn("Failure in swiftest_driver", stacklevel=2)
sys.exit()
except:
warnings.warn(f"Error executing main swiftest_driver program", stacklevel=2)
res = p.communicate()
for line in res[1]:
print(line, end='')
sys.exit()
# res = p.communicate()
# if p.returncode != 0:
# for line in res[1]:
# print(line, end='')
# warnings.warn("Failure in swiftest_driver", stacklevel=2)
# sys.exit()
# except:
# warnings.warn(f"Error executing main swiftest_driver program", stacklevel=2)
# res = p.communicate()
# for line in res[1]:
# print(line, end='')
# sys.exit()

pbar.close()
return
Expand Down Expand Up @@ -500,12 +504,6 @@ def run(self,dask: bool = False, **kwargs):
warnings.warn(f"Running an integration is not yet supported for {self.codename}",stacklevel=2)
return

if not self.binary_source.exists():
msg = "Path to swiftest_driver has not been set!"
msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_source.parent)}"
warnings.warn(msg,stacklevel=2)
return

if not self.restart:
self.clean()

Expand Down Expand Up @@ -943,19 +941,6 @@ def set_integrator(self,

self.param['! VERSION'] = f"{self.codename} input file"
update_list.append("codename")
if self.codename == "Swiftest":
self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver"
self.driver_executable = self.binary_source
if not self.binary_source.exists():
warnings.warn(f"Cannot find the Swiftest driver at {str(self.binary_source)}",stacklevel=2)
self.driver_executable = None
else:
if self.binary_source.exists():
self.driver_executable.resolve()
else:
self.binary_source = "NOT IMPLEMENTED FOR THIS CODE"
self.driver_executable = None
update_list.append("driver_executable")

if self.codename == "Swifter":
J2 = self.param.pop("J2",0.0)
Expand Down Expand Up @@ -1018,7 +1003,6 @@ def get_integrator(self,arg_list: str | List[str] | None = None, verbose: bool |
valid_instance_vars = {"codename": self.codename,
"integrator": self.integrator,
"param_file": str(self.param_file),
"driver_executable": str(self.driver_executable)
}

try:
Expand Down Expand Up @@ -2770,13 +2754,6 @@ def write_param(self,
else:
warnings.warn('Cannot process unknown code type. Call the read_param method with a valid code name. Valid options are "Swiftest", "Swifter", or "Swift".',stacklevel=2)

# # Generate executable script
# self.driver_script = os.path.join(self.simdir, "swiftest_driver.sh")
# with open(self.driver_script, 'w') as f:
# f.write(f"#{self._shell_full}\n")
# f.write(f"cd {self.simdir}\n")
# f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n")

return

def convert(self, param_file, newcodename="Swiftest", plname="pl.swiftest.in", tpname="tp.swiftest.in",
Expand Down Expand Up @@ -3008,11 +2985,6 @@ def save(self,
infile_name = Path(self.simdir) / param['NC_IN']
io.swiftest_xr2infile(ds=self.data, param=param, in_type=self.param['IN_TYPE'], infile_name=infile_name, framenum=framenum, verbose=verbose)
self.write_param(param_file=param_file,**kwargs)
if not self.binary_source.exists():
msg = "Path to swiftest_driver has not been set!"
msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_source.parent)}"
warnings.warn(msg,stacklevel=2)
return
elif codename == "Swifter":
swifter_param = io.swiftest2swifter_param(param)
if "rhill" in self.data:
Expand Down

0 comments on commit c64eefd

Please sign in to comment.