Skip to content

Commit 4bb84d0

Browse files
committed
print formatting fix for dag
1 parent 3620a08 commit 4bb84d0

File tree

4 files changed

+66
-121
lines changed

4 files changed

+66
-121
lines changed

components/eamxx/src/control/atmosphere_driver.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ void AtmosphereDriver::create_atm_processes()
248248
// First, add all atm processes
249249
dag.init_atm_proc_nodes(*m_atm_process_group);
250250
// Write a dot file for visualization
251-
dag.write_dag("createProc_dag.dot", std::max(verb_lvl, 0));
251+
if (m_atm_comm.am_i_root()) {
252+
dag.write_dag("scream_atm_createProc_dag.dot", std::max(verb_lvl, 0));
253+
}
252254
}
253255
}
254256

@@ -702,14 +704,16 @@ void AtmosphereDriver::create_fields()
702704
if (verb_lvl>0) {
703705
// now that we've got fields, generate a DAG with fields and dependencies
704706
// NOTE: at this point, fields provided by initial conditions may (will)
705-
// appear as unment dependencies
707+
// appear as unmet dependencies
706708
AtmProcDAG dag;
707709

708710
// First, add all atm processes
709711
dag.create_dag(*m_atm_process_group);
710712

711713
// Write a dot file for visualization
712-
dag.write_dag("createField_dag.dot", std::max(verb_lvl,0));
714+
if (m_atm_comm.am_i_root()) {
715+
dag.write_dag("scream_atm_createField_dag.dot", std::max(verb_lvl,0));
716+
}
713717
}
714718

715719
m_ad_status |= s_fields_created;
@@ -903,9 +907,11 @@ initialize_fields ()
903907
// First, add all atm processes
904908
dag.create_dag(*m_atm_process_group);
905909
// process the initial conditions to maybe fulfill unmet dependencies
906-
dag.process_IC_alt(m_fields_inited);
910+
dag.process_initial_conditions(m_fields_inited);
907911
// Write a dot file for visualization
908-
dag.write_dag("initField_dag.dot", std::max(verb_lvl,0));
912+
if (m_atm_comm.am_i_root()) {
913+
dag.write_dag("scream_atm_initField_dag.dot", std::max(verb_lvl,0));
914+
}
909915
}
910916

911917
// Initialize fields
@@ -1129,7 +1135,6 @@ void AtmosphereDriver::set_initial_conditions ()
11291135
grid_name == "Point Grid") {
11301136
this_grid_topo_file_fnames.push_back("PHIS_d");
11311137
this_grid_topo_eamxx_fnames.push_back(fname);
1132-
// FIXME:
11331138
m_fields_inited[grid_name].push_back(fname);
11341139
} else {
11351140
EKAT_ERROR_MSG ("Error! Requesting phis on an unknown grid: " + grid_name + ".\n");
@@ -1245,11 +1250,6 @@ void AtmosphereDriver::set_initial_conditions ()
12451250
: ic_pl.get<std::string>("topography_filename");
12461251
m_iop->setup_io_info(file_name, it.second->get_grid());
12471252
}
1248-
// // f_iop is std::map<std::string, Field>
1249-
// auto f_iop = m_iop->get_iop_field_map();
1250-
// for (const auto &f : f_iop) {
1251-
// m_fields_inited[grid_name].push_back(f.first);
1252-
// }
12531253
}
12541254
}
12551255

@@ -1269,7 +1269,6 @@ void AtmosphereDriver::set_initial_conditions ()
12691269
ic_fields_names[grid_name],
12701270
m_current_ts,
12711271
it.second);
1272-
// m_fields_inited[grid_name].push_back(ic_fields_names[grid_name]);
12731272
}
12741273
}
12751274
}
@@ -1294,8 +1293,6 @@ void AtmosphereDriver::set_initial_conditions ()
12941293
// Get the two fields, and copy src to tgt
12951294
auto f_tgt = fm->get_field(tgt_fname);
12961295
auto f_src = fm->get_field(src_fname);
1297-
// FIXME:
1298-
// m_fields_inited[gname].push_back(tgt_fname);
12991296
f_tgt.deep_copy(f_src);
13001297

13011298
// Set the initial time stamp
@@ -1351,10 +1348,6 @@ void AtmosphereDriver::set_initial_conditions ()
13511348
read_fields_from_file (topography_file_fields_names[grid_name],
13521349
topography_eamxx_fields_names[grid_name],
13531350
io_grid,file_name,m_current_ts);
1354-
// auto &f_grid = topography_eamxx_fields_names[grid_name];
1355-
// for (const auto &f : f_grid) {
1356-
// m_fields_inited[grid_name].push_back(f);
1357-
// }
13581351
} else {
13591352
// For IOP enabled, we load from file and copy data from the closest
13601353
// lat/lon column to every other column
@@ -1363,7 +1356,6 @@ void AtmosphereDriver::set_initial_conditions ()
13631356
topography_eamxx_fields_names[grid_name],
13641357
m_current_ts,
13651358
it.second);
1366-
// m_fields_inited[grid_name].push_back(topography_eamxx_fields_names[grid_name]);
13671359
}
13681360
}
13691361
// Store in provenance list, for later usage in output file metadata
@@ -1534,8 +1526,6 @@ read_fields_from_file (const std::vector<std::string>& field_names,
15341526
std::vector<Field> fields;
15351527
for (const auto& fn : field_names) {
15361528
fields.push_back(field_mgr->get_field(fn));
1537-
// // FIXME:
1538-
// m_fields_inited[grid->name()].push_back(fn);
15391529
}
15401530

15411531
AtmosphereInput ic_reader(file_name,grid,fields);
@@ -1659,14 +1649,16 @@ void AtmosphereDriver::initialize_atm_procs ()
16591649
if (verb_lvl>0) {
16601650
// now that we've got fields, generate a DAG with fields and dependencies
16611651
// NOTE: at this point, fields provided by initial conditions may (will)
1662-
// appear as unment dependencies
1652+
// appear as unmet dependencies
16631653
AtmProcDAG dag;
16641654
// First, add all atm processes
16651655
dag.create_dag(*m_atm_process_group);
16661656
// process the initial conditions to maybe fulfill unmet dependencies
1667-
dag.process_IC_alt(m_fields_inited);
1657+
dag.process_initial_conditions(m_fields_inited);
16681658
// Write a dot file for visualization
1669-
dag.write_dag("initProc_dag.dot", std::max(verb_lvl,0));
1659+
if (m_atm_comm.am_i_root()) {
1660+
dag.write_dag("scream_atm_initProc_dag.dot", std::max(verb_lvl,0));
1661+
}
16701662
}
16711663
}
16721664

components/eamxx/src/control/atmosphere_driver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ class AtmosphereDriver
264264
// Current simulation casename
265265
std::string m_casename;
266266

267-
// TODO: might be a better place to put this?
268-
std::map<std::string,std::vector<std::string>> m_fields_inited;
267+
// maps grid name to a vector of its initialized fields
268+
std::map<std::string, std::vector<std::string>> m_fields_inited;
269269
};
270270

271271
} // namespace control

components/eamxx/src/share/atm_process/atmosphere_process_dag.cpp

Lines changed: 48 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ void AtmProcDAG::write_dag (const std::string& fname, const int verbosity) const
202202
id_end = n.id;
203203
box_fmt = " color=\"#88621e\"\n fontcolor=\"#88621e\"\n style=filled\n"
204204
" fillcolor=\"#dccfb9\"\n";
205-
} else {
206-
box_fmt = "penwidth=4\n fontsize=30";
207205
}
208206

