gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
diagnostics.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
20 
21 #include "gambit/Core/core.hpp"
28 #include "gambit/cmake/cmake_variables.hpp"
29 
30 namespace Gambit
31 {
32 
35  {
36  table_formatter table("Modules", "#functions");
37  table.padding(1);
38  table.capitalize_title();
39  table.default_widths(25);
40  for (std::set<str>::const_iterator it = modules.begin(); it != modules.end(); ++it)
41  {
42  int nf = 0;
43  for (fVec::const_iterator jt = functorList.begin(); jt != functorList.end(); ++jt)
44  {
45  if ((*jt)->origin() == *it) nf++;
46  }
47  table << *it << nf;
48  }
49  std::stringstream out;
50  out << table.str();
51  if (out.str().size() > 0)
52  print_to_screen(out.str(), "module");
53  }
54 
57  {
58  bool all_good = true;
59  table_formatter table("Backends", "Version", "Path to lib", "Status ", " #func ", "#types ", "#ctors");
60  table.padding(1);
61  table.capitalize_title();
62  table.default_widths(18, 7, 70, 13, 3, 3);
63 
64  // Loop over all registered backends
65  for (std::map<str, std::set<str> >::const_iterator it = backend_versions.begin(); it != backend_versions.end(); ++it)
66  {
67  // Loop over all registered versions of this backend
68  for (std::set<str>::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt)
69  {
70  int nfuncs = 0;
71  int ntypes = 0;
72  int nctors = 0;
73 
74  // Retrieve the status and path info.
75  const str path = backendData->path(it->first,*jt); // Get the path of this backend
76  const str status = backend_status(it->first, *jt, all_good); // Save the status of this backend
77 
78  // Count up the number of functions in this version of the backend, using the registered functors.
79  for (fVec::const_iterator kt = backendFunctorList.begin(); kt != backendFunctorList.end(); ++kt)
80  {
81  if ((*kt)->origin() == it->first and (*kt)->version() == *jt) nfuncs++; // If backend matches, increment the count of the functions in this version
82  }
83 
84  // Do things specific to versions that provide classes
85  if (backendData->classloader.at(it->first+*jt))
86  {
87  std::set<str> classes = backendData->classes.at(it->first+*jt); // Retrieve classes loaded by this version
88  ntypes = classes.size(); // Get the number of classes loaded by this backend
89  for (std::set<str>::const_iterator kt = classes.begin(); kt != classes.end(); ++kt)
90  {
91  nctors += backendData->factory_args.at(it->first+*jt+*kt).size(); // Add the number of factories for this class to the total
92  }
93  }
94 
95  // Print the info
96  std::ostringstream ss1, ss2;
97  str ss1a, ss2a;
98  const str firstentry = (jt == it->second.begin() ? it->first : "");
99  ss1 << nfuncs;
100  ss2 << ntypes;
101  table << firstentry << *jt << path;
102  if (status == "OK")
103  table.green() << status;
104  else
105  table.red() << status;
106  table << " " + ss1.str() << ss2.str() << nctors;
107  }
108  }
109 
110  std::stringstream out;
111  out << "All relative paths are given with reference to " << GAMBIT_DIR << ".";
112  if (all_good) out << endl << endl << "\033[032m" << "All your backend are belong to us." << "\033[0m" << endl;
113  out << endl;
114  out << table.str();
115  if (out.str().size() > 0)
116  print_to_screen(out.str(), "backend");
117  }
118 
121  {
122  std::stringstream out;
123  table_formatter table("Model", "Parent", "Parameters");
124  table.default_widths(35);
125  table.padding(1);
126  table.capitalize_title();
127  for (pmfVec::const_iterator it = primaryModelFunctorList.begin(); it != primaryModelFunctorList.end(); ++it)
128  {
129  str model = (*it)->origin();
130  str parentof = modelInfo->get_parent(model);
131  int nparams = (*it)->valuePtr()->getNumberOfPars();
132  table << model << parentof << nparams;
133  }
134  #ifdef HAVE_GRAPHVIZ
135  // Create and spit out graph of the model hierarchy.
136  str graphfile = Utils::runtime_scratch() + "GAMBIT_model_hierarchy.gv";
137  ModelHierarchy modelGraph(*modelInfo,primaryModelFunctorList,graphfile,false);
138  out << endl << "Created graphviz model hierarchy graph in "+graphfile+"." << endl;
139  out << endl << "To get postscript plot of model hierarchy, please run: " << endl;
140  out << GAMBIT_DIR << "/Core/scripts/./graphviz.sh "+graphfile << endl;
141  #else
142  out << endl << "To get postscript plot of model hierarchy, please install graphviz, rerun cmake and remake GAMBIT." << endl;
143  #endif
144  out << table.str();
145  if (out.str().size() > 0)
146  print_to_screen(out.str(), "model");
147  }
148 
151  {
152 
153  // Default, list-format output header
154  table_formatter table("Capabilities", "Available in (modules/models)", "Available in (backends)");
155  table.padding(1);
156  table.capitalize_title();
157  table.default_widths(35, 25);
158  for (std::set<str>::const_iterator it = capabilities.begin(); it != capabilities.end(); ++it)
159  {
160  std::set<str> modset, beset;
161  str mods, bes, description;
162 
163  // Make sets of matching modules and backends
164  for (fVec::const_iterator jt = functorList.begin(); jt != functorList.end(); ++jt)
165  {
166  if ((*jt)->capability() == *it) modset.insert((*jt)->origin());
167  }
168  for (fVec::const_iterator jt = backendFunctorList.begin(); jt != backendFunctorList.end(); ++jt)
169  {
170  if ((*jt)->capability() == *it) beset.insert((*jt)->origin());
171  }
172 
173  // Make strings out of the sets
174  for (std::set<str>::const_iterator jt = modset.begin(); jt != modset.end(); ++jt)
175  {
176  if (jt != modset.begin()) mods += ", ";
177  mods += *jt;
178  }
179  for (std::set<str>::const_iterator jt = beset.begin(); jt != beset.end(); ++jt)
180  {
181  if (jt != beset.begin()) bes += ", ";
182  bes += *jt;
183  }
184 
185  // Identify the primary model parameters with their models.
186  if (mods.length() == 0 and bes.length() == 0) mods = it->substr(0,it->length()-11);
187 
188  // Print the entry in the table (list format)
189  table << *it << mods << bes;
190  }
191  std::stringstream out;
192  out << table.str();
193  if (out.str().size() > 0)
194  print_to_screen(out.str(), "capability");
195  }
196 
199  {
200  // Import scanner plugin info from ScannerBit
201  std::string output = Scanner::Plugins::plugin_info().print_all("scanner");
202  if (output.length() > 0)
203  print_to_screen(output, "scanners");
204  }
205 
208  {
209  std::string output = Scanner::Plugins::plugin_info().print_all("objective");
210  if (output.length() > 0)
211  print_to_screen(output, "objectives");
212  }
213 
215  {
216  std::string output = Scanner::Plugins::plugin_info().print_priors("priors");
217  if (output.length() > 0)
218  print_to_screen(output, "priors");
219  }
220 
222  {
223  if (command != "priors")
224  {
225  std::string output = Scanner::Plugins::plugin_info().print_priors(command);
226  if (output.length() > 0)
227  print_to_screen(output, command);
228  }
229  }
230 
233  {
234  std::stringstream out; //added this! not 'cout' but 'out'
235  for (std::set<str>::const_iterator it = modules.begin(); it != modules.end(); ++it)
236  {
237  if (command == *it)
238  {
239  out << "Information for module " << *it << "." << std::endl << std::endl;
240  table_formatter table("", "", "", "LOOP MANAGER:", "DEPENDENCIES / BACKEND REQUIREMENTS");
241  table.new_titles("Function", "Capability", "Result Type", " IS NEEDS", "[type] {type}");
242  table.padding(1);
243  table.capitalize_title();
244  table.default_widths(30, 35, 35, 19, 27);
245 
246  for (fVec::const_iterator jt = functorList.begin(); jt != functorList.end(); ++jt)
247  {
248  if ((*jt)->origin() == *it) // Module matches
249  {
250  str f = (*jt)->name();
251  str c = (*jt)->capability();
252  str t = (*jt)->type();
253  str islm = (*jt)->canBeLoopManager() ? "Yes" : "No ";
254  str nlm = (*jt)->loopManagerCapability();
255  std::set<sspair> deps = (*jt)->dependencies();
256  std::set<sspair> reqs = (*jt)->backendreqs();
257  table.no_newline() << f << c << t << (" " + islm + " " + nlm);
258 
259  if (not deps.empty())
260  {
261  for (std::set<sspair>::const_iterator kt = deps.begin(); kt != deps.end(); ++kt)
262  {
263  if (kt != deps.begin())
264  table.no_newline() << "" << "" << "" << "" << kt->first + " [" + kt->second + "]";
265  else
266  table << kt->first + " [" + kt->second + "]";
267  }
268  }
269  if (not reqs.empty())
270  {
271  for (std::set<sspair>::const_iterator kt = reqs.begin(); kt != reqs.end(); ++kt)
272  {
273  if (kt != reqs.begin() or not deps.empty())
274  table.no_newline() << "" << "" << "" << "" << kt->first + " {" + kt->second + "}";
275  else
276  table << kt->first + " {" + kt->second + "}";
277  }
278  }
279  if (reqs.empty() and deps.empty()) table << "";
280  table.newline(table.row_pos()-1);
281  }
282  }
283  out << table.str();
284  break;
285  }
286  }
287  if (out.str().size() > 0)
288  print_to_screen(out.str(), command);
289  }
290 
293  {
294  std::stringstream out;
295  //Iterate over all backends to see if command matches one of them
296  for (std::map<str, std::set<str> >::const_iterator it = backend_versions.begin(); it != backend_versions.end(); ++it)
297  {
298  if (command == it->first)
299  {
300  const std::set<str> versions = it->second;
301  bool has_classloader = false;
302  out << "Information for backend " << it->first << "." << std::endl << std::endl;
303 
304  // Loop over all registered versions of this backend
305  for (std::set<str>::const_iterator jt = versions.begin(); jt != versions.end(); ++jt)
306  {
307  bool who_cares;
308  const str path = backendData->corrected_path(it->first,*jt); // Save the path of this backend
309  const str status = backend_status(it->first, *jt, who_cares); // Save the status of this backend
310  out << "Version: " << *jt << std::endl;
311  out << "Path to library: " << path << std::endl;
312  out << "Library status: " << status << std::endl;
313  //bool first = true;
314 
315  table_formatter back_table(" Function/Variable", "Capability", "Type", "Status");
316  back_table.capitalize_title();
317  back_table.default_widths(27, 35, 40, 40);
318  back_table.padding(1);
319  back_table.top_line(true);
320  back_table.bottom_line(true);
321  // Loop over all the backend functions and variables
322  for (fVec::const_iterator kt = backendFunctorList.begin(); kt != backendFunctorList.end(); ++kt)
323  {
324  if (((*kt)->origin() == it->first) and ((*kt)->version() == (*jt)))
325  {
326  const str f = (*kt)->name();
327  const str c = (*kt)->capability();
328  const str t = (*kt)->type();
329  const int s = (*kt)->status();
330  back_table << (" " + f) << c << t;
331  if(s == -5) back_table.red() << "Mathematica absent";
332  else if (s == -2) back_table.red() << "Function absent";//ss = "Function absent";
333  else if (s == -1) back_table.red() << "Backend absent";//ss = "Backend absent";
334  else if (s >= 0) back_table.green() << "Available";//ss = "Available";
335  else back_table << "";
336  }
337  }
338  if (back_table.rows() > 0)
339  out << back_table.str();
340  table_formatter class_table(" Class", "Constructor overload", "Status");
341  class_table.capitalize_title();
342  class_table.default_widths(46, 60, 60);
343  class_table.padding(1);
344  class_table.top_line(true);
345  class_table.bottom_line(true);
346  // If this version has classes to offer, print out info on them too
347  if (backendData->classloader.at(it->first+*jt))
348  {
349  std::set<str> classes;
350  if (backendData->classes.find(it->first+*jt) != backendData->classes.end()) classes = backendData->classes.at(it->first+*jt);
351  has_classloader = true;
352  // Loop over the classes
353  for (std::set<str>::const_iterator kt = classes.begin(); kt != classes.end(); ++kt)
354  {
355  const std::set<str> ctors = backendData->factory_args.at(it->first+*jt+*kt);
356  // Loop over the constructors in each class
357  for (std::set<str>::const_iterator lt = ctors.begin(); lt != ctors.end(); ++lt)
358  {
359  str args = *lt;
360  boost::replace_all(args, "my_ns::", "");
361  const str ss = backendData->constructor_status.at(it->first+*jt+*kt+args);
362  const str firstentry = (lt == ctors.begin() ? *kt : "");
363  class_table << (" " + firstentry) << args;
364  if (ss == "OK")
365  class_table.green() << status;
366  else
367  class_table.red() << status;
368  }
369  }
370  }
371  if (class_table.rows() > 0)
372  out << class_table.str();
373  }
374  // Tell the user what the default version is for classes of this backend (if there are any).
375  if (has_classloader)
376  {
377  const std::map<str, str> defs = backendData->default_safe_versions;
378  const str my_def = (defs.find(it->first) != defs.end() ? backendData->version_from_safe_version(it->first,defs.at(it->first)) : "none");
379  out << std::endl << "Default version for loaded classes: " << my_def << std::endl << std::endl;
380  }
381  break;
382  }
383  }
384  if (out.str().size() > 0)
385  print_to_screen(out.str(), command);
386  }
387 
390  {
391  std::stringstream out;
392  //Iterate over all models to see if command matches one of them
393  for (pmfVec::const_iterator it = primaryModelFunctorList.begin(); it != primaryModelFunctorList.end(); ++it)
394  {
395  str model = (*it)->origin();
396  if (command == model)
397  {
398  out << "Information for model " << model << "." << endl << endl;;
399 
400  // Retrieve info on this capability from the database file
401  model_info mod = get_model_info(model);
402 
403  // Need copies of lineage and descendant vectors with self-reference removed
404  std::vector<str> lin_X = mod.lineage;
405  std::vector<str> des_X = mod.descendants;
406 
407  // Erase element matching name
408  lin_X.erase(std::remove(lin_X.begin(), lin_X.end(), mod.name), lin_X.end());
409  des_X.erase(std::remove(des_X.begin(), des_X.end(), mod.name), des_X.end());
410 
411  out << " Parent Model: " << mod.parent << std::endl;
412  out << " Number of parameters: " << mod.nparams << std::endl;
413  out << " Parameter names:" << mod.parameters << std::endl;
414  out << " 'Ancestor' models:" << lin_X << std::endl;
415  out << " 'Descendant' models:" << des_X << std::endl;
416  out << " Description: " << endl << mod.description << std::endl;
417 
418  break;
419  }
420  }
421  if (out.str().size() > 0)
422  print_to_screen(out.str(), command);
423  }
424 
427  {
428  std::stringstream out;
429  //Iterate over all capabilities to see if command matches one of them
430  for (std::set<str>::const_iterator it = capabilities.begin(); it != capabilities.end(); ++it)
431  {
432  if (command == *it)
433  {
434  out << "Information for capability " << *it << "." << std::endl << std::endl;
435 
436  // Retrieve info on this capability from the database file
437  const capability_info cap = get_capability_info(*it);
438  std::vector< std::pair<str, std::map<str, std::set<std::pair<str,str> > > > > origins;
439  origins.push_back(std::pair<str, std::map<str, std::set<std::pair<str,str> > > >("modules", cap.modset));
440  origins.push_back(std::pair<str, std::map<str, std::set<std::pair<str,str> > > >("backends", cap.beset));
441  // Loop over {modules, backends}
442  for (std::vector< std::pair<str, std::map<str, std::set<std::pair<str,str> > > > >::const_iterator it = origins.begin(); it != origins.end(); ++it)
443  {
444  if (not it->second.empty())
445  {
446  out << " Available in " << it->first << ": " << std::endl;
447  // Loop over modules or backends
448  for (std::map<str, std::set<std::pair<str,str> > >::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt)
449  {
450  out << " " << jt->first << ": " << std::endl;
451  // Loop over matching module/backend functions
452  for (std::set<std::pair<str,str> >::const_iterator kt = jt->second.begin(); kt != jt->second.end(); ++kt)
453  {
454  // Spit out: function name [function type]
455  out << " function " << kt->first << " [type " << kt->second << "]" << std::endl;
456  }
457  }
458  out << std::endl;
459  }
460  }
461  out << " Description: " << std::endl << cap.description << std::endl;
462  break;
463  }
464  }
465  if (out.str().size() > 0)
466  print_to_screen(out.str(), command);
467  }
468 
471  {
472  std::string output = Scanner::Plugins::plugin_info().print_plugin("scanner", command);
473  if (output.length() > 0)
474  print_to_screen(output, command);
475  }
476 
479  {
480  std::string output = Scanner::Plugins::plugin_info().print_plugin("objective", command);
481  if (output.length() > 0)
482  print_to_screen(output, command);
483  }
484 
485 }
Define overloadings of the stream operator for various containers.
std::map< str, std::set< str > > backend_versions
Map from backend names to a list of all registered versions of the backend.
Definition: core.hpp:57
table_formatter & green(int i=-1, int j=-1)
table_formatter & red(int i=-1, int j=-1)
void ff_capability_diagnostic(str &)
Free-form capability diagnostic function.
void new_titles(const T &... in)
std::map< str, std::set< std::pair< str, str > > > modset
Set of modules and module functions in which capability is used, along with corresponding result type...
str backend_status(str, str, bool &)
Compute the status of a given backend.
Definition: core.cpp:553
int nparams
Number of parameters ( parameters.size() )
void capability_diagnostic()
Basic capability diagnostic function.
std::vector< str > parameters
Parameter names.
Helper struct to carry around model information.
void model_diagnostic()
Basic model diagnostic function.
void backend_diagnostic()
Basic backend diagnostic function.
Definition: diagnostics.cpp:56
str get_parent(const str &) const
Retrieve the parent model for a given model.
Definition: models.cpp:244
fVec functorList
List of all declared module functors.
Definition: core.hpp:66
std::set< str > capabilities
List of all declared capabilities.
Definition: core.hpp:60
table_formatter & newline(int j=-1)
Utility Functions for the Gambit Scanner.
General small utility functions.
table_formatter & no_newline(int j=-1)
const capability_info get_capability_info(const str &) const
Get the description (and other info) of the named item from the capability database.
Definition: core.cpp:513
void ff_prior_diagnostic(str &)
std::set< str > modules
Set of all declared modules.
Definition: core.hpp:54
void ff_scanner_diagnostic(str &)
Free-form scanner diagnostic function.
const model_info get_model_info(const str &) const
Get the description (and other info) of the named item from the model database.
Definition: core.cpp:533
pmfVec primaryModelFunctorList
List of all declared primary model functors.
Definition: core.hpp:75
std::map< str, std::set< std::pair< str, str > > > beset
Set of backends and backend functions in which capability is used, along with corresponding type sign...
GAMBIT Core driver class.
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Model graph declarations.
void test_function_diagnostic()
Basic test function diagnostic function.
Helper struct to carry around capability information.
void scanner_diagnostic()
Basic scanner diagnostic function.
void default_widths(const T &... in)
Utility Functions for the Gambit Scanner.
void ff_test_function_diagnostic(str &)
Free-form test function diagnostic function.
EXPORT_SYMBOLS const str & runtime_scratch()
Return the path the the run-specific scratch directory.
const Models::ModelFunctorClaw * modelInfo
Internal model claw pointer.
Definition: core.hpp:48
std::vector< str > descendants
All children and later descendants.
std::vector< str > lineage
Parent and all ancestor models.
void module_diagnostic()
Basic diagnostic functions.
Definition: diagnostics.cpp:34
str description
Full description of capability.
Loader singleton class for scanner plugins.
void ff_model_diagnostic(str &)
Free-form model diagnostic function.
EXPORT_SYMBOLS pluginInfo plugin_info
Access Functor for plugin info.
void ff_module_diagnostic(str &)
Free-form diagnostic functions.
fVec backendFunctorList
List of all declared backend functors.
Definition: core.hpp:72
str parent
Parent model name.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
str description
Full description of capability.
Model hierarchy tree class.
Definition: modelgraph.hpp:36
const Backends::backend_info * backendData
Internal backend info pointer.
Definition: core.hpp:51
void ff_backend_diagnostic(str &)
Free-form backend diagnostic function.
void print_to_screen(const std::string &file_in, const std::string &name)