List of all members | Public Types | Public Member Functions
casadi::GraphBuilder Class Reference

A mutable, format-neutral interface to a computational-graph model. More...

#include <graph_builder.hpp>

Detailed Description

Two-stage workflow: explore and configure a model (introspection, dynamic-dimension binding) with GraphBuilder, then freeze it into an immutable, evaluable Function.

GraphBuilder b("model.onnx");
b.bind_dim("batch", 4);
Function f = b.create("net");
Date
2026

Extra doc: https://github.com/casadi/casadi/wiki/L_2jd

Definition at line 49 of file graph_builder.hpp.

Inheritance diagram for casadi::GraphBuilder:
Inheritance graph
[legend]

Public Types

using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

std::string type_name () const
 Readable name of the class. More...
 
 GraphBuilder ()
 Default constructor. More...
 
 GraphBuilder (const std::string &model_path, const Dict &opts=Dict())
 Construct from a model file (import lifecycle; format from the file suffix) More...
 
 GraphBuilder (const Function &f, const Dict &opts=Dict())
 Construct from a CasADi Function (export lifecycle) More...
 
const std::string & name () const
 Name of the model. More...
 
Function create (const std::string &name, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict()) const
 Freeze into an evaluable Function. More...
 
Function create (const std::string &name, const Dict &opts=Dict()) const
 Freeze into an evaluable Function, exposing all model inputs and outputs. More...
 
Function create () const
 Freeze into an evaluable Function, default naming. More...
 
void export_onnx (const std::string &filename, const Dict &opts=Dict())
 Export to an ONNX model file. More...
 
std::string class_name () const
 Get class name. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
Model introspection
casadi_int n_in () const
 Declared shape of a tensor (input or output) by name; -1 for dynamic dimensions. More...
 
casadi_int n_out () const
 Declared shape of a tensor (input or output) by name; -1 for dynamic dimensions. More...
 
std::vector< std::string > name_in () const
 Declared shape of a tensor (input or output) by name; -1 for dynamic dimensions. More...
 
std::vector< std::string > name_out () const
 Declared shape of a tensor (input or output) by name; -1 for dynamic dimensions. More...
 
std::vector< casadi_int > dimension (const std::string &name) const
 Declared shape of a tensor (input or output) by name; -1 for dynamic dimensions. More...
 
std::string dtype (const std::string &name) const
 Element type name of a tensor (input or output) by name (FLOAT, INT64, ...) More...
 
std::vector< std::string > dimension_param (const std::string &name) const
 Per-axis symbolic dimension name of a tensor by name ("" for static axes) More...
 
std::vector< std::string > dynamic_params () const
 Names of the symbolic/dynamic dimensions in the model. More...
 
Configuration
void bind_dim (const std::string &param, casadi_int value)
 Bind a symbolic/dynamic dimension to a concrete size. More...
 
void bind_shape (const std::string &input_name, const std::vector< casadi_int > &shape)
 Pin the full shape of an input. More...
 
void set (const std::string &input_name, const std::vector< double > &value)
 Bake a fixed value into an input; it is fed at create() and not exposed as a Function input. More...
 
void set (const std::string &input_name, double value)
 Bake a scalar value into an input. More...
 

Member Typedef Documentation

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

using casadi::SharedObject::internal_base_type = SharedObjectInternal
inherited

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ GraphBuilder() [1/3]

casadi::GraphBuilder::GraphBuilder ( )

◆ GraphBuilder() [2/3]

casadi::GraphBuilder::GraphBuilder ( const std::string &  model_path,
const Dict opts = Dict() 
)
explicit

◆ GraphBuilder() [3/3]

casadi::GraphBuilder::GraphBuilder ( const Function f,
const Dict opts = Dict() 
)
explicit

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__hash__
inherited

If the Object does not point to any node, "0" is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_av

Definition at line 123 of file generic_shared_impl.hpp.

◆ bind_dim()

void casadi::GraphBuilder::bind_dim ( const std::string &  param,
casadi_int  value 
)

◆ bind_shape()

void casadi::GraphBuilder::bind_shape ( const std::string &  input_name,
const std::vector< casadi_int > &  shape 
)

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ create() [1/3]

Function casadi::GraphBuilder::create ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_2jg

Definition at line 127 of file graph_builder.hpp.

◆ create() [2/3]

Function casadi::GraphBuilder::create ( const std::string &  name,
const Dict opts = Dict() 
) const
Parameters
nameName assigned to the resulting Function
optsSee the full create() overload

Extra doc: https://github.com/casadi/casadi/wiki/L_2jf

◆ create() [3/3]

Function casadi::GraphBuilder::create ( const std::string &  name,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const Dict opts = Dict() 
) const
Parameters
nameName assigned to the resulting Function
name_inNames of the inputs to expose (empty = all model inputs)
name_outNames of the outputs to expose (empty = all model outputs)
opts"symbolic" (bool, default false) and "backend" (numeric backend, default "ort"); any remaining options pass through to the backend.

Extra doc: https://github.com/casadi/casadi/wiki/L_2je

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

◆ dimension()

std::vector<casadi_int> casadi::GraphBuilder::dimension ( const std::string &  name) const

◆ dimension_param()

std::vector<std::string> casadi::GraphBuilder::dimension_param ( const std::string &  name) const

◆ disp()

void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited

◆ dtype()

std::string casadi::GraphBuilder::dtype ( const std::string &  name) const

◆ dynamic_params()

std::vector<std::string> casadi::GraphBuilder::dynamic_params ( ) const

◆ export_onnx()

void casadi::GraphBuilder::export_onnx ( const std::string &  filename,
const Dict opts = Dict() 
)

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

◆ is_null()

bool casadi::GenericShared< SharedObject , SharedObjectInternal >::is_null
inherited

Definition at line 116 of file generic_shared_impl.hpp.

◆ n_in()

casadi_int casadi::GraphBuilder::n_in ( ) const

◆ n_out()

casadi_int casadi::GraphBuilder::n_out ( ) const

◆ name()

const std::string& casadi::GraphBuilder::name ( ) const

◆ name_in()

std::vector<std::string> casadi::GraphBuilder::name_in ( ) const

◆ name_out()

std::vector<std::string> casadi::GraphBuilder::name_out ( ) const

◆ set() [1/2]

void casadi::GraphBuilder::set ( const std::string &  input_name,
const std::vector< double > &  value 
)

◆ set() [2/2]

void casadi::GraphBuilder::set ( const std::string &  input_name,
double  value 
)

◆ type_name()

std::string casadi::GraphBuilder::type_name ( ) const
inline

Definition at line 54 of file graph_builder.hpp.


The documentation for this class was generated from the following file: