diff --git a/templates/template_driver.py b/templates/template_driver.py index dcfdf7c7..54046104 100644 --- a/templates/template_driver.py +++ b/templates/template_driver.py @@ -501,8 +501,8 @@ def _modify_outer_models(self, template, case, components, sources): text = 'Samplers|CustomSampler@name:mc_arma_dispatch|constant@name:{}' # Remove anything having to do with 'denoises', it's no longer needed. raven.remove(raven.find(".//alias[@variable='denoises']")) - denoises_parent = template.find(".//constant[@name='denoises']/..") - denoises_parent.remove(denoises_parent.find(".//constant[@name='denoises']")) + for denoises_parent in template.findall(".//constant[@name='denoises']/.."): + denoises_parent.remove(denoises_parent.find(".//constant[@name='denoises']")) # Remove any GRO_final_return vars that compute Sigma or Var (e.g. var_NPV) final_return_vars = template.find('.//VariableGroups/Group[@name="GRO_outer_results"]') new_final_return_vars = [var for var in final_return_vars.text.split(", ") if "std" not in var and "var" not in var] @@ -521,7 +521,7 @@ def _modify_outer_models(self, template, case, components, sources): if cap.is_parametric() and isinstance(cap.get_value(debug=case.debug['enabled']) , list): feature_list += name + '_capacity' + ',' feature_list = feature_list[0:-1] - if case.get_mode() == 'opt': + if case.get_mode() == 'opt' and (not case.debug['enabled']): gpr = template.find('Models').find('ROM') gpr.find('Features').text = feature_list new_opt_metric = self._build_opt_metric_out_name(case) @@ -682,7 +682,7 @@ def _modify_outer_samplers(self, template, case, components): dist, xml = self._create_new_sweep_capacity(name, var_name, vals, sampler) dists_node.append(dist) # Bayesian Optimizer requires additional modification - if case.get_opt_strategy() == 'BayesianOpt' and case.get_mode() == 'opt': + if case.get_opt_strategy() == 'BayesianOpt' and case.get_mode() == 'opt' and (not case.debug['enabled']): xml.remove(xml.find('initial')) samps_node.append(xml) grid_node = xmlUtils.newNode('grid', text='0 1', @@ -719,7 +719,7 @@ def _modify_outer_optimizers(self, template, case): """ # Setting base outer for opt based on optimizer used strategy = case.get_opt_strategy() - if case.get_mode() == 'opt': + if case.get_mode() == 'opt'and (not case.debug['enabled']): # Strategy tells us which optimizer to use if strategy == 'BayesianOpt': opt_node = template.find('Optimizers').find(".//BayesianOptimizer[@name='cap_opt']") @@ -730,8 +730,11 @@ def _modify_outer_optimizers(self, template, case): template.remove(template.find('Samplers')) template.find('Models').remove(template.find(".//ROM[@name='gpROM']")) template.find('Optimizers').remove(template.find(".//BayesianOptimizer[@name='cap_opt']")) + # if running in debug, none of these nodes should be here, skip + if case.debug['enabled']: + return # only modify if optimization_settings is in Case - if (case.get_mode() == 'opt') and (case.get_optimization_settings() is not None) and (not case.debug['enabled']): # TODO there should be a better way to handle the debug case + if (case.get_mode() == 'opt') and (case.get_optimization_settings() is not None): # TODO there should be a better way to handle the debug case optimization_settings = case.get_optimization_settings() # Strategy tells us which optimizer to use if strategy == 'BayesianOpt': diff --git a/tests/integration_tests/mechanics/debug_mode/opt/heron_input.xml b/tests/integration_tests/mechanics/debug_mode/opt/heron_input.xml new file mode 100644 index 00000000..5e9f0923 --- /dev/null +++ b/tests/integration_tests/mechanics/debug_mode/opt/heron_input.xml @@ -0,0 +1,113 @@ + + + DebugMode + talbpaul + 2021-02-22 + + Tests a debug mode of operation, where a single outer runs a single sample of inner + and outputs the optimized dispatch. + + HERON + + + + opt + + 2 + 2 + True + + 1 + + Time + 2 + 21 + + + 3 + 0.08 + 0.3 + 0.02 + 50 + + + + + + + + + + + 1, 100 + + + + 5 + + + + + + steam + + -100 + + + + -1 + 0.5 + + + + + 5 + + + + + + + -2 + + + + 30 + + + electricity + + + 0.5 + + + + + + + + + -1e200 + + + + 30 + + + electricity + + + transfers + + + + + + + + + %HERON_DATA%/TSA/Sine/arma.pk + ../transfers.py + + + diff --git a/tests/integration_tests/mechanics/debug_mode/heron_input.xml b/tests/integration_tests/mechanics/debug_mode/sweep/heron_input.xml similarity index 98% rename from tests/integration_tests/mechanics/debug_mode/heron_input.xml rename to tests/integration_tests/mechanics/debug_mode/sweep/heron_input.xml index e7a312c8..97562dcf 100644 --- a/tests/integration_tests/mechanics/debug_mode/heron_input.xml +++ b/tests/integration_tests/mechanics/debug_mode/sweep/heron_input.xml @@ -107,7 +107,7 @@ %HERON_DATA%/TSA/Sine/arma.pk - transfers.py + ../transfers.py diff --git a/tests/integration_tests/mechanics/debug_mode/tests b/tests/integration_tests/mechanics/debug_mode/tests index f525b46e..ed2f7657 100644 --- a/tests/integration_tests/mechanics/debug_mode/tests +++ b/tests/integration_tests/mechanics/debug_mode/tests @@ -1,25 +1,48 @@ [Tests] - [./DebugMode] + [./DebugModeWithSweep] type = 'HeronIntegration' - input = heron_input.xml + input = 'sweep/heron_input.xml' [./dispatch_db] type = NetCDF - output = 'Debug_Run_o/dispatch.nc' + output = 'sweep/Debug_Run_o/dispatch.nc' gold_files = 'dispatch.nc' [../] [./dispatch_csv] type = UnorderedCSV - output = 'Debug_Run_o/dispatch_print.csv' + output = 'sweep/Debug_Run_o/dispatch_print.csv' gold_files = 'dispatch_print.csv' rel_err = 1e-8 [../] [./debug_plot] type = Exists - output = 'Debug_Run_o/dispatch_id0_y10_c0_f1.png Debug_Run_o/dispatch_id0_y11_c0_f1.png Debug_Run_o/dispatch_id1_y10_c0_f1.png Debug_Run_o/dispatch_id1_y11_c0_f1.png' + output = 'sweep/Debug_Run_o/dispatch_id0_y10_c0_f1.png sweep/Debug_Run_o/dispatch_id0_y11_c0_f1.png sweep/Debug_Run_o/dispatch_id1_y10_c0_f1.png sweep/Debug_Run_o/dispatch_id1_y11_c0_f1.png' [../] [./debug_plot] type = Exists - output = 'network.png' + output = 'sweep/network.png' + [../] + [../] + [./DebugModeWithOpt] + type = 'HeronIntegration' + input = 'opt/heron_input.xml' + [./dispatch_db] + type = NetCDF + output = 'opt/Debug_Run_o/dispatch.nc' + gold_files = 'dispatch.nc' + [../] + [./dispatch_csv] + type = UnorderedCSV + output = 'opt/Debug_Run_o/dispatch_print.csv' + gold_files = 'dispatch_print.csv' + rel_err = 1e-8 + [../] + [./debug_plot] + type = Exists + output = 'opt/Debug_Run_o/dispatch_id0_y10_c0_f1.png opt/Debug_Run_o/dispatch_id0_y11_c0_f1.png opt/Debug_Run_o/dispatch_id1_y10_c0_f1.png opt/Debug_Run_o/dispatch_id1_y11_c0_f1.png' + [../] + [./debug_plot] + type = Exists + output = 'opt/network.png' [../] [../] []