예제 #1
0
def runtest(nout, repeat=5, path=None, nprocs=4, model=None, log_dir=None):
    """Run `model` in `path` `repeat` times, returning the mean runtime
    and its standard deviation

    """
    if path is None:
        path = DEFAULT_MODEL_PATH
    if model is None:
        model = DEFAULT_MODEL_EXE
    os.chdir(path)

    shell_safe("make")

    command = "mpirun -n {nprocs} ./{model} NOUT={nout} >/dev/null".format(
        model=model, nout=nout, nprocs=nprocs)

    runtime = []

    for run_number in range(repeat):
        runtime.append(timeit.timeit(lambda: shell_safe(command), number=1))
        backup_log_file(log_dir, subdir="run{:02d}".format(run_number))

    return {
        "mean": np.mean(runtime),
        "std": np.std(runtime),
        "low": np.min(runtime)
    }
예제 #2
0
def git_info():
    """Return a dict of the commit hash and the date on which it was committed

    """
    _, git_commit = shell_safe("git rev-parse HEAD", pipe=True)
    _, commit_date = shell_safe("git --no-pager show -s --format=%ci",
                                pipe=True)

    return {"commit": git_commit[:7], "date": commit_date.strip()}
예제 #3
0
def cleanup():
    """Make sure BOUT++ directory is clean and submodules correct

    """
    shell("make distclean")
    shell_safe(r'find src -type f -name "*\.o" -delete')

    shutil.rmtree("googletest", ignore_errors=True)
    shutil.rmtree("externalpackages/googletest", ignore_errors=True)
    shutil.rmtree("externalpackages/mpark.variant", ignore_errors=True)
    shell_safe("git submodule update --init --recursive")
예제 #4
0
def configure_bout(configure_line=None):
    """Configure BOUT++

    """

    if configure_line is None:
        configure_line = (
            "./configure -C "
            "CXXFLAGS='-std=c++11 -fdiagnostics-color=always' "
            "--with-netcdf --enable-optimize=3 --enable-checks=no "
            "--disable-backtrace")

    print(configure_line)
    shell_safe(configure_line)
예제 #5
0
    def test_git_hash(self):
        # Try to get git hash directly instead of through versioneer's get_versions()

        from boututils.run_wrapper import shell, shell_safe

        # check if git exists
        retval, git_version = shell("git --version")
        if retval == 0:
            # git exists

            from pathlib import Path
            from hypnotoad.__init__ import __file__ as hypnotoad_init_file

            hypnotoad_path = Path(hypnotoad_init_file).parent

            # check if hypnotoad is in it's own git repo. hypnotoad.__init__.py
            # should be in the hypnotoad/ subdirectory of the git repo if it is.
            # So the parent directory of hypnotoad_path should contain a '.git'
            # directory if hypnotoad is in a git repo
            if hypnotoad_path.parent.joinpath(".git").is_dir():
                retval, git_hash = shell_safe(
                    "cd "
                    + str(hypnotoad_path)
                    + '&& git describe --always --abbrev=0 --dirty --match "NOT A TAG"',
                    pipe=True,
                )
                git_hash = git_hash.strip()

                # found a git hash, check it is consistent with the one from versioneer
                dirty_pos = git_hash.find("-dirty")
                if dirty_pos != -1:
                    # Check versioneer says the repo is dirty
                    assert get_versions()["dirty"]

                    # remove "-dirty" from git_hash
                    git_hash = git_hash[:dirty_pos]
                else:
                    # repo is clean
                    assert not get_versions()["dirty"]

                assert git_hash == get_versions()["full-revisionid"]
        elif retval == 127:
            # git not installed
            pass
        else:
            raise RuntimeError(
                "'git --version' failed with {retval}. Output was {git_version}"
            )
예제 #6
0
파일: runtest.py 프로젝트: jenuis/BOUT-dev
gamma_tol = 1e-2

from boututils.run_wrapper import shell, shell_safe, launch_safe, getmpirun
from boututils.file_import import file_import
from boututils.calculus import deriv
from boututils.linear_regression import linear_regression

from boutdata.collect import collect
import numpy as np
from sys import exit ,argv

nthreads=1
MPIRUN = getmpirun()

print("Making resistive drift instability test")
shell_safe("make > make.log")

zlist          = [2, 32, 256]  # Just test a few

# Values from revision c4f7ec92786b333a5502c5256b5e602ba867090f
# 26th Oct 2011
omega_orig     = {1:1.00819536681,
                  2:0.975756752742,
                  4:0.888269347989,
                  8:0.741253948437,
                  16:0.574003058717,
                  32:0.428644078148, #0.430745728591, Changed 25th April 2014, revision fd032da
                  64:0.336073734175,
                  128:0.2208085,
                  256:0.155890075514} #0.156853396108} Changed 25th April 2014
gamma_orig     = {1:0.0784576199501,
예제 #7
0
    #,("../fci-wave-logn/div-integrate", "Model 5 (velocity, log density, area integration)")
]

data_boundary = [
    ("boundary", "Model 2 (density, momentum)")
    ,("boundary-logn", "Model 3 (log density, momentum)")
    #,("../fci-wave-logn/boundary", "Model 5 (log density, velocity)")
    ]

# Change this to select no boundary or boundary cases
data = data_noboundary

if run:
    from boututils.run_wrapper import shell_safe, launch_safe, getmpirun
    
    shell_safe("make > make.log")
    MPIRUN=getmpirun()
    
    for path,label in data:
        launch_safe("./fci-wave -d "+path, runcmd=MPIRUN, nproc=nproc, pipe=False)

# Collect the results into a dictionary 
sum_n_B = {}

for path,label in data:
    n = collect("n", path=path)
    Bxyz = collect("Bxyz", path=path)

    time = collect("t_array", path=path)
    
    nt, nx, ny, nz = n.shape
예제 #8
0
    #,("../fci-wave-logn/div-integrate", "Model 5 (velocity, log density, area integration)")
]

data_boundary = [
    ("boundary", "Model 2 (density, momentum)"),
    ("boundary-logn", "Model 3 (log density, momentum)")
    #,("../fci-wave-logn/boundary", "Model 5 (log density, velocity)")
]

# Change this to select no boundary or boundary cases
data = data_noboundary

if run:
    from boututils.run_wrapper import shell_safe, launch_safe, getmpirun

    shell_safe("make > make.log")
    MPIRUN = getmpirun()

    for path, label in data:
        launch_safe("./fci-wave -d " + path,
                    runcmd=MPIRUN,
                    nproc=nproc,
                    pipe=False)

# Collect the results into a dictionary
sum_n_B = {}

for path, label in data:
    n = collect("n", path=path)
    Bxyz = collect("Bxyz", path=path)
예제 #9
0
def build_bout(configure_line=None):
    """Build BOUT++
    """
    shell_safe("make -j8")