CYCLUS
Loading...
Searching...
No Matches
pyhooks.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_PYHOOKS_H_
2#define CYCLUS_SRC_PYHOOKS_H_
3
4#include <string>
5
6#include "any.hpp"
7
8namespace cyclus {
9class Agent;
10/// Because of NumPy #7595, we can only initialize & finalize the Python
11/// interpreter once. This variable keeps a count of how many times we have
12/// initialized so that we can know when to really stop the interpreter.
13/// When Python binding are not installed, this will always remain zero.
14extern int PY_INTERP_COUNT;
15
16/// Whether or not the Python interpreter has been initilized.
17extern bool PY_INTERP_INIT;
18
19/// Initialize Python functionality, this is a no-op if Python was not
20/// installed along with Cyclus. This may be called many times and safely
21/// initializes the Python interpreter only once.
22void PyStart(void);
23
24/// Closes the current Python session. This is a no-op if Python was
25/// not installed with Cyclus. This may safely be called many times.
26void PyStop(void);
27
28// Add some simple shims that attach C++ to Python C hooks
29void EventLoop(void);
30
31/// Finds a Python module and returns its filename.
32std::string PyFindModule(std::string);
33
34/// Finds a Python module and returns an agent pointer from it.
35Agent* MakePyAgent(std::string, std::string, void*);
36
37/// Initializes a Python agent fron another agent
38void InitFromPyAgent(Agent*, Agent*, void*);
39
40/// Removes all Python agents from the internal cache. There is usually
41/// no need for a user to call this.
42void ClearPyAgentRefs(void);
43
44/// Removes a single Python agent from the reference cache.
45void PyDelAgent(int);
46
47namespace toolkit {
48enum TimeSeriesType : int;
49/// Convert Python simulation string to JSON
50std::string PyToJson(std::string);
51
52/// Convert JSON string to Python simulation string
53std::string JsonToPy(std::string);
54
55/// Calls the Python listeners
56void PyCallListeners(std::string tsname, Agent* agent, void* cpp_ctx, int time, boost::spirit::hold_any value);
57
58} // ends namespace toolkit
59} // ends namespace cyclus
60#endif // ends CYCLUS_SRC_PYHOOKS_H_
TimeSeriesType
Time series types to be used in the RecordTimeSeries() functions.
Definition timeseries.h:24
void PyCallListeners(std::string tsname, Agent *agent, void *cpp_ctx, int time, boost::spirit::hold_any value)
Calls the Python listeners.
Definition pyhooks.cc:100
std::string PyToJson(std::string infile)
Convert Python simulation string to JSON.
Definition pyhooks.cc:88
std::string JsonToPy(std::string infile)
Convert JSON string to Python simulation string.
Definition pyhooks.cc:94
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
bool PY_INTERP_INIT
Whether or not the Python interpreter has been initilized.
Definition pyhooks.cc:69
void EventLoop(void)
Definition pyhooks.cc:75
void InitFromPyAgent(Agent *src, Agent *dst, void *ctx)
Initializes a Python agent fron another agent.
Definition pyhooks.cc:81
void ClearPyAgentRefs(void)
Removes all Python agents from the internal cache.
Definition pyhooks.cc:83
int PY_INTERP_COUNT
Because of NumPy #7595, we can only initialize & finalize the Python interpreter once.
Definition pyhooks.cc:68
void PyDelAgent(int i)
Removes a single Python agent from the reference cache.
Definition pyhooks.cc:85
std::string PyFindModule(std::string lib)
Finds a Python module and returns its filename.
Definition pyhooks.cc:77
void PyStop(void)
Closes the current Python session.
Definition pyhooks.cc:73
Agent * MakePyAgent(std::string lib, std::string agent, void *ctx)
Finds a Python module and returns an agent pointer from it.
Definition pyhooks.cc:79
void PyStart(void)
Initialize Python functionality, this is a no-op if Python was not installed along with Cyclus.
Definition pyhooks.cc:71
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters