quantrs2_tytan/solution_debugger/
types.rs

1//! Core types for the solution debugger.
2
3use scirs2_core::ndarray::Array2;
4use serde::Serialize;
5use std::collections::HashMap;
6
7/// Problem information
8#[derive(Debug, Clone, Serialize)]
9pub struct ProblemInfo {
10    /// Problem name
11    pub name: String,
12    /// Problem type
13    pub problem_type: String,
14    /// Number of variables
15    pub num_variables: usize,
16    /// Variable mapping
17    pub var_map: HashMap<String, usize>,
18    /// Reverse variable mapping
19    pub reverse_var_map: HashMap<usize, String>,
20    /// QUBO matrix
21    pub qubo: Array2<f64>,
22    /// Constraints
23    pub constraints: Vec<ConstraintInfo>,
24    /// Known optimal solution (if available)
25    pub optimal_solution: Option<Solution>,
26    /// Additional metadata
27    pub metadata: HashMap<String, String>,
28}
29
30#[derive(Debug, Clone, serde::Serialize)]
31pub struct Solution {
32    /// Variable assignments
33    pub assignments: HashMap<String, bool>,
34    /// Solution energy
35    pub energy: f64,
36    /// Solution quality metrics
37    pub quality_metrics: HashMap<String, f64>,
38    /// Solution metadata
39    pub metadata: HashMap<String, String>,
40    /// Sampling statistics
41    pub sampling_stats: Option<SamplingStats>,
42}
43
44#[derive(Debug, Clone, Serialize)]
45pub struct SamplingStats {
46    /// Number of reads
47    pub num_reads: usize,
48    /// Annealing time
49    pub annealing_time: f64,
50    /// Chain break fraction
51    pub chain_break_fraction: f64,
52    /// Sampler used
53    pub sampler: String,
54}
55
56/// Constraint information
57#[derive(Debug, Clone, Serialize)]
58pub struct ConstraintInfo {
59    /// Constraint name
60    pub name: Option<String>,
61    /// Constraint type
62    pub constraint_type: ConstraintType,
63    /// Variables involved
64    pub variables: Vec<String>,
65    /// Constraint parameters
66    pub parameters: HashMap<String, f64>,
67    /// Penalty weight
68    pub penalty: f64,
69    /// Description
70    pub description: Option<String>,
71}
72
73#[derive(Debug, Clone, Serialize)]
74pub enum ConstraintType {
75    /// Equality constraint
76    Equality { target: f64 },
77    /// Inequality constraint
78    Inequality {
79        bound: f64,
80        direction: InequalityDirection,
81    },
82    /// All different constraint
83    AllDifferent,
84    /// Exactly one constraint
85    ExactlyOne,
86    /// At most one constraint
87    AtMostOne,
88    /// Custom constraint
89    Custom { evaluator: String },
90}
91
92#[derive(Debug, Clone, Serialize)]
93pub enum InequalityDirection {
94    LessEqual,
95    GreaterEqual,
96}