MUQ  0.4.3
WorkPieceWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
9 
10 #include <pybind11/pybind11.h>
11 #include <pybind11/stl.h>
12 #include <pybind11/eigen.h>
13 
14 #include <string>
15 
16 #include <boost/any.hpp>
17 #include <functional>
18 #include <vector>
19 
21 
22 using namespace muq::Modeling::PythonBindings;
23 namespace py = pybind11;
24 
25 
27 {
28  // Define some functions from the WorkPiece base class
29  py::class_<WorkPiece, std::shared_ptr<WorkPiece>> wp(m, "WorkPiece");
30  wp
31  .def("Evaluate", (std::vector<boost::any> const& (WorkPiece::*)(std::vector<boost::any> const&)) &WorkPiece::Evaluate)
32  .def("Evaluate", (std::vector<boost::any> const& (WorkPiece::*)()) &WorkPiece::Evaluate);
33 
34  // The Identity WorkPiece
35  py::class_<IdentityPiece, WorkPiece, std::shared_ptr<IdentityPiece>> ip(m, "IdentityPiece");
36  ip
37  .def(py::init())
38  .def(py::init<int const>())
39  .def(py::init<std::vector<std::string> const&>())
40  .def(py::init<std::map<unsigned int, std::string> const&>())
41  .def(py::init<std::map<unsigned int, std::string> const&, unsigned int const>());
42 
43  // The Constant WorkPiece
44  py::class_<ConstantPiece, WorkPiece, std::shared_ptr<ConstantPiece>> cp(m, "ConstantPiece");
45  cp
46  .def(py::init<std::vector<boost::any> const&>())
47  .def(py::init<boost::any const&>());
48 
49  // The WorkGraphPiece
50  py::class_<WorkGraphPiece, WorkPiece, std::shared_ptr<WorkGraphPiece>> wgp(m, "WorkGraphPiece");
51 
52  // The WorkGraph
53  py::class_<WorkGraph> wg(m, "WorkGraph");
54  wg
55  .def(py::init())
56  .def("Clone", &WorkGraph::Clone)
57  .def("NumNodes", &WorkGraph::NumNodes)
58  .def("NumEdges", &WorkGraph::NumEdges)
59  .def("AddNode", &WorkGraph::AddNode, py::keep_alive<1, 2>())
60  .def("AddEdge", &WorkGraph::AddEdge)
61  .def("GetPiece", (std::shared_ptr<WorkPiece> (WorkGraph::*)(std::string const&)) &WorkGraph::GetPiece)
62  .def("GetName", (std::string (WorkGraph::*)(std::shared_ptr<WorkPiece> const&) const) &WorkGraph::GetName)
63  .def("HasNode", (bool (WorkGraph::*)(std::string const&) const) &WorkGraph::HasNode)
64  .def("Visualize", &WorkGraph::Visualize)
65  .def("DependentCut", &WorkGraph::DependentCut)
66  .def("CreateWorkPiece", &WorkGraph::CreateWorkPiece)
67  .def("CreateModPiece", &WorkGraph::CreateModPiece, py::arg("node"),py::arg("inNames") = std::vector<std::string>())
68  .def("Constant", (bool (WorkGraph::*)(std::string const&) const) &WorkGraph::Constant)
69  .def("GetConstantOutputs", (std::vector<boost::any> const& (WorkGraph::*)(std::string const&) const) &WorkGraph::GetConstantOutputs);
70 
71  //
72  // py::class_<FenicsPiece, std::shared_ptr<FenicsPiece>> fp(m, "FenicsPiece", wp);
73  // fp
74  // .def(py::init<pybind11::object const&, pybind11::object const&, std::vector<pybind11::object> const&>() )
75  // .def("EvaluateVec", &FenicsPiece::EvaluateVec);
76  //
77  // return m.ptr();
78 }
void AddNode(std::shared_ptr< WorkPiece > input, std::string const &name)
Add a new node to the graph.
Definition: WorkGraph.cpp:195
void AddEdge(std::string const &nameFrom, unsigned int const outputDim, std::string const &nameTo, unsigned int const inputDim)
Add a new edge to the graph.
Definition: WorkGraph.cpp:206
unsigned int NumEdges() const
Get the number of edgess in the graph.
Definition: WorkGraph.cpp:92
std::shared_ptr< WorkGraph > DependentCut(std::string const &nameOut) const
Create a new graph cutting any of the nodes that do not affect the output node.
Definition: WorkGraph.cpp:477
virtual std::shared_ptr< WorkGraph > Clone() const
Definition: WorkGraph.cpp:54
std::shared_ptr< ModGraphPiece > CreateModPiece(std::string const &node, std::vector< std::string > const &inNames=std::vector< std::string >()) const
Create a muq::Modeling::ModPiece whose output matches a given node.
Definition: WorkGraph.cpp:591
std::shared_ptr< WorkPiece > GetPiece(std::string const &name)
Definition: WorkGraph.cpp:720
std::string GetName(std::shared_ptr< WorkPiece > piece) const
Definition: WorkGraph.cpp:749
void Visualize(std::string const &filename) const
Visualize the graph.
Definition: WorkGraph.cpp:857
std::shared_ptr< WorkGraphPiece > CreateWorkPiece(std::string const &node) const
Create a muq::Modeling::WorkPiece whose output matches a given node.
Definition: WorkGraph.cpp:523
std::vector< boost::any > const & GetConstantOutputs(std::string const &node) const
Get the output values for a constant node.
Definition: WorkGraph.cpp:936
unsigned int NumNodes() const
Get the number of nodes in the graph.
Definition: WorkGraph.cpp:86
bool Constant(std::string const &node) const
Check to see if a node is constant?
Definition: WorkGraph.cpp:1002
bool HasNode(std::string const &name) const
Is the given node in the graph?
Definition: WorkGraph.cpp:177
std::vector< boost::any > const & Evaluate()
Evaluate this muq::Modeling::WorkPiece in the case that there are no inputs.
Definition: WorkPiece.cpp:222
void WorkPieceWrapper(pybind11::module &m)