Skip to content

Commit

Permalink
print formatting fix for dag
Browse files Browse the repository at this point in the history
  • Loading branch information
mjschmidt271 committed Nov 7, 2024
1 parent 3620a08 commit 4bb84d0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 121 deletions.
40 changes: 16 additions & 24 deletions components/eamxx/src/control/atmosphere_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ void AtmosphereDriver::create_atm_processes()
// First, add all atm processes
dag.init_atm_proc_nodes(*m_atm_process_group);
// Write a dot file for visualization
dag.write_dag("createProc_dag.dot", std::max(verb_lvl, 0));
if (m_atm_comm.am_i_root()) {
dag.write_dag("scream_atm_createProc_dag.dot", std::max(verb_lvl, 0));
}
}
}

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

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

// Write a dot file for visualization
dag.write_dag("createField_dag.dot", std::max(verb_lvl,0));
if (m_atm_comm.am_i_root()) {
dag.write_dag("scream_atm_createField_dag.dot", std::max(verb_lvl,0));
}
}

m_ad_status |= s_fields_created;
Expand Down Expand Up @@ -903,9 +907,11 @@ initialize_fields ()
// First, add all atm processes
dag.create_dag(*m_atm_process_group);
// process the initial conditions to maybe fulfill unmet dependencies
dag.process_IC_alt(m_fields_inited);
dag.process_initial_conditions(m_fields_inited);
// Write a dot file for visualization
dag.write_dag("initField_dag.dot", std::max(verb_lvl,0));
if (m_atm_comm.am_i_root()) {
dag.write_dag("scream_atm_initField_dag.dot", std::max(verb_lvl,0));
}
}

// Initialize fields
Expand Down Expand Up @@ -1129,7 +1135,6 @@ void AtmosphereDriver::set_initial_conditions ()
grid_name == "Point Grid") {
this_grid_topo_file_fnames.push_back("PHIS_d");
this_grid_topo_eamxx_fnames.push_back(fname);
// FIXME:
m_fields_inited[grid_name].push_back(fname);
} else {
EKAT_ERROR_MSG ("Error! Requesting phis on an unknown grid: " + grid_name + ".\n");
Expand Down Expand Up @@ -1245,11 +1250,6 @@ void AtmosphereDriver::set_initial_conditions ()
: ic_pl.get<std::string>("topography_filename");
m_iop->setup_io_info(file_name, it.second->get_grid());
}
// // f_iop is std::map<std::string, Field>
// auto f_iop = m_iop->get_iop_field_map();
// for (const auto &f : f_iop) {
// m_fields_inited[grid_name].push_back(f.first);
// }
}
}

Expand All @@ -1269,7 +1269,6 @@ void AtmosphereDriver::set_initial_conditions ()
ic_fields_names[grid_name],
m_current_ts,
it.second);
// m_fields_inited[grid_name].push_back(ic_fields_names[grid_name]);
}
}
}
Expand All @@ -1294,8 +1293,6 @@ void AtmosphereDriver::set_initial_conditions ()
// Get the two fields, and copy src to tgt
auto f_tgt = fm->get_field(tgt_fname);
auto f_src = fm->get_field(src_fname);
// FIXME:
// m_fields_inited[gname].push_back(tgt_fname);
f_tgt.deep_copy(f_src);

// Set the initial time stamp
Expand Down Expand Up @@ -1351,10 +1348,6 @@ void AtmosphereDriver::set_initial_conditions ()
read_fields_from_file (topography_file_fields_names[grid_name],
topography_eamxx_fields_names[grid_name],
io_grid,file_name,m_current_ts);
// auto &f_grid = topography_eamxx_fields_names[grid_name];
// for (const auto &f : f_grid) {
// m_fields_inited[grid_name].push_back(f);
// }
} else {
// For IOP enabled, we load from file and copy data from the closest
// lat/lon column to every other column
Expand All @@ -1363,7 +1356,6 @@ void AtmosphereDriver::set_initial_conditions ()
topography_eamxx_fields_names[grid_name],
m_current_ts,
it.second);
// m_fields_inited[grid_name].push_back(topography_eamxx_fields_names[grid_name]);
}
}
// Store in provenance list, for later usage in output file metadata
Expand Down Expand Up @@ -1534,8 +1526,6 @@ read_fields_from_file (const std::vector<std::string>& field_names,
std::vector<Field> fields;
for (const auto& fn : field_names) {
fields.push_back(field_mgr->get_field(fn));
// // FIXME:
// m_fields_inited[grid->name()].push_back(fn);
}

AtmosphereInput ic_reader(file_name,grid,fields);
Expand Down Expand Up @@ -1659,14 +1649,16 @@ void AtmosphereDriver::initialize_atm_procs ()
if (verb_lvl>0) {
// now that we've got fields, generate a DAG with fields and dependencies
// NOTE: at this point, fields provided by initial conditions may (will)
// appear as unment dependencies
// appear as unmet dependencies
AtmProcDAG dag;
// First, add all atm processes
dag.create_dag(*m_atm_process_group);
// process the initial conditions to maybe fulfill unmet dependencies
dag.process_IC_alt(m_fields_inited);
dag.process_initial_conditions(m_fields_inited);
// Write a dot file for visualization
dag.write_dag("initProc_dag.dot", std::max(verb_lvl,0));
if (m_atm_comm.am_i_root()) {
dag.write_dag("scream_atm_initProc_dag.dot", std::max(verb_lvl,0));
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/eamxx/src/control/atmosphere_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ class AtmosphereDriver
// Current simulation casename
std::string m_casename;

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

} // namespace control
Expand Down
142 changes: 48 additions & 94 deletions components/eamxx/src/share/atm_process/atmosphere_process_dag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ void AtmProcDAG::write_dag (const std::string& fname, const int verbosity) const
id_end = n.id;
box_fmt = " color=\"#88621e\"\n fontcolor=\"#88621e\"\n style=filled\n"
" fillcolor=\"#dccfb9\"\n";
} else {
box_fmt = "penwidth=4\n fontsize=30";
}

// Write node, with computed/required fields
Expand All @@ -216,59 +214,63 @@ void AtmProcDAG::write_dag (const std::string& fname, const int verbosity) const
<< " label=<\n"
<< " <table border=\"0\">\n"
<< " <tr><td><b><font point-size=\"40\">" << html_fix(n.name)
<< "</font></b></td></tr>";
<< "</font></b></td></tr>\n";
if (verbosity>1) {
// FieldIntentifier prints bare min with verb 0.
// DAG starts printing fids with verb 2, so fid verb is verb-2;
int fid_verb = verbosity-2;
ofile << "<hr/>\n";

// Computed fields
if (n.id == id_begin) {
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
<< "Atm input fields from previous time step:</font></b></td></tr>\n";
} else if (n.id == id_IC) {
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
<< "Initial Fields:</font></b></td></tr>\n";
} else if (n.id != id_end) {
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
<< "Computed Fields:</font></b></td></tr>\n";
}
ofile << " <hr/>\n";

for (const auto& fid : n.computed) {
std::string fc = "<font color=\"";
fc += "black";
fc += "\"> ";
ofile << " <tr><td align=\"left\">" << fc
<< html_fix(print_fid(m_fids[fid],fid_verb))
<< "</font></td></tr>\n";
}
if (n.computed.size() > 0) {
// Computed fields
if (n.id == id_begin) {
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
<< "Atm input fields from previous time step:</font></b></td></tr>\n";
} else if (n.id == id_IC) {
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
<< "Initial Fields:</font></b></td></tr>\n";
} else if (n.id != id_end) {
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
<< "Computed Fields:</font></b></td></tr>\n";
}

// Required fields
if (n.id == id_end) {
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
<< "Atm output fields for next time step:</font></b></td></tr>\n";
} else if (n.id != id_begin && n.id != id_IC) {
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
<< "Required Fields:</font></b></td></tr>\n";
}
for (const auto& fid : n.required) {
std::string fc = "<font color=\"";
if (ekat::contains(unmet, fid)) {
fc += "red";
} else if (ekat::contains(unmet, -fid)) {
fc += "#006219";
} else {
for (const auto& fid : n.computed) {
std::string fc = "<font color=\"";
fc += "black";
fc += "\"> ";
ofile << " <tr><td align=\"left\">" << fc
<< html_fix(print_fid(m_fids[fid],fid_verb))
<< "</font></td></tr>\n";
}
fc += "\"> ";
ofile << " <tr><td align=\"left\">" << fc << html_fix(print_fid(m_fids[fid],fid_verb));
if (ekat::contains(m_unmet_deps.at(n.id), fid)) {
ofile << "<b> *** MISSING ***</b>";
} else if (ekat::contains(m_unmet_deps.at(n.id), -fid)) {
ofile << "<b> (Init. Cond.)</b>";
}

if (n.required.size() > 0) {
// Required fields
if (n.id == id_end) {
ofile << " <tr><td align=\"left\"><b><font color=\"#88621e\">"
<< "Atm output fields for next time step:</font></b></td></tr>\n";
} else if (n.id != id_begin && n.id != id_IC) {
ofile << " <tr><td align=\"left\"><b><font color=\"#00667E\">"
<< "Required Fields:</font></b></td></tr>\n";
}
for (const auto& fid : n.required) {
std::string fc = "<font color=\"";
if (ekat::contains(unmet, fid)) {
fc += "red";
} else if (ekat::contains(unmet, -fid)) {
fc += "#006219";
} else {
fc += "black";
}
fc += "\"> ";
ofile << " <tr><td align=\"left\">" << fc << html_fix(print_fid(m_fids[fid],fid_verb));
if (ekat::contains(m_unmet_deps.at(n.id), fid)) {
ofile << "<b> *** MISSING ***</b>";
} else if (ekat::contains(m_unmet_deps.at(n.id), -fid)) {
ofile << "<b> (Init. Cond.)</b>";
}
ofile << "</font></td></tr>\n";
}
ofile << "</font></td></tr>\n";
}

// Computed groups
Expand Down Expand Up @@ -578,60 +580,12 @@ void AtmProcDAG::add_edges () {
}

void AtmProcDAG::process_initial_conditions(const grid_field_map &ic_inited) {
// return if there's nothing to do
if (ic_inited.size() == 0) {
return;
}
// Create a node for the ICs
int id = m_nodes.size();
m_nodes.push_back(Node());
Node& ic_node = m_nodes.back();
ic_node.id = id;
ic_node.name = "Initial Conditions";
m_unmet_deps[id].clear();
for (auto &node : m_nodes) {
if (m_unmet_deps.at(node.id).empty()) {
continue;
} else {
// NOTE: node_unmet_fields is a std::set<int>
auto &node_unmet_fields = m_unmet_deps.at(node.id);
// add the current node as a child of the IC node
ic_node.children.push_back(node.id);
for (auto um_fid : node_unmet_fields) {
for (auto &it1 : ic_inited) {
const auto &grid_name = it1.first;
// if this unmet-dependency field's name is in the ic_inited map for
// the provided grid_name key, then we flip its value negative and
// break from the for (ic_inited) and for (node_unmet_fields) loops;
// otherwise, keep trying for the next grid_name
if (ekat::contains(ic_inited.at(grid_name), m_fids[um_fid].name())) {
auto id_now_met = node_unmet_fields.extract(um_fid);
id_now_met.value() = -id_now_met.value();
node_unmet_fields.insert(std::move(id_now_met));
// add the fid of the formerly unmet dep to the initial condition
// node's computed list
ic_node.computed.insert(um_fid);
goto endloop;
} else {
continue;
}
}
endloop:;
}
}
}
m_IC_processed = true;
}

void AtmProcDAG::process_IC_alt(const grid_field_map &ic_inited) {
// First, add the fields that were determined to come from the previous time
// step => IC for t = 0
// get the begin_node since the IC is identical at first
const Node &begin_node = m_nodes[m_nodes.size() - 2];
int id = m_nodes.size();
// Create a node for the ICs by copying the begin_node
// FIXME:(?) do we need an explicit copy constructor given that a Node is
// just a struct?
m_nodes.push_back(Node(begin_node));
Node& ic_node = m_nodes.back();
// now set/clear the basic data for the ic_node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AtmProcDAG {

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

void init_atm_proc_nodes(const group_type& atm_procs);

Expand Down

0 comments on commit 4bb84d0

Please sign in to comment.