How to use the easyvvuq.actions.ExecuteLocal function in easyvvuq

To help you get started, we’ve selected a few easyvvuq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UCL-CCS / EasyVVUQ / tests / test_flee.py View on Github external
def test_flee(tmpdir):

    my_campaign = uq.Campaign(state_filename="tests/fleetest/flee_application.json", workdir=tmpdir)

    my_campaign.vary_param("MaxMoveSpeed", dist=uq.distributions.normal(200.0, 5.0))

    random_sampler = uq.elements.sampling.RandomSampler(my_campaign)

    my_campaign.add_runs(random_sampler, max_num=5)

    my_campaign.populate_runs_dir()

    my_campaign.apply_for_each_run_dir(
            uq.actions.ExecuteLocal("/bin/bash run_flee.sh\n"))

    output_filename = 'out.csv'
    output_columns = ['Total error']

    aggregate = uq.elements.collate.AggregateSamples(
                                my_campaign,
                                output_filename=output_filename,
                                output_columns=output_columns,
                                header=0)
    aggregate.apply()

    my_campaign.save_state("test_flee.json")

    sys.exit(0)
github UCL-CCS / EasyVVUQ / tests / test_multisampler.py View on Github external
# Test reloading
    my_campaign.save_state(tmpdir + "test_multisampler.json")
    reloaded_campaign = uq.Campaign(state_file=tmpdir + "test_multisampler.json", work_dir=tmpdir)

    # Draw all samples
    my_campaign.draw_samples()

    # Print the list of runs now in the campaign db
    print("List of runs added:")
    pprint(my_campaign.list_runs())
    print("---")

    # Encode and execute.
    my_campaign.populate_runs_dir()
    my_campaign.apply_for_each_run_dir(
        uq.actions.ExecuteLocal("tests/cannonsim/bin/cannonsim in.cannon output.csv"))

    print("Runs list after encoding and execution:")
    pprint(my_campaign.list_runs())

    # Collate all data into one pandas data frame
    my_campaign.collate()
    print("data:", my_campaign.get_collation_result())

    # Create a BasicStats analysis element and apply it to the campaign
    stats = uq.analysis.BasicStats(qoi_cols=['Dist', 'lastvx', 'lastvy'])
    my_campaign.apply_analysis(stats)
    print("stats:\n", my_campaign.get_last_analysis())

    # Print the campaign log
    pprint(my_campaign._log)
github UCL-CCS / EasyVVUQ / tests / test_dimension_adaptive_SC.py View on Github external
my_sampler = uq.sampling.SCSampler(vary=vary, polynomial_order=1,
                                       quadrature_rule="C",
                                       sparse=True, growth=True,
                                       midpoint_level1=True,
                                       dimension_adaptive=True)

    # Associate the sampler with the campaign
    my_campaign.set_sampler(my_sampler)

    # Will draw all (of the finite set of samples)
    my_campaign.draw_samples()
    my_campaign.populate_runs_dir()

    # Run the samples using EasyVVUQ on the localhost
    my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(
        "tests/sc/poly_model_anisotropic.py poly_in.json"))

    my_campaign.collate()
    data_frame = my_campaign.get_collation_result()

    # Post-processing analysis
    analysis = uq.analysis.SCAnalysis(sampler=my_sampler, qoi_cols=output_columns)

    my_campaign.apply_analysis(analysis)

    for i in range(number_of_adaptations):
        my_sampler.look_ahead(analysis.l_norm)

        my_campaign.draw_samples()
        my_campaign.populate_runs_dir()
        my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(
github UCL-CCS / EasyVVUQ / tests / test_cannonsim_csv_jsondb.py View on Github external
# Print the list of runs now in the campaign db
    print("List of runs added:")
    pprint(my_campaign.list_runs())
    print("---")

    # Encode all runs into a local directory
    pprint(
        f"Encoding all runs to campaign runs dir {my_campaign.get_campaign_runs_dir()}")
    my_campaign.populate_runs_dir()

    assert(len(my_campaign.get_campaign_runs_dir()) > 0)
    assert(os.path.exists(my_campaign.get_campaign_runs_dir()))
    assert(os.path.isdir(my_campaign.get_campaign_runs_dir()))

    # Local execution
    my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(
        "tests/cannonsim/bin/cannonsim in.cannon output.csv"))

    # Collate all data into one pandas data frame
    my_campaign.collate()
    print("data:", my_campaign.get_collation_result())

    # Save the state of the campaign
    state_file = tmpdir + "cannonsim_state.json"
    my_campaign.save_state(state_file)

    my_campaign = None

    # Load state in new campaign object
    reloaded_campaign = uq.Campaign(state_file=state_file, work_dir=tmpdir)
    reloaded_campaign.set_app("cannonsim")
