SST  10.0.0
StructuralSimulationToolkit
pymodel.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2020 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2020, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 
15 #ifndef SST_CORE_MODEL_PYTHON
16 #define SST_CORE_MODEL_PYTHON
17 
18 // This only works if we have Python defined from configure, otherwise this is
19 // a compile time error.
20 #ifdef SST_CONFIG_HAVE_PYTHON
21 
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include "sst/core/model/sstmodel.h"
27 #include "sst/core/config.h"
28 #include "sst/core/rankInfo.h"
29 #include "sst/core/output.h"
30 #include "sst/core/configGraph.h"
31 
32 using namespace SST;
33 
34 namespace SST {
35 namespace Core {
36 
37 class SSTPythonModelDefinition : public SSTModelDescription {
38 
39 public:
40  SSTPythonModelDefinition(const std::string& script_file, int verbosity, Config* config, int argc, char **argv);
41  SSTPythonModelDefinition(const std::string& script_file, int verbosity, Config* config);
42  virtual ~SSTPythonModelDefinition();
43 
44  ConfigGraph* createConfigGraph() override;
45 
46 protected:
47  void initModel(const std::string& script_file, int verbosity, Config* config, int argc, char** argv);
48  std::string scriptName;
49  Output* output;
50  Config* config;
51  ConfigGraph *graph;
52  char *namePrefix;
53  size_t namePrefixLen;
54  std::vector<size_t> nameStack;
55  std::map<std::string, ComponentId_t> compNameMap;
56  ComponentId_t nextComponentId;
57 
58 
59 public: /* Public, but private. Called only from Python functions */
60  Config* getConfig(void) const { return config; }
61 
62  ConfigGraph* getGraph(void) const { return graph; }
63 
64  Output* getOutput() const { return output; }
65 
66  ComponentId_t getNextComponentId() { return nextComponentId++; }
67 
68  ComponentId_t addComponent(const char *name, const char *type) {
69  ComponentId_t id = getNextComponentId();
70  graph->addComponent(id, name, type);
71  compNameMap[std::string(name)] = id;
72  return id;
73  }
74 
75  ComponentId_t findComponentByName(const char *name) const {
76  std::string origname(name);
77  auto index = origname.find(":");
78  std::string compname = origname.substr(0,index);
79  auto itr = compNameMap.find(compname);
80 
81  // Check to see if component was found
82  if ( itr == compNameMap.end() ) return UNSET_COMPONENT_ID;
83 
84  // If this was just a component name
85  if ( index == std::string::npos ) return itr->second;
86 
87  // See if this is a valid subcomponent name
88  ConfigComponent* cc = graph->findComponent(itr->second);
89  cc = cc->findSubComponentByName(origname.substr(index+1,std::string::npos));
90  if ( cc ) return cc->id;
91  return UNSET_COMPONENT_ID;
92  }
93 
94  void addLink(ComponentId_t id, const char *link_name, const char *port, const char *latency, bool no_cut) const {graph->addLink(id, link_name, port, latency, no_cut); }
95  void setLinkNoCut(const char *link_name) const {graph->setLinkNoCut(link_name); }
96 
97  void pushNamePrefix(const char *name);
98  void popNamePrefix(void);
99  char* addNamePrefix(const char *name) const;
100 
101  void setStatisticOutput(const char* Name) { graph->setStatisticOutput(Name); }
102  void addStatisticOutputParameter(const std::string& param, const std::string& value) { graph->addStatisticOutputParameter(param, value); }
103  void setStatisticLoadLevel(uint8_t loadLevel) { graph->setStatisticLoadLevel(loadLevel); }
104 
105  void enableStatisticForComponentName(const std::string& compname, const std::string& statname, bool apply_to_children = false) const {
106  graph->enableStatisticForComponentName(compname,statname,apply_to_children);
107  }
108 
109  void enableStatisticForComponentType(const std::string& comptype, const std::string& statname, bool apply_to_children = false) const {
110  graph->enableStatisticForComponentType(comptype, statname, apply_to_children);
111  }
112 
113  void addStatisticParameterForComponentName(const std::string& compname, const std::string& statname, const std::string& param, const std::string& value, bool apply_to_children = false) {
114  graph->addStatisticParameterForComponentName(compname,statname,param,value,apply_to_children);
115  }
116 
117  void addStatisticParameterForComponentType(const std::string& comptype, const std::string& statname, const std::string& param, const std::string& value, bool apply_to_children = false) {
118  graph->addStatisticParameterForComponentType(comptype, statname, param, value, apply_to_children);
119  }
120 };
121 
122 std::map<std::string,std::string> generateStatisticParameters(PyObject* statParamDict);
123 
124 }
125 }
126 
127 #endif
128 
129 #endif
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Class to contain SST Simulation Configuration variables.
Definition: config.h:31
Represents the configuration of a generic component.
Definition: configGraph.h:193
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:316
ComponentId_t id
Definition: configGraph.h:195
Base class for Model Generation.
Definition: sstmodel.h:22