示例#1
0
def test_missing_template_dir():
    '''test that we raise an exception if the specified template location
    does not exist'''
    template_dir = os.path.join(SCRIPT_DIR, "invalid")
    with pytest.raises(RuntimeError) as excinfo:
        _ = create_input(OPTION, TEMPLATE_NAME, template_location=template_dir)
    assert "template '" + TEMPLATE_NAME + "' not found" in str(excinfo.value)
示例#2
0
def test_non_existant_template():
    '''test that we raise an exception if the specified template does not
    exist'''
    template_name = "invalid.txt"
    with pytest.raises(RuntimeError) as excinfo:
        _ = create_input(OPTION, template_name, template_location=TEMPLATE_DIR)
    assert "template '" + template_name + "' not found" in str(excinfo.value)
示例#3
0
def test_option_wrong_format():
    '''check that we raise an exception if the input option is not in the
    expected format (a dictionary within a list).'''
    option = ["fred"]
    with pytest.raises(RuntimeError) as excinfo:
        _ = create_input(option, TEMPLATE_NAME, template_location=TEMPLATE_DIR)
    assert "Expecting a dictionary" in str(excinfo.value)
示例#4
0
def launch(option):
    '''Set the gromacs input data using the supplied input options, run
    gromacs and extract and return the required outputs.'''

    from melody.inputs import create_input
    _ = create_input(option, template_name="input.mdp")

    # save the input file in the appropriate place and launch gromacs using
    # longbow ...

    # determine if the run was successful
    success = True

    results = None
    if success:
        # extract the required outputs
        results = {
            "rate": {
                "value": 35,
                "units": "ns/day"
            },
        }

    return success, results
示例#5
0
def execute(option):
    '''A script that melody calls with each valid set of options. This
    script runs the required code and returns the results.'''

    namelist_option = []
    makefile_option = []
    flags = ""
    for entry in option:
        key = entry.keys()[0]
        if key == "Problem Size":
            namelist_option.append({"SIZE": entry[key]})
        elif key == "F90":
            makefile_option.append(entry)
        else:
            flags += entry[key] + " "
    makefile_option.append({"F90FLAGS": flags})

    namelist = create_input(namelist_option,
                            "namelist",
                            template_location="templates")

    makefile_include = create_input(makefile_option,
                                    "Makefile.include",
                                    template_location="templates")

    benchmark_base = "shallow"

    # save the input files in the appropriate place
    location = benchmark_base + "/original/namelist"
    my_file = open(location, 'w')
    my_file.write(namelist)
    my_file.flush()

    location = benchmark_base + "/common/Makefile.include"
    my_file = open(location, 'w')
    my_file.write(makefile_include)
    my_file.flush()

    # compile shallow if required
    base_path = benchmark_base + "/original"
    import subprocess
    make_process = subprocess.Popen(["make", "clean"],
                                    cwd=base_path,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)
    if make_process.wait() != 0:
        return False, []

    make_process = subprocess.Popen(["make"],
                                    cwd=base_path,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)
    if make_process.wait() != 0:
        return False, []

    # run shallow
    make_process = subprocess.Popen(["./shallow_base"],
                                    cwd=base_path,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)
    if make_process.wait() != 0:
        return False, []
    # _ = make_process.stderr.read()
    stdout = make_process.stdout.read()

    # determine if the results are correct. We will need to look at
    # the results from stdout but for the moment we assume they are
    # correct

    # extract the required outputs
    for line in stdout.split("\n"):
        if "Time-stepping" in line:
            total_time = line.split()[2]

    return True, total_time
示例#6
0
def test_create_input():
    ''' test that we can modify a template file correctly '''
    result = create_input(OPTION,
                          TEMPLATE_NAME,
                          template_location=TEMPLATE_DIR)
    assert EXPECTED in result