github UCL-CCS / EasyVVUQ / tests / test_cannonsim_csv_jsondb.py View on Github external
my_campaign = None

    # Load state in new campaign object
    reloaded_campaign = uq.Campaign(state_file=state_file, work_dir=tmpdir)
    reloaded_campaign.set_app("cannonsim")

    # Draw 3 more samples, execute, and collate onto existing dataframe
    print("Running 3 more samples...")
    reloaded_campaign.draw_samples(num_samples=3)
    print("List of runs added:")
    pprint(reloaded_campaign.list_runs())
    print("---")

    reloaded_campaign.populate_runs_dir()
    reloaded_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(
        "tests/cannonsim/bin/cannonsim in.cannon output.csv"))

    print("Completed runs:")
    pprint(reloaded_campaign.scan_completed())

    print("All completed?", reloaded_campaign.all_complete())

    reloaded_campaign.collate()
    print("data:\n", reloaded_campaign.get_collation_result())

    print(reloaded_campaign)

    # Create a BasicStats analysis element and apply it to the campaign
    stats = uq.analysis.BasicStats(qoi_cols=['Dist', 'lastvx', 'lastvy'])
    reloaded_campaign.apply_analysis(stats)
    print("stats:\n", reloaded_campaign.get_last_analysis())
github UCL-CCS / EasyVVUQ / tests / test_gauss_custom_encoder.py View on Github external
# Draw samples
    my_campaign.draw_samples(num_samples=number_of_samples,
                             replicas=number_of_replicas)

    # TODO: Assert no. samples in db = number_of_samples*number_of_replicas

    my_campaign.populate_runs_dir()

    assert (len(my_campaign.get_campaign_runs_dir()) > 0)
    runs_dir = my_campaign.get_campaign_runs_dir()
    assert (os.path.exists(runs_dir))
    assert (os.path.isdir(runs_dir))

    my_campaign.apply_for_each_run_dir(
        uq.actions.ExecuteLocal("tests/gauss/gauss_json.py gauss_in.json"))

    my_campaign.collate()

    # Create a EnsembleBoot analysis element and apply it to the campaign
    stats = uq.analysis.EnsembleBoot(groupby=["mu"], qoi_cols=["Value"])
    my_campaign.apply_analysis(stats)
    print("stats:", my_campaign.get_last_analysis())
github UCL-CCS / EasyVVUQ / tests / test_multiapp.py View on Github external
encoder = uq.encoders.GenericEncoder(
        template_fname='tests/cooling/cooling.template',
        delimiter='$',
        target_filename='cooling_in.json')
    decoder = uq.decoders.SimpleCSV(target_filename=output_filename,
                                    output_columns=output_columns,
                                    header=0)
    collater = uq.collate.AggregateSamples(average=False)

    vary = {
        "kappa": cp.Uniform(0.025, 0.075),
        "t_env": cp.Uniform(15, 25)
    }
    cooling_sampler = uq.sampling.PCESampler(vary=vary, polynomial_order=3)
    cooling_action = uq.actions.ExecuteLocal("tests/cooling/cooling_model.py cooling_in.json")
    cooling_stats = uq.analysis.PCEAnalysis(sampler=cooling_sampler, qoi_cols=output_columns)

    return params, encoder, decoder, collater, cooling_sampler, cooling_action, cooling_stats
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_pce_tutorial.py View on Github external
"t_env": cp.Uniform(15, 25)
}
my_sampler = uq.sampling.PCESampler(vary=vary,
                                    polynomial_order=3)

# Associate the sampler with the campaign
my_campaign.set_sampler(my_sampler)

# Will draw all (of the finite set of samples)
my_campaign.draw_samples()

my_campaign.populate_runs_dir()

cwd = os.getcwd()
cmd = f"{cwd}/cooling_model.py cooling_in.json"
my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(cmd, interpret='python3'))
my_campaign.collate()

# Post-processing analysis
my_analysis = uq.analysis.PCEAnalysis(sampler=my_sampler,
                                          qoi_cols=["te"])
my_campaign.apply_analysis(my_analysis)

# Get Descriptive Statistics
results = my_campaign.get_last_analysis()
stats = results['statistical_moments']['te']
per = results['percentiles']['te']
sobols = results['sobols_first']['te']