23#ifndef VULPES_GEOMETRY_AGGLOMERATION_GNN_AGGLOMERATION_HPP_
24#define VULPES_GEOMETRY_AGGLOMERATION_GNN_AGGLOMERATION_HPP_
26#include <torch/script.h>
27#include <torch/torch.h>
36#include <vtkCellArray.h>
37#include <vtkCellData.h>
38#include <vtkIntArray.h>
41#include <vtkPolyData.h>
42#include <vtkSmartPointer.h>
43#include <vtkUnstructuredGrid.h>
44#include <vtkXMLPolyDataWriter.h>
45#include <vtkXMLUnstructuredGridWriter.h>
73 if constexpr (std::is_same_v<T, float>) {
74 return torch::kFloat32;
75 }
else if constexpr (std::is_same_v<T, double>) {
76 return torch::kFloat64;
77 }
else if constexpr (std::is_same_v<T, int32_t>) {
79 }
else if constexpr (std::is_same_v<T, int64_t>) {
83 std::is_same_v<T, void>,
84 "Unsupported type: must be float, double, int32_t, or int64_t");
106template <
typename MeshType>
121 using Module = torch::jit::script::Module;
164 const MeshType& mesh,
167 bool return_hierarchy =
true,
168 const std::string& segregated_tag =
"",
169 const IndVec& subset = {})
override;
180 const std::vector<bool>& )
override {
181 throw std::runtime_error(
182 "Method 'directKWay' does not exist for GNNAgglomeration");
Defines an abstract interface for mesh agglomeration strategies.
Definition abs_agg_model.hpp:71
double float_t
Definition abs_agg_model.hpp:73
datastructure::IndexTracker< index_t > IndexTrackerType
Definition abs_agg_model.hpp:78
datastructure::CrsMap< index_t, index_t > MapType
Definition abs_agg_model.hpp:76
std::variant< index_t, float_t > ParamType
Definition abs_agg_model.hpp:77
std::vector< index_t > IndVec
Definition abs_agg_model.hpp:75
int64_t index_t
Definition abs_agg_model.hpp:74
GNN-based agglomeration model (GraphSAGE via TorchScript).
Definition gnn_agglomeration.hpp:107
Cell< MeshType::self_dim, MeshFloatType, MeshIndexType > CellType
Definition gnn_agglomeration.hpp:116
torch::Tensor bisectGraph(const GNNGraph &graph)
Run the TorchScript SAGE model on a graph to obtain a 2-class split.
Definition gnn_agglomeration.cpp:174
typename MeshType::float_t MeshFloatType
Definition gnn_agglomeration.hpp:113
static constexpr auto s_torch_mesh_index_type
Definition gnn_agglomeration.hpp:126
typename AbstractAgglomerationModel< MeshType >::index_t ClassIndexType
Definition gnn_agglomeration.hpp:110
static constexpr auto s_torch_mesh_float_type
Definition gnn_agglomeration.hpp:124
ClassIndexType m_n_kmeans_calls
Definition gnn_agglomeration.hpp:211
typename AbstractAgglomerationModel< MeshType >::float_t ClassFloatType
Definition gnn_agglomeration.hpp:109
Module m_model
Definition gnn_agglomeration.hpp:215
torch::Tensor m_feature_tensor
Definition gnn_agglomeration.hpp:214
typename AbstractAgglomerationModel< MeshType >::MapType MapType
Definition gnn_agglomeration.hpp:111
GNNAgglomeration(const std::string &name, SAGEType SAGE_t)
Construct a GNN agglomerator.
Definition gnn_agglomeration.cpp:36
torch::jit::script::Module Module
Definition gnn_agglomeration.hpp:121
static constexpr auto s_torch_class_index_type
Definition gnn_agglomeration.hpp:128
typename AbstractAgglomerationModel< MeshType >::ParamType ParamType
Definition gnn_agglomeration.hpp:122
IndVec bisectSubGraph(const MeshType &mesh, const IndVec &subgraph) override
Backend implementation of a single bisection operation.
Definition gnn_agglomeration.cpp:138
void directKWay(const MeshType &, std::size_t, IndexTrackerType &, const std::vector< bool > &) override
Direct k-way partition is not supported by the GNN backend.
Definition gnn_agglomeration.hpp:176
Eigen::Matrix< MeshFloatType, -1, -1, Eigen::RowMajor > m_feature_mat
Definition gnn_agglomeration.hpp:217
SAGEType m_sage_t
Definition gnn_agglomeration.hpp:212
GNNGraph m_graph
Definition gnn_agglomeration.hpp:213
typename MeshType::index_t MeshIndexType
Definition gnn_agglomeration.hpp:114
typename AbstractAgglomerationModel< MeshType >::IndexTrackerType IndexTrackerType
Definition gnn_agglomeration.hpp:118
typename AbstractAgglomerationModel< MeshType >::IndVec IndVec
Definition gnn_agglomeration.hpp:117
std::vector< MeshType > agglomerate(const MeshType &mesh, MethodType method_type, ParamType params, bool return_hierarchy=true, const std::string &segregated_tag="", const IndVec &subset={}) override
Agglomerate a mesh using a selected high-level strategy.
Definition gnn_agglomeration.cpp:68
static constexpr ClassIndexType dim
Definition gnn_agglomeration.hpp:131
Graph wrapper with Torch tensors for features and edges.
Definition gnn_graph.hpp:46
constexpr torch::ScalarType toTorchType()
Map C++ mesh types (float, double, int32_t, int64_t) to the corresponding Torch scalar type.
Definition gnn_agglomeration.hpp:72
Definition abs_agg_model.cpp:40
SAGEType
Variants of pretrained GraphSAGE models supported by this backend.
Definition gnn_agglomeration.hpp:63
@ Base
Definition gnn_agglomeration.hpp:63
@ Heterogeneous
Definition gnn_agglomeration.hpp:63
MethodType
Definition abs_agg_model.hpp:41
std::conditional_t< Dim==2, Cell2D< FloatType, IndexType >, Cell3D< FloatType, IndexType > > Cell
Definition cell.hpp:267
Definition cell_manager.hpp:38