예제 #1
0
def test_running_in_different_directory():
    """Test ability to provide parameter names."""
    work_folder = "dakota_runs"
    run_directory = os.path.abspath(os.path.join(os.getcwd(), "running_here"))
    work_directory = os.path.abspath(
        os.path.join(run_directory, "..", "working_here"))
    configuration_file = "another_excellent_yaml.yaml"
    run_log = "run_output_should_be_here.log"
    error_log = "no_errors_inside.log"
    parameters_file = "parameters_here.in"
    results_file = "neato_results_here.out"
    input_file = "dakota_LHC.in"
    output_file = "dakota_LHC.out"

    k = Dakota(
        method="sampling",
        variables="uniform_uncertain",
        input_file=input_file,
        output_file=output_file,
        interface="fork",
        run_directory=run_directory,
        work_directory=work_directory,
        work_folder=work_folder,
        configuration_file=configuration_file,
        run_log=run_log,
        error_log=error_log,
        parameters_file=parameters_file,
        results_file=results_file,
    )
    k.write_input_file()
    k.serialize()
    k.run()

    # teardown. First the run directory.
    lhc_filelist = [f for f in os.listdir(".") if f.startswith("LHS")]
    for f in lhc_filelist:
        os.remove(f)
    os.remove(configuration_file)
    os.remove(run_log)
    os.remove(error_log)
    os.remove(input_file)
    os.remove(output_file)
    teardown_module()
    [os.remove(f) for f in os.listdir(".")]
    os.chdir("..")
    os.rmdir(run_directory)

    # Second the working directory.

    num_runs = k.method.samples
    os.chdir(work_directory)
    for i in range(num_runs):
        folder_name = ".".join([work_folder, str(i + 1)])
        os.chdir(folder_name)
        os.remove(parameters_file)
        os.remove(results_file)
        os.chdir("..")
        os.rmdir(folder_name)
    os.chdir("..")
    os.rmdir(work_directory)
예제 #2
0
def test_default_run_with_input_file():
    """Test default object run method with input file."""
    if is_dakota_installed():
        k = Dakota()
        k.write_input_file()
        k.run()
        assert_true(os.path.exists(k.output_file))
        assert_true(os.path.exists(k.environment.data_file))
예제 #3
0
def test_default_run_without_input_file():
    """Test default object run method fails with no input file."""
    if is_dakota_installed():
        if os.path.exists(input_file):
            os.remove(input_file)
        try:
            k = Dakota()
            k.run()
        except CalledProcessError:
            pass
예제 #4
0
def test_run_by_setting_attributes():
    """Test running a HydroTrend simulation."""
    d = Dakota(method="vector_parameter_study", plugin="hydrotrend")
    d.template_file = os.path.join(data_dir, "HYDRO.IN.dtmpl")
    d.auxiliary_files = os.path.join(data_dir, "HYDRO0.HYPS")
    d.variables.descriptors = [
        "starting_mean_annual_temperature",
        "total_annual_precipitation",
    ]
    d.variables.initial_point = [10.0, 1.5]
    d.method.final_point = [20.0, 2.5]
    d.method.n_steps = 5
    d.responses.response_descriptors = ["Qs_median", "Q_mean"]
    d.responses.response_files = ["HYDROASCII.QS", "HYDROASCII.Q"]
    d.responses.response_statistics = ["median", "mean"]
    d.setup()
    assert_true(os.path.exists(d.input_file))
    if is_dakota_installed() and is_hydrotrend_installed():
        d.run()
        assert_true(os.path.exists(d.output_file))
예제 #5
0
def test_changing_parameter_names():
    """Test ability to provide parameter names."""
    run_directory = "looped_runs"
    configuration_file = "an_excellent_yaml.yaml"
    run_log = "run_output_here.log"
    error_log = "no_errors_here.log"
    if is_dakota_installed():
        k = Dakota(
            method="vector_parameter_study",
            run_directory=run_directory,
            configuration_file=configuration_file,
            run_log=run_log,
            error_log=error_log,
        )
        k.write_input_file()
        k.serialize()
        k.run()

        os.remove(configuration_file)
        os.remove(run_log)
        os.remove(error_log)
        teardown_module()
        os.chdir("..")
        os.rmdir(run_directory)