How to use the easyvvuq.sampling.RandomSampler 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_gauss.py View on Github external
my_campaign.add_app(name="gauss",
                        params=params,
                        encoder=encoder,
                        decoder=decoder
                        )

    # Create a collation element for this campaign
    collater = uq.collate.AggregateSamples(average=False)
    my_campaign.set_collater(collater)

    # Make a random sampler
    vary = {
        "mu": cp.Uniform(1.0, 100.0),
    }
    sampler1 = uq.sampling.RandomSampler(vary=vary)

    # Set the campaign to use this sampler
    my_campaign.set_sampler(sampler1)

    # 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))
github UCL-CCS / EasyVVUQ / tests / test_clear_collate.py View on Github external
my_campaign.add_app(name="cannonsim",
                        params=params,
                        encoder=encoder,
                        decoder=decoder,
                        collater=collater)

    # Set the active app to be cannonsim (this is redundant when only one app
    # has been added)
    my_campaign.set_app("cannonsim")

    # Set up samplers
    vary = {
        "gravity": cp.Uniform(9.8, 1.0),
        "mass": cp.Uniform(2.0, 10.0),
    }
    sampler = uq.sampling.RandomSampler(vary=vary, max_num=5)

    # Set the campaign to use this sampler
    my_campaign.set_sampler(sampler)

    # 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()

    # Encode
    my_campaign.populate_runs_dir()

    # Execute
    my_campaign.apply_for_each_run_dir(
github UCL-CCS / EasyVVUQ / tests / test_multiapp.py View on Github external
"default": 10.0}}

    encoder = uq.encoders.GenericEncoder(
        template_fname='tests/cannonsim/test_input/cannonsim.template',
        delimiter='#',
        target_filename='in.cannon')
    decoder = uq.decoders.SimpleCSV(
        target_filename='output.csv', output_columns=[
            'Dist', 'lastvx', 'lastvy'], header=0)
    collater = uq.collate.AggregateSamples(average=False)

    vary = {
        "gravity": cp.Uniform(9.8, 1.0),
        "mass": cp.Uniform(2.0, 10.0),
    }
    cannon_sampler = uq.sampling.RandomSampler(vary=vary, max_num=5)
    cannon_action = uq.actions.ExecuteLocal("tests/cannonsim/bin/cannonsim in.cannon output.csv")
    cannon_stats = uq.analysis.BasicStats(qoi_cols=['Dist', 'lastvx', 'lastvy'])

    return params, encoder, decoder, collater, cannon_sampler, cannon_action, cannon_stats
github UCL-CCS / EasyVVUQ / tests / test_gauss_custom_encoder.py View on Github external
my_campaign.add_app(name="gauss",
                        params=params,
                        encoder=encoder,
                        decoder=decoder
                        )

    # Create a collation element for this campaign
    collater = uq.collate.AggregateSamples(average=False)
    my_campaign.set_collater(collater)

    # Make a random sampler
    vary = {
        "mu": cp.Uniform(1.0, 100.0),
    }
    sampler1 = uq.sampling.RandomSampler(vary=vary)

    # Set the campaign to use this sampler
    my_campaign.set_sampler(sampler1)

    # 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))
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_restart_campaign_tutorial.py View on Github external
collater = uq.collate.AggregateSamples(average=True)

my_campaign.add_app(name="gauss",
                    params=params,
                    encoder=encoder,
                    decoder=decoder,
                    collater=collater
                    )

# 4. Specify Sampler
#    -  vary the `mu` parameter only
vary = {
    "mu": cp.Uniform(1.0, 100.0),
}

my_sampler = uq.sampling.RandomSampler(vary=vary)

my_campaign.set_sampler(my_sampler)

# 5. Get run parameters
my_campaign.draw_samples(num_samples=3, replicas=5)

# 6. Create run input directories
my_campaign.populate_runs_dir()

# 7. Run Application
#    - gauss is executed for each sample
my_campaign.apply_for_each_run_dir(uq.actions.ExecuteLocal(cmd, interpret='python3'))

# 8. Collate output
my_campaign.collate()