How to use the easyvvuq.Campaign 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_hierarchical_sparse_grid_sc.py View on Github external
def run_campaign(poly_order, work_dir='/tmp'):
    # Set up a fresh campaign called "sc"
    my_campaign = uq.Campaign(name='sc', work_dir=work_dir)

    # Define parameter space
    params = {
        "x1": {
            "type": "float",
            "min": 0.0,
            "max": 1.0,
            "default": 0.5},
        "x2": {
            "type": "float",
            "min": 0.0,
            "max": 1.0,
            "default": 0.5},
        "x3": {
            "type": "float",
            "min": 0.0,
github UCL-CCS / EasyVVUQ / tests / test_anisotropic_order.py View on Github external
def test_anisotropic_order(tmpdir):

    # Set up a fresh campaign called "sc"
    my_campaign = uq.Campaign(name='sc', work_dir=tmpdir, db_location='sqlite:///')

    # Define parameter space
    params = {
        "Pe": {
            "type": "float",
            "min": 1.0,
            "max": 2000.0,
            "default": 100.0},
        "f": {
            "type": "float",
            "min": 0.0,
            "max": 10.0,
            "default": 1.0},
        "out_file": {
            "type": "string",
            "default": "output.csv"}}
github UCL-CCS / EasyVVUQ / tests / test_campaign_dir_prefix.py View on Github external
def test_campaign_dir_prefix(tmpdir):

    # Test inputs
    input_json = "tests/cannonsim/test_input/test_cannonsim_csv.json"
    output_json = os.path.join(tmpdir, "out_campaign_dir_prefix.json")
    alternative_prefix = "ALTERNATIVEPREFIX"

    assert(os.path.exists(input_json))

    # Build a campaign with an alternative default prefix
    my_campaign = uq.Campaign(
        state_filename=input_json, workdir=tmpdir,
        default_campaign_dir_prefix=alternative_prefix)

    assert(my_campaign is not None)
    assert(len(my_campaign.campaign_id()) > 0)
    assert(my_campaign.campaign_id().startswith(alternative_prefix))
    assert(
        my_campaign.campaign_id(
            without_prefix=True).startswith(alternative_prefix) is False)
    assert(len(my_campaign.campaign_id(without_prefix=True)) > 0)
    assert('campaign_dir_prefix' in my_campaign.app_info)
    assert(my_campaign.app_info['campaign_dir_prefix'] == alternative_prefix)

    # Save state of campaign
    my_campaign.save_state(output_json)
github UCL-CCS / EasyVVUQ / tests / test_cannonsim_csv_jsondb.py View on Github external
# 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")

    # 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())
github UCL-CCS / EasyVVUQ / tests / test_multiapp.py View on Github external
def test_multiapp(tmpdir):

    my_campaign = uq.Campaign(name='multiapp', work_dir=tmpdir)

    # Add the cannonsim app to the campaign
    (params, encoder, decoder, collater, cannon_sampler,
     cannon_action, cannon_stats) = setup_cannonsim_app()
    my_campaign.add_app(name="cannonsim",
                        params=params,
                        encoder=encoder,
                        decoder=decoder,
                        collater=collater)

    my_campaign.set_app("cannonsim")
    my_campaign.set_sampler(cannon_sampler)

    # Add the cooling app to the campaign
    (params, encoder, decoder, collater, cooling_sampler,
     cooling_action, cooling_stats) = setup_cooling_app()
github UCL-CCS / EasyVVUQ / tests / test_multiencoder.py View on Github external
def test_multiencoder(tmpdir):

    # Set up a fresh campaign called "cannon"
    my_campaign = uq.Campaign(name='cannon', work_dir=tmpdir)

    # Define parameter space for the cannonsim app
    params = {
        "angle": {
            "type": "float",
            "min": 0.0,
            "max": 6.28,
            "default": 0.79},
        "air_resistance": {
            "type": "float",
            "min": 0.0,
            "max": 1.0,
            "default": 0.2},
        "height": {
            "type": "float",
            "min": 0.0,
github UCL-CCS / EasyVVUQ / tests / SC_easyvvuq / run_SC_Fab_campaign.py View on Github external
Test problem: advection-diffusion equation: u_x - 1/Pe*u_xx = f,
with uncertain Peclet number (Pe) and scalar forcing term (f).
"""

import numpy as np
import matplotlib.pyplot as plt
import easyvvuq as uq
import os

# Input file containing information about parameters of interest
input_json = "ade_input.json"
output_json = "ade_output.json"

# 1. Initialize `Campaign` object which information on parameters to be sampled
#    and the values used for all sampling runs
my_campaign = uq.Campaign(state_filename=input_json)

# 2. Set which parameters we wish to include in the analysis and the
#    distribution from which to draw samples
m1 = 6
m2 = 6
my_campaign.vary_param("Pe", dist=uq.distributions.legendre(m1))
my_campaign.vary_param("f", dist=uq.distributions.legendre(m2))

# 3. Select the SC sampler to create a tensor grid
sc_sampler = uq.elements.sampling.SCSampler(my_campaign)
number_of_samples = sc_sampler.number_of_samples

my_campaign.add_runs(sc_sampler, max_num=number_of_samples)

# 4. Create directories containing inputs for each run containing the
#    parameters determined by the `Sampler`(s).
github UCL-CCS / EasyVVUQ / tests / test_gauss_add_default_run.py View on Github external
def test_gauss_fix(tmpdir):

    # Params for testing
    input_json = "tests/gauss/test_gauss_fix.json"
    output_json = os.path.join(tmpdir, "out_gauss.json")

    assert(os.path.exists(input_json))

    my_campaign = uq.Campaign(state_filename=input_json, workdir=tmpdir)

    assert(my_campaign is not None)
    assert("sigma" in my_campaign.params_info)
    assert("mu" in my_campaign.params_info)
    assert("num_steps" in my_campaign.params_info)
    assert("out_file" in my_campaign.params_info)

    my_campaign.add_default_run()

    assert(len(my_campaign.runs) == 1)
    assert(my_campaign.runs['Run_0']['sigma'] == '0.25')
    assert(my_campaign.runs['Run_0']['mu'] == '1')
    assert(my_campaign.runs['Run_0']['num_steps'] == '10')
    assert(my_campaign.runs['Run_0']['out_file'] == 'output.csv')

    my_campaign.populate_runs_dir()
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_pce_tutorial.py View on Github external
import easyvvuq as uq
import chaospy as cp

# Set up a fresh campaign called "coffee_pce"
my_campaign = uq.Campaign(name='coffee_pce')

# Define parameter space
params = {
    "temp_init": {"type": "float", "min": 0.0, "max": 100.0, "default": 95.0},
    "kappa": {"type": "float", "min": 0.0, "max": 0.1, "default": 0.025},
    "t_env": {"type": "float", "min": 0.0, "max": 40.0, "default": 15.0},
    "out_file": {"type": "string", "default": "output.csv"}
}

# Create an encoder and decoder for PCE test app
encoder = uq.encoders.GenericEncoder(
    template_fname='cooling.template',
    delimiter='$',
    target_filename='cooling_in.json')

decoder = uq.decoders.SimpleCSV(target_filename="output.csv",