Skip to content
Snippets Groups Projects
Commit 0dfb5dcd authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Added option to run multiple approximations in one config file.

parent 42283d30
Branches
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ use rule * from ann_training as ANN_*
module approximation:
snakefile: DIR + '/approximation.smk'
config: config
config: {**config['Approximation'], 'data_directory': config['data_directory']}
use rule * from approximation as DG_*
......
data_directory: 'model-Feb14'
plot_dir: 'fig-Feb14'
plot_name: 'Separation-Test'
random_seed: 1234
# Parameter for Approximation with Troubled Cell Detection
dg_parameter:
Approximation:
plot_dir: 'fig-Feb14'
schemes:
Separation_Test:
wave_speed: 1
polynomial_degree: 2
cfl_number: 0.2
......@@ -36,8 +38,8 @@ dg_parameter:
num_eval_points: 12
update_scheme: 'SSPRK3'
# Test_Run:
# detector: 'Theoretical'
Test_Run:
detector: 'Theoretical'
# Parameter for Training Data Generation
ANN_Data:
......
......@@ -7,27 +7,31 @@ configfile: 'config.yaml'
PLOTS = ['error', 'exact_and_approx', 'semilog_error', 'shock_tube']
DIR = config['data_directory']
SCHEMES = config['schemes']
# if config['random_seed'] is not None:
# np.random.seed(config['random_seed'])
rule all:
input:
expand(config['plot_dir'] + '/{plot}/' + config['plot_name'] + '.pdf', plot=PLOTS)
expand(config['plot_dir'] + '/{plot}/{scheme}.pdf', plot=PLOTS, scheme=SCHEMES)
default_target: True
def get_ANN_model(wildcards):
if config['schemes'][wildcards.scheme]['detector'] == 'ArtificialNeuralNetwork':
return DIR + '/trained models/' \
+ config['schemes'][wildcards.scheme]['detector_config']['model_state']
return []
rule approximate_solution:
input:
config['data_directory'] + '/trained models/'
+ config['dg_parameter']['detector_config']['model_state']
if config['dg_parameter']['detector'] == 'ArtificialNeuralNetwork' else ''
get_ANN_model
output:
expand(config['plot_dir'] + '/{plot}/' + config['plot_name'] + '.pdf', plot=PLOTS)
expand(config['plot_dir'] + '/{plot}/{{scheme}}.pdf', plot=PLOTS)
params:
dg_params=config['dg_parameter'],
plot_dir=config['plot_dir'],
plot_name=config['plot_name']
dg_params=lambda wildcards: config['schemes'][wildcards.scheme],
plot_dir=config['plot_dir']
log:
DIR+'/log/approximate_solution.log'
DIR+'/log/approximate_solution_{scheme}.log'
run:
with open(str(log), 'w') as logfile:
sys.stdout = logfile
......@@ -35,13 +39,14 @@ rule approximate_solution:
tic = time.perf_counter()
if len(input) > 0:
params.dg_params['detector_config']['model_state'] = input
print(params.dg_params)
dg_scheme = DGScheme(plot_dir=params.plot_dir, **params.dg_params)
dg_scheme.approximate()
dg_scheme.save_plots(params.plot_name)
dg_scheme.save_plots(wildcards.scheme)
toc = time.perf_counter()
print(f'Time: {toc - tic:0.4f}s')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment