18#include <unordered_map>
20#include "dlinear/libs/libgmp.h"
21#include "dlinear/libs/libonnx.h"
22#include "dlinear/parser/Driver.h"
23#include "dlinear/parser/onnx/NodeOpType.h"
24#include "dlinear/parser/onnx/Tensor.h"
25#include "dlinear/symbolic/literal.h"
26#include "dlinear/symbolic/symbolic.h"
27#include "dlinear/util/concepts.h"
46 bool ParseFile(
const std::string& filename)
override;
53 [[nodiscard]] const ::onnx::ModelProto&
model()
const {
return model_; }
55 [[nodiscard]] const ::onnx::GraphProto&
graph()
const {
return model_.graph(); }
58 static const std::map<std::string, std::function<void(
OnnxDriver&, const ::onnx::NodeProto&)>>
82 template <IsAnyOf<
bool,
float, std::
int64_t, std::
string, std::vector<
float>, std::vector<std::
int64_t>,
83 std::vector<std::
string>, const ::onnx::TensorProto*>
85 T
GetAttribute(const ::onnx::NodeProto& node,
const std::string& name,
86 const std::optional<T>& default_value = {})
const;
88 static void EnsureInput(const ::onnx::NodeProto& node,
int lb,
int ub);
89 static void EnsureInput(const ::onnx::NodeProto& node,
int exact);
111 bool AddNode(const ::onnx::NodeProto& node);
117 void AddValueInfo(const ::onnx::ValueInfoProto& value_info,
bool is_input =
false);
123 void AddValueInfoTensor(const ::onnx::ValueInfoProto& value_info,
bool is_input =
false);
140 template <NodeOpType T>
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities.
The Driver is the base class for all the parsers.
const Context & context() const
Get read-only access to the enabled of the Driver.
Represents a symbolic form of an expression.
Represents a symbolic variable.
The OnnxDriver class reads the onnx file.
const ::onnx::GraphProto & graph() const
Get read-only access to the graph of the Driver.
void AddNodes()
Go through all the nodes in the graph and construct the final assertions.
static const std::map< std::string, std::function< void(OnnxDriver &, const ::onnx::NodeProto &)> > node_handlers
Map between node op_type and the corresponding handler..
bool ParseFile(const std::string &filename) override
Invoke the scanner and parser on a file.
T GetAttribute(const ::onnx::NodeProto &node, const std::string &name, const std::optional< T > &default_value={}) const
Get the attribute name from the node.
const Variable & ToEqualVar(const Expression &expression)
Associate to a linear expression a fresh variable.
const std::unordered_map< std::string, Tensor > & variables() const
Get read-only access to the variables of the Driver.
bool AddNode(const ::onnx::NodeProto &node)
Go through a specific node and add the corresponding assertions.
std::unordered_map< Expression, Variable > equal_vars_
Variables created to summarize linear constraints.
const std::unordered_map< std::string, Tensor > & available_inputs() const
Get read-only access to the available_inputs of the Driver.
void AddNode(const ::onnx::NodeProto &node)
Add a node to the context.
void AddValueInfo(const ::onnx::ValueInfoProto &value_info, bool is_input=false)
Add the input and output to the Context.
bool ParseStreamCore(std::istream &in) override
Parse the stream.
void AddFormula(const std::string &output)
Add the formulas to the Context.
std::unordered_map< std::string, Tensor > available_inputs_
Available inputs in the model.
::onnx::ModelProto model_
The onnx model obtained from the file.
OnnxDriver(Context &context)
Construct a new parser driver context.
const ::onnx::ModelProto & model() const
Get read-only access to the model of the Driver.
void AddInitializer(const ::onnx::TensorProto &tensor)
Add an initializer to the available_inputs_.
std::unordered_map< std::string, Tensor > variables_
Variables in the model.
void ParseGraph()
Parse the model_ 's graph.
void AddValueInfoTensor(const ::onnx::ValueInfoProto &value_info, bool is_input=false)
Add the input and output to the Context.
Namespace for the ONNX parser of the dlinear library.