List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
casadi::GraphModel Class Reference

Format-agnostic handle to a parsed computational-graph model. More...

#include <graph_model_impl.hpp>

Detailed Description

Loaded by format name as a plugin (e.g. "onnx"); the concrete backend is the only place a heavy dependency (protobuf) is linked. The Fmu analogue for GraphBuilder. Internal: owned by GraphBuilderInternal, not exposed to the scripting layer.

Date
2026

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


List of available options
IdTypeDescriptionUsed in
verboseOT_BOOLVerbose evaluation – for debuggingcasadi::GraphModel

Definition at line 47 of file graph_model_impl.hpp.

Inheritance diagram for casadi::GraphModel:
Inheritance graph
[legend]
Collaboration diagram for casadi::GraphModel:
Collaboration 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...
 
 GraphModel ()
 Default constructor (null handle) More...
 
 GraphModel (const std::string &format, const std::vector< uint8_t > &model_data=std::vector< uint8_t >(), const Dict &opts=Dict())
 Load a backend for a format, optionally with parsed model bytes. More...
 
std::string format () const
 Format name (plugin name) More...
 
void fill_metadata (GraphBuilderInternal &gb) const
 Populate a builder's Node metadata from the parsed model. More...
 
Function import_symbolic (const GraphBuilderInternal &gb, const std::string &name) const
 Symbolic import: rebuild the graph as a CasADi Function. More...
 
std::vector< uint8_t > export_symbolic (const Function &f, const Dict &opts=Dict())
 Symbolic export: serialize a CasADi Function to model bytes. More...
 
const std::vector< uint8_t > & model_data () const
 Raw model bytes. 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...
 
void print_ptr (std::ostream &stream=casadi::uout()) const
 
void own (SharedObjectInternal *node)
 
void assign (SharedObjectInternal *node)
 Assign the node to a node class pointer without reference counting. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. 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...
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
GraphModelInternaloperator-> ()
 
const GraphModelInternaloperator-> () const
 
GraphModelInternalget () const
 

Static Public Member Functions

static bool has_plugin (const std::string &name)
 Check if a format plugin is available. More...
 
static void load_plugin (const std::string &name)
 Explicitly load a format plugin. More...
 
static std::string doc (const std::string &name)
 Get format-specific documentation. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Member Typedef Documentation

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ GraphModel() [1/2]

casadi::GraphModel::GraphModel ( )

Definition at line 32 of file graph_model.cpp.

32  {
33  }

◆ GraphModel() [2/2]

casadi::GraphModel::GraphModel ( const std::string &  format,
const std::vector< uint8_t > &  model_data = std::vector<uint8_t>(),
const Dict opts = Dict() 
)
explicit

Definition at line 35 of file graph_model.cpp.

36  {
38  (*this)->construct(opts);
39  }
const std::vector< uint8_t > & model_data() const
Raw model bytes.
Definition: graph_model.cpp:65
std::string format() const
Format name (plugin name)
Definition: graph_model.cpp:51
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.

References format(), casadi::PluginInterface< GraphModelInternal >::getPlugin(), model_data(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

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.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ assign()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

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

Definition at line 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ class_name()

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

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_down
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

46  {
47 #ifdef WITH_EXTRA_CHECKS
48  casadi_assert_dev(Function::call_depth_==0);
49 #endif // WITH_EXTRA_CHECKS
50  if (!node) return;
51 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 132 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ debug_repr()

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

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
std::string debug_repr(const Internal *) const

◆ disp()

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

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ doc()

std::string casadi::GraphModel::doc ( const std::string &  name)
static

Definition at line 73 of file graph_model.cpp.

73  {
74  return GraphModelInternal::getPlugin(name).doc;
75  }

References casadi::PluginInterface< GraphModelInternal >::getPlugin().

Referenced by casadi::doc_graphmodel().

◆ export_symbolic()

std::vector< uint8_t > casadi::GraphModel::export_symbolic ( const Function f,
const Dict opts = Dict() 
)

Definition at line 62 of file graph_model.cpp.

62  {
63  return (*this)->export_symbolic(f, opts);
64  }

Referenced by casadi::GraphBuilderInternal::export_onnx().

◆ fill_metadata()

void casadi::GraphModel::fill_metadata ( GraphBuilderInternal gb) const

Definition at line 53 of file graph_model.cpp.

53  {
54  (*this)->fill_metadata(gb);
55  }

Referenced by casadi::GraphBuilderInternal::GraphBuilderInternal().

◆ format()

std::string casadi::GraphModel::format ( ) const

Definition at line 51 of file graph_model.cpp.

51 { return (*this)->plugin_name(); }

Referenced by GraphModel().

◆ get()

GraphModelInternal * casadi::GraphModel::get ( ) const

Access functions of the node

Definition at line 47 of file graph_model.cpp.

47  {
48  return static_cast<GraphModelInternal*>(SharedObject::get());
49  }
SharedObjectInternal * get() const
Get a const pointer to the node.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

Referenced by import_symbolic().

◆ get_str()

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

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ getCount()

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

Definition at line 102 of file generic_shared_impl.hpp.

138  {
139  return (*this)->getCount();
140  }

◆ has_plugin()

bool casadi::GraphModel::has_plugin ( const std::string &  name)
static

Definition at line 67 of file graph_model.cpp.

67  {
68  return GraphModelInternal::has_plugin(name);
69  }
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.

References casadi::PluginInterface< GraphModelInternal >::has_plugin().

Referenced by casadi::has_graphmodel().

◆ import_symbolic()

Function casadi::GraphModel::import_symbolic ( const GraphBuilderInternal gb,
const std::string &  name 
) const

Definition at line 56 of file graph_model.cpp.

57  {
58  // Shallow const: the backend engine mutates internally, but importing does not
59  // change the model handle's logical state.
60  return get()->import_symbolic(gb, name);
61  }
virtual Function import_symbolic(const GraphBuilderInternal &gb, const std::string &name)=0
Rebuild the graph as a CasADi Function (symbolic import; mutates the backend's engine)
GraphModelInternal * get() const
Definition: graph_model.cpp:47

References get(), and casadi::GraphModelInternal::import_symbolic().

Referenced by casadi::GraphBuilderInternal::create_function().

◆ is_null()

Definition at line 116 of file generic_shared_impl.hpp.

120  {
121  return node==nullptr;
122  }

◆ load_plugin()

void casadi::GraphModel::load_plugin ( const std::string &  name)
static

Definition at line 70 of file graph_model.cpp.

70  {
72  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

References casadi::PluginInterface< GraphModelInternal >::load_plugin().

Referenced by casadi::load_graphmodel().

◆ model_data()

const std::vector< uint8_t > & casadi::GraphModel::model_data ( ) const

Definition at line 65 of file graph_model.cpp.

65 { return (*this)->model_data(); }

Referenced by GraphModel().

◆ operator->() [1/2]

GraphModelInternal * casadi::GraphModel::operator-> ( )

Access functions of the node

Definition at line 41 of file graph_model.cpp.

41  {
42  return static_cast<GraphModelInternal*>(SharedObject::operator->());
43  }
SharedObjectInternal * operator->() const
Access a member function or object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ operator->() [2/2]

const GraphModelInternal * casadi::GraphModel::operator-> ( ) const

Access functions of the node

Definition at line 44 of file graph_model.cpp.

44  {
45  return static_cast<const GraphModelInternal*>(SharedObject::operator->());
46  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ own()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 89 of file generic_shared_impl.hpp.

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ swap()

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ type_name()

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

Definition at line 50 of file graph_model_impl.hpp.

50 { return "GraphModel"; }

◆ weak()

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

Definition at line 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

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