Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# non-blocking. In such a case it is the job of the middleware section to keep track of
# which runs have been encoded, and updating the database (all at the end if need be) to
# indicate this to EasyVVUQ _before_ trying to run the collation/analysis section. If
# EasyVVUQ has not been informed that runs have been encoded, it will most likely just tell
# you that 'nothing has been collated' or something to that effect.
####
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())
bootstrap = uq.analysis.EnsembleBoot(groupby=['Dist'], qoi_cols=['lastv'])
with pytest.raises(RuntimeError, match=r".* lastv"):
my_campaign.apply_analysis(bootstrap)
# Print the campaign log
pprint(my_campaign._log)
print("All completed?", my_campaign.all_complete())
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)
print("All completed?", my_campaign.all_complete())
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())
# Print the campaign log
pprint(reloaded_campaign._log)
print("All completed?", reloaded_campaign.all_complete())
"min": 0.0,
"max": 1000.0,
"default": 10.0}}
# Create an encoder and decoder for the cannonsim app
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)
# Create a collation element for this campaign
collater = uq.collate.AggregateSamples(average=False)
actions = uq.actions.ExecuteLocal("tests/cannonsim/bin/cannonsim in.cannon output.csv")
stats = uq.analysis.BasicStats(qoi_cols=['Dist', 'lastvx', 'lastvy'])
# Make a random sampler
vary = {
"angle": cp.Uniform(0.0, 1.0),
"height": cp.Uniform(2.0, 10.0),
"velocity": cp.Normal(10.0, 1.0),
"mass": cp.Uniform(5.0, 1.0)
}
sampler = uq.sampling.RandomSampler(vary=vary)
campaign(tmpdir, 'cannon', 'cannonsim', params, encoder, decoder, sampler,
collater, actions, stats, vary, 5, 1)
# campaign(tmpdir, 'cannon', 'cannonsim', params, encoder, decoder, sampler,
# collater, None, stats, vary, 5, 1, call_fn=execute_cannonsim)
# Make a sweep sampler
sweep = {
"angle": [0.1, 0.2, 0.3],
"height": [2.0, 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)
# Create a collation element for this campaign
collater = uq.collate.AggregateSamples(average=False)
actions = uq.actions.ExecuteLocal("/home/hpc/pn69ju/di73kuj2/cannonsim/bin/cannonsim in.cannon output.csv")
campaign.add_app(name='cannonsim',
params=params,
encoder=encoder,
decoder=decoder,
collater=collater)
stats = uq.analysis.BasicStats(qoi_cols=['Dist', 'lastvx', 'lastvy'])
# Make a random sampler
vary = {
"angle": cp.Uniform(0.0, 1.0),
"height": cp.Uniform(2.0, 10.0),
"velocity": cp.Normal(10.0, 1.0),
"mass": cp.Uniform(5.0, 1.0)
}
sampler = uq.sampling.RandomSampler(vary=vary)
campaign.set_sampler(sampler)
campaign.draw_samples(num_samples=56, replicas=1)
cluster = SLURMCluster(job_extra=['--cluster=mpp2'], queue='mpp2_batch', cores=56, processes=56, memory='64 GB')
print(cluster.job_script())
cluster.scale(4)
client = Client(cluster)
campaign.populate_runs_dir()
campaign.apply_for_each_run_dir(actions, client)
reloaded_campaign.populate_runs_dir()
reloaded_campaign.call_for_each_run(execute_cannonsim)
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())
# Print the campaign log
pprint(reloaded_campaign._log)
print("All completed?", reloaded_campaign.all_complete())
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