Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"min": 0.0,
"max": 1000.0,
"default": 9.8},
"mass": {
"type": "float",
"min": 0.0001,
"max": 1000.0,
"default": 1.0},
"velocity": {
"type": "float",
"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)
print("Serialized encoder:", encoder.serialize())
print("Serialized decoder:", decoder.serialize())
# Add the cannonsim app
my_campaign.add_app(name="cannonsim",
params=params,
encoder=encoder,
decoder=decoder)
"max": 1.0,
"default": 0.5},
"x6": {
"type": "float",
"min": 0.0,
"max": 1.0,
"default": 0.5},
"out_file": {
"type": "string",
"default": "output.csv"}}
output_filename = params["out_file"]["default"]
output_columns = ["f"]
# Create an encoder, decoder and collation element
encoder = uq.encoders.GenericEncoder(
template_fname=HOME + '/sc/sobol.template',
delimiter='$',
target_filename='poly_in.json')
decoder = uq.decoders.SimpleCSV(target_filename=output_filename,
output_columns=output_columns,
header=0)
collater = uq.collate.AggregateSamples(average=False)
# Add the SC app (automatically set as current app)
my_campaign.add_app(name="sc",
params=params,
encoder=encoder,
decoder=decoder,
collater=collater)
# Create the sampler
"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"}}
output_filename = params["out_file"]["default"]
output_columns = ["te", "ti"]
# Create an encoder and decoder for QMC test app
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)
# Add the PC app (automatically set as current app)
my_campaign.add_app(name="qmc",
params=params,
encoder=encoder,
decoder=decoder
)
# Create a collation element for this campaign
collater = uq.collate.AggregateSamples(average=False)
"min": 0.0,
"max": 1000.0,
"default": 9.8},
"mass": {
"type": "float",
"min": 0.0001,
"max": 1000.0,
"default": 1.0},
"velocity": {
"type": "float",
"min": 0.0,
"max": 1000.0,
"default": 10.0}}
# Create an encoder, decoder and collater 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)
collater = uq.collate.AggregateSamples(average=False)
# Add the cannonsim app
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
"min": 0.0,
"max": 1000.0,
"default": 9.8},
"mass": {
"type": "float",
"min": 0.0001,
"max": 1000.0,
"default": 1.0},
"velocity": {
"type": "float",
"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')
output_cols = ['Dist', 'lastvx', 'lastvy']
decoder = uq.decoders.SimpleCSV(
target_filename='output.csv', output_columns=output_cols, header=0)
# Create a collation element for this campaign
collater = uq.collate.AggregateByVariables(average=False)
# Make a random sampler
sweep = {
"angle": [0.1, 0.2, 0.3],
"height": [2.0, 10.0],
"velocity": [10.0, 10.1, 10.2]
}
sampler = uq.sampling.BasicSweep(sweep=sweep)
def test_encoder(restart):
app = restart.campaign_db.app('gauss')
encoder = uq.encoders.GenericEncoder(template_fname='tests/gauss/gauss.template',
target_filename='gauss_in.json')
assert(app['input_encoder'] == encoder.serialize())
my_campaign = uq.Campaign(name='sc', work_dir='/tmp')
# Define parameter space
params = {}
for i in range(10):
params["x%d" % (i + 1)] = {"type": "float",
"min": 0.0,
"max": 1.0,
"default": 0.5}
params["out_file"] = {"type": "string", "default": "output.csv"}
output_filename = params["out_file"]["default"]
output_columns = ["f"]
# Create an encoder, decoder and collation element
encoder = uq.encoders.GenericEncoder(
template_fname='tests/sc/poly_model_anisotropic.template',
delimiter='$',
target_filename='poly_in.json')
decoder = uq.decoders.SimpleCSV(target_filename=output_filename,
output_columns=output_columns,
header=0)
collater = uq.collate.AggregateSamples(average=False)
# Add the SC app (automatically set as current app)
my_campaign.add_app(name="sc",
params=params,
encoder=encoder,
decoder=decoder,
collater=collater)
# Create the sampler
"min": 0.0,
"max": 1000.0,
"default": 9.8},
"mass": {
"type": "float",
"min": 0.0001,
"max": 1000.0,
"default": 1.0},
"velocity": {
"type": "float",
"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')
output_cols = ['Dist', 'lastvx', 'lastvy']
decoder = uq.decoders.SimpleCSV(
target_filename='output.csv', output_columns=output_cols, header=0)
collater = uq.collate.AggregateSamples(average=False)
# 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=num_samples)
my_campaign = uq.Campaign(name='test', work_dir=tmpdir, db_location='sqlite:///')
"max": 1.0,
"default": 0.5},
"x5": {
"type": "float",
"min": 0.0,
"max": 1.0,
"default": 0.5},
"out_file": {
"type": "string",
"default": "output.csv"}}
output_filename = params["out_file"]["default"]
output_columns = ["f"]
# Create an encoder, decoder and collation element
encoder = uq.encoders.GenericEncoder(
template_fname=HOME + '/sobol.template',
delimiter='$',
target_filename='sobol_in.json')
decoder = uq.decoders.SimpleCSV(target_filename=output_filename,
output_columns=output_columns,
header=0)
collater = uq.collate.AggregateSamples(average=False)
# Add the SC app (automatically set as current app)
my_campaign.add_app(name="sc",
params=params,
encoder=encoder,
decoder=decoder,
collater=collater)
# Create the sampler
"num_steps": {
"type": "integer",
"min": 0,
"max": 100000,
"default": 10
},
"out_file": {
"type": "string",
"default": "output.csv"
}
}
# 3. Wrap Application
# - Define a new application (we'll call it 'gauss'), and the encoding/decoding elements it needs
# - Also requires a collation element - his will be responsible for aggregating the results
encoder = uq.encoders.GenericEncoder(template_fname=template,
target_filename=input_filename)
decoder = uq.decoders.SimpleCSV(
target_filename=out_file,
output_columns=['Step', 'Value'],
header=0)
collater = uq.collate.AggregateSamples(average=True)
my_campaign.add_app(name="gauss",
params=params,
encoder=encoder,
decoder=decoder,
collater=collater
)