tnc/tensornetwork/partitioning/
partition_config.rs

1use std::{
2    ffi::{CStr, CString},
3    path::PathBuf,
4};
5
6use kahypar::{include_cstr, KaHyParContext};
7
8static MIN_CUT_CONFIG: &CStr = include_cstr!("cut_kKaHyPar_sea20.ini");
9static COMMUNITY_FINDING_CONFIG: &CStr = include_cstr!("km1_kKaHyPar_sea20.ini");
10
11/// Different strategies for partitioning a tensor network.
12pub enum PartitioningStrategy {
13    /// Uses the min cut heuristic.
14    MinCut,
15    /// Uses the community finding heuristic.
16    CommunityFinding,
17    /// A custom `KaHyPar` configuration loaded from an INI file.
18    Custom(PathBuf),
19}
20
21impl PartitioningStrategy {
22    pub(super) fn apply(self, context: &mut KaHyParContext) {
23        match self {
24            Self::MinCut => {
25                context.configure_from_str(MIN_CUT_CONFIG);
26            }
27            Self::CommunityFinding => {
28                context.configure_from_str(COMMUNITY_FINDING_CONFIG);
29            }
30            Self::Custom(path) => {
31                context
32                    .configure_from_file(CString::new(path.to_str().unwrap()).unwrap().as_c_str());
33            }
34        }
35    }
36}