209207
// Write node, with computed/required fields
@@ -216,59 +214,63 @@ void AtmProcDAG::write_dag (const std::string& fname, const int verbosity) const
216214
<< " label=<\n"
217215
<< " <table border=\"0\">\n"
218216
<< " <tr><td><b><font point-size=\"40\">" << html_fix(n.name)
219-
<< "</font></b></td></tr>";
217+
<< "</font></b></td></tr>\n";
220218
if (verbosity>1) {
221219
// FieldIntentifier prints bare min with verb 0.
222220
// DAG starts printing fids with verb 2, so fid verb is verb-2;
223221
int fid_verb = verbosity-2;
224-
ofile << "<hr/>\n";
225-
226-
// Computed fields
227-
if (n.id == id_begin) {
228-
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
229-
<< "Atm input fields from previous time step:</font></b></td></tr>\n";
230-
} else if (n.id == id_IC) {
231-
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
232-
<< "Initial Fields:</font></b></td></tr>\n";
233-
} else if (n.id != id_end) {
234-
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
235-
<< "Computed Fields:</font></b></td></tr>\n";
236-
}
222+
ofile << " <hr/>\n";
237223

238-
for (const auto& fid : n.computed) {
239-
std::string fc = "<font color=\"";
240-
fc += "black";
241-
fc += "\"> ";
242-
ofile << " <tr><td align=\"left\">" << fc
243-
<< html_fix(print_fid(m_fids[fid],fid_verb))
244-
<< "</font></td></tr>\n";
245-
}
224+
if (n.computed.size() > 0) {
225+
// Computed fields
226+
if (n.id == id_begin) {
227+
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
228+
<< "Atm input fields from previous time step:</font></b></td></tr>\n";
229+
} else if (n.id == id_IC) {
230+
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
231+
<< "Initial Fields:</font></b></td></tr>\n";
232+
} else if (n.id != id_end) {
233+
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
234+
<< "Computed Fields:</font></b></td></tr>\n";
235+
}
246236

247-
// Required fields
248-
if (n.id == id_end) {
249-
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
250-
<< "Atm output fields for next time step:</font></b></td></tr>\n";
251-
} else if (n.id != id_begin && n.id != id_IC) {
252-
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
253-
<< "Required Fields:</font></b></td></tr>\n";
254-
}
255-
for (const auto& fid : n.required) {
256-
std::string fc = "<font color=\"";
257-
if (ekat::contains(unmet, fid)) {
258-
fc += "red";
259-
} else if (ekat::contains(unmet, -fid)) {
260-
fc += "#006219";
261-
} else {
237+
for (const auto& fid : n.computed) {
238+
std::string fc = "<font color=\"";
262239
fc += "black";
240+
fc += "\"> ";
241+
ofile << " <tr><td align=\"left\">" << fc
242+
<< html_fix(print_fid(m_fids[fid],fid_verb))
243+
<< "</font></td></tr>\n";
263244
}
264-
fc += "\"> ";
265-
ofile << " <tr><td align=\"left\">" << fc << html_fix(print_fid(m_fids[fid],fid_verb));
266-
if (ekat::contains(m_unmet_deps.at(n.id), fid)) {
267-
ofile << "<b> *** MISSING ***</b>";
268-
} else if (ekat::contains(m_unmet_deps.at(n.id), -fid)) {
269-
ofile << "<b> (Init. Cond.)</b>";
245+
}
246+
247+
if (n.required.size() > 0) {
248+
// Required fields
249+
if (n.id == id_end) {
250+
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
251+
<< "Atm output fields for next time step:</font></b></td></tr>\n";
252+
} else if (n.id != id_begin && n.id != id_IC) {
253+
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
254+
<< "Required Fields:</font></b></td></tr>\n";
255+
}
256+
for (const auto& fid : n.required) {
257+
std::string fc = "<font color=\"";
258+
if (ekat::contains(unmet, fid)) {
259+
fc += "red";
260+
} else if (ekat::contains(unmet, -fid)) {
261+
fc += "#006219";
262+
} else {
263+
fc += "black";
264+
}
265+
fc += "\"> ";
266+
ofile << " <tr><td align=\"left\">" << fc << html_fix(print_fid(m_fids[fid],fid_verb));
267+
if (ekat::contains(m_unmet_deps.at(n.id), fid)) {
268+
ofile << "<b> *** MISSING ***</b>";
269+
} else if (ekat::contains(m_unmet_deps.at(n.id), -fid)) {
270+
ofile << "<b> (Init. Cond.)</b>";
271+
}
272+
ofile << "</font></td></tr>\n";
270273
}
271-
ofile << "</font></td></tr>\n";
272274
}
273275

274276
// Computed groups
@@ -578,60 +580,12 @@ void AtmProcDAG::add_edges () {
578580
}
579581

580582
void AtmProcDAG::process_initial_conditions(const grid_field_map &ic_inited) {
581-
// return if there's nothing to do
582-
if (ic_inited.size() == 0) {
583-
return;
584-
}
585-
// Create a node for the ICs
586-
int id = m_nodes.size();
587-
m_nodes.push_back(Node());
588-
Node& ic_node = m_nodes.back();
589-
ic_node.id = id;
590-
ic_node.name = "Initial Conditions";
591-
m_unmet_deps[id].clear();
592-
for (auto &node : m_nodes) {
593-
if (m_unmet_deps.at(node.id).empty()) {
594-
continue;
595-
} else {
596-
// NOTE: node_unmet_fields is a std::set<int>
597-
auto &node_unmet_fields = m_unmet_deps.at(node.id);
598-
// add the current node as a child of the IC node
599-
ic_node.children.push_back(node.id);
600-
for (auto um_fid : node_unmet_fields) {
601-
for (auto &it1 : ic_inited) {
602-
const auto &grid_name = it1.first;
603-
// if this unmet-dependency field's name is in the ic_inited map for
604-
// the provided grid_name key, then we flip its value negative and
605-
// break from the for (ic_inited) and for (node_unmet_fields) loops;
606-
// otherwise, keep trying for the next grid_name
607-
if (ekat::contains(ic_inited.at(grid_name), m_fids[um_fid].name())) {
608-
auto id_now_met = node_unmet_fields.extract(um_fid);
609-
id_now_met.value() = -id_now_met.value();
610-
node_unmet_fields.insert(std::move(id_now_met));
611-
// add the fid of the formerly unmet dep to the initial condition
612-
// node's computed list
613-
ic_node.computed.insert(um_fid);
614-
goto endloop;
615-
} else {
616-
continue;
617-
}
618-
}
619-
endloop:;
620-
}
621-
}
622-
}
623-
m_IC_processed = true;
624-
}
625-
626-
void AtmProcDAG::process_IC_alt(const grid_field_map &ic_inited) {
627583
// First, add the fields that were determined to come from the previous time
628584
// step => IC for t = 0
629585
// get the begin_node since the IC is identical at first
630586
const Node &begin_node = m_nodes[m_nodes.size() - 2];
631587
int id = m_nodes.size();
632588
// Create a node for the ICs by copying the begin_node
633-
// FIXME:(?) do we need an explicit copy constructor given that a Node is
634-
// just a struct?
635589
m_nodes.push_back(Node(begin_node));
636590
Node& ic_node = m_nodes.back();
637591
// now set/clear the basic data for the ic_node

components/eamxx/src/share/atm_process/atmosphere_process_dag.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class AtmProcDAG {
1818

1919
using grid_field_map = std::map<std::string,std::vector<std::string>>;
2020
void process_initial_conditions(const grid_field_map &ic_inited);
21-
void process_IC_alt(const grid_field_map &ic_inited);
2221

2322
void init_atm_proc_nodes(const group_type& atm_procs);
2423

0 commit comments

Comments
 (0)