gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
depresolver.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
30 
31 #ifndef __depresolver_hpp__
32 #define __depresolver_hpp__
33 
34 #include <string>
35 #include <list>
36 #include <vector>
37 #include <map>
38 #include <queue>
39 
40 #include "gambit/Core/core.hpp"
46 
47 #include <boost/graph/adjacency_list.hpp>
48 #include <boost/graph/topological_sort.hpp>
49 
50 namespace Gambit
51 {
52 
53  namespace DRes
54  {
55 
56  using namespace boost;
57 
60  typedef adjacency_list<vecS, vecS, bidirectionalS, functor*, vecS> MasterGraphType;
61  typedef graph_traits<MasterGraphType>::vertex_descriptor VertexID;
62  typedef graph_traits<MasterGraphType>::edge_descriptor EdgeID;
63  typedef property_map<MasterGraphType,vertex_index_t>::type IndexMap;
65 
68  typedef std::map<std::string, double *> inputMapType;
69  typedef std::map<std::string, std::vector<functor*> > outputMapType;
71 
74  {
75  VertexID vertex;
77  };
78 
81  struct Rule
82  {
83  Rule(std::string function, std::string module) : function(function), module(module) {};
85  {
86  module = t.module;
87  function = t.function;
88  };
89  std::string function;
90  std::string module;
91  };
92 
94  struct QueueEntry
95  {
97  QueueEntry(sspair a, DRes::VertexID b, int c, bool d)
98  {
99  first = a;
100  second = b;
101  third = c;
102  printme = d;
103  }
106  int third;
107  bool printme;
108  };
109 
111  bool stringComp(const str &s1, const str &s2, bool with_regex = true);
112 
114  bool typeComp(str, str, const Utils::type_equivalency&, bool with_regex = true);
115 
118  {
119  public:
121  DependencyResolver(const gambit_core&, const Models::ModelFunctorClaw&, const IniParser::IniFile&, const Utils::type_equivalency&, Printers::BasePrinter&);
122 
124  void doResolution();
125 
127  static MasterGraphType cullInactiveFunctors(MasterGraphType&);
128 
130  void printFunctorList();
131 
133  void printFunctorEvalOrder(bool toterminal=false);
134 
136  std::vector<VertexID> getObsLikeOrder();
137 
139  void calcObsLike(VertexID);
140 
142  void printObsLike(VertexID, const int);
143 
145  bool printTiming();
146 
148  functor* get_functor(VertexID);
149 
151  str checkTypeMatch(VertexID, const str&, const std::vector<str>&);
152 
154  template <typename TYPE>
155  TYPE getObsLike(VertexID vertex)
156  {
157  module_functor<TYPE>* module_ptr = dynamic_cast<module_functor<TYPE>*>(masterGraph[vertex]);
158  if (module_ptr == NULL)
159  {
160  str msg = "Attempted to retrieve result of " + masterGraph[vertex]->origin() + "::" +
161  masterGraph[vertex]->name() + "\nwith incorrect type. The type should be: " +
162  masterGraph[vertex]->type() + ".";
163  core_error().raise(LOCAL_INFO, msg);
164  }
165  // This always accesses the 0-index result, which is the one-thread result
166  // or the 'final result' when more than one thread has run the functor.
167  return (*module_ptr)(0);
168  }
169 
170  const IniParser::ObservableType * getIniEntry(VertexID);
171 
172  void invalidatePointAt(VertexID, bool);
173 
174  void resetAll();
175 
176  private:
178  void addFunctors();
179 
181  str printGenericFunctorList(const std::vector<functor*>&);
182  str printGenericFunctorList(const std::vector<VertexID>&);
183 
185  str printQuantityToBeResolved(const sspair & quantity, const DRes::VertexID & vertex);
186 
188  void initialisePrinter();
189 
191  void makeFunctorsModelCompatible();
192 
194  boost::tuple<const IniParser::ObservableType *, DRes::VertexID>
195  resolveDependency(DRes::VertexID toVertex, sspair quantity);
196 
198  DRes::VertexID resolveDependencyFromRules(const DRes::VertexID & toVertex, const sspair & quantity);
199 
201  Options collectIniOptions(const DRes::VertexID & vertex);
202 
204  Options collectSubCaps(const DRes::VertexID & vertex);
205 
207  void generateTree(std::queue<QueueEntry> parQueue);
208 
210  void fillParQueue(std::queue<QueueEntry> *parQueue,
211  DRes::VertexID vertex);
212 
214  std::list<VertexID> run_topological_sort();
215 
218  const IniParser::ObservableType * findIniEntry(
219  sspair quantity, const IniParser::ObservablesType &, const str &);
220  const IniParser::ObservableType * findIniEntry(
221  DRes::VertexID toVertex, const IniParser::ObservablesType &, const str &);
223 
225  void resolveVertexBackend(VertexID);
226 
228  functor* solveRequirement(std::set<sspair>, const IniParser::ObservableType*, VertexID, std::vector<functor*>, bool, str group="none");
229 
231  void resolveRequirement(functor*, VertexID);
232 
235  std::vector<DRes::VertexID> closestCandidateForModel(std::vector<DRes::VertexID> candidates);
236 
237  //
238  // Private data members
239  //
240 
243 
246 
249 
252 
254  Printers::BasePrinter *boundPrinter;
255 
257  std::vector<OutputVertexInfo> outputVertexInfos;
258 
260  MasterGraphType masterGraph;
261 
263  std::list<VertexID> function_order;
264 
266  std::map<VertexID, std::vector<VertexID>> SortedParentVertices;
267 
269  std::map<VertexID, std::set<VertexID>> loopManagerMap;
270 
273  std::map<VertexID, std::set<VertexID>> edges_to_force_on_manager;
274 
276  IndexMap index;
277 
280 
282  bool print_timing = false;
283 
285  bool print_unitcube = false;
286  };
287  }
288 }
289 #endif /* defined(__depresolver_hpp__) */
Exception object declarations.
MasterGraphType masterGraph
The central boost graph object.
graph_traits< MasterGraphType >::edge_descriptor EdgeID
Definition: depresolver.hpp:62
Structure providing type equivalency classes to the dep resolver.
QueueEntry(sspair a, DRes::VertexID b, int c, bool d)
Definition: depresolver.hpp:97
QueueEntry()
Definition: depresolver.hpp:96
Actual module functor type for all but TYPE=void.
Definition: functors.hpp:745
#define LOCAL_INFO
Definition: local_info.hpp:34
Function wrapper (functor) base class.
Definition: functors.hpp:87
std::map< VertexID, std::set< VertexID > > edges_to_force_on_manager
Map from nested function -> list of fulfilled dependencies that need to be passed on to its loop mana...
bool printme
error & core_error()
Core errors.
const IniParser::ObservableType * iniEntry
Definition: depresolver.hpp:76
std::list< VertexID > function_order
Saved calling order for functions.
bool typeComp(str, str, const Utils::type_equivalency &, bool with_regex=true)
Type comparison taking into account equivalence classes.
str origin() const
Getter for the wrapped function&#39;s origin (module or backend name)
Definition: functors.cpp:121
START_MODEL b
Definition: demo.hpp:270
sspair first
const gambit_core * boundCore
Core to which this dependency resolver is bound.
std::pair< str, str > sspair
Shorthand for a pair of standard strings.
Definition: util_types.hpp:64
Models object that performs initialisation and checking operations on a primary_model_functor list...
Definition: models.hpp:55
Master driver class for a GAMBIT scan.
Definition: core.hpp:35
graph_traits< MasterGraphType >::vertex_descriptor VertexID
Definition: depresolver.hpp:61
property_map< MasterGraphType, vertex_index_t >::type IndexMap
Definition: depresolver.hpp:63
Functor class definitions.
bool stringComp(const str &s1, const str &s2, bool with_regex=true)
Check whether s1 (wildcard + regex allowed) matches s2.
A simple rule for dependency resolution (aka constraints on module and function name).
Definition: depresolver.hpp:81
Main dependency resolver.
const Utils::type_equivalency * boundTEs
Type equivalency object to which this dependency resolver is bound.
std::map< std::string, double * > inputMapType
Typedefs for communication channels with the master-likelihood.
Definition: depresolver.hpp:68
IndexMap index
Indices associated with graph vertices (used by printers to identify functors)
std::vector< ObservableType > ObservablesType
Definition: yaml_parser.hpp:86
Printers::BasePrinter * boundPrinter
Printer object to which this dependency resolver is bound.
GAMBIT Core driver class.
Ini-file parser based on yaml-cpp.
std::map< VertexID, std::vector< VertexID > > SortedParentVertices
Saved calling order for functions required to compute single ObsLike entries.
Declaration and definition of printer base class.
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Information in parameter queue.
Definition: depresolver.hpp:94
Rule(std::string function, std::string module)
Definition: depresolver.hpp:83
const IniParser::IniFile * boundIniFile
ini file to which this dependency resolver is bound
std::string module
Definition: depresolver.hpp:90
Rule(IniParser::ObservableType t)
Definition: depresolver.hpp:84
int third
Main inifile class.
Definition: yaml_parser.hpp:89
Minimal info about outputVertices.
Definition: depresolver.hpp:73
const Models::ModelFunctorClaw * boundClaw
Model claw to which this dependency resolver is bound.
Simple container used for storing info about which types have been defined as equivalent for depencen...
DRes::VertexID second
std::vector< OutputVertexInfo > outputVertexInfos
Output Vertex Infos.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
const str activeFunctorGraphFile
Output filename for graph of active functors.
A small wrapper object for &#39;options&#39; nodes.
std::map< VertexID, std::set< VertexID > > loopManagerMap
Temporary map for loop manager -> list of nested functions.
std::map< std::string, std::vector< functor * > > outputMapType
Definition: depresolver.hpp:69
TYPE getObsLike(VertexID vertex)
Return the result of a functor.
adjacency_list< vecS, vecS, bidirectionalS, functor *, vecS > MasterGraphType
Typedefs for central boost graph.
Definition: depresolver.hpp:60