@@ -24,7 +24,7 @@ pub enum SolverType {
2424}
2525
2626/// Configuration for Fusion Blossom decoder
27- #[ derive( Debug , Clone , PartialEq , Eq ) ]
27+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
2828pub struct FusionBlossomConfig {
2929 /// Number of nodes in the graph
3030 pub num_nodes : Option < usize > ,
@@ -48,7 +48,7 @@ impl Default for FusionBlossomConfig {
4848}
4949
5050/// Options for decoding
51- #[ derive( Debug , Clone , Default ) ]
51+ #[ derive( Debug , Clone , Copy , Default ) ]
5252pub struct DecodingOptions {
5353 /// Whether to include perfect matching details in the result
5454 pub include_perfect_matching : bool ,
@@ -122,7 +122,7 @@ impl fmt::Display for DecodingResult {
122122}
123123
124124/// Standard QEC code types
125- #[ derive( Debug , Clone ) ]
125+ #[ derive( Debug , Clone , Copy ) ]
126126pub enum StandardCode {
127127 /// Code capacity planar code
128128 CodeCapacityPlanar {
@@ -202,6 +202,10 @@ pub struct FusionBlossomDecoder {
202202
203203impl FusionBlossomDecoder {
204204 /// Create a new decoder with the given configuration
205+ ///
206+ /// # Errors
207+ ///
208+ /// Returns [`FusionBlossomError::Configuration`] if `num_nodes` is not specified in the config.
205209 pub fn new ( config : FusionBlossomConfig ) -> Result < Self > {
206210 let num_nodes = config. num_nodes . ok_or_else ( || {
207211 FusionBlossomError :: Configuration ( "num_nodes must be specified" . to_string ( ) )
@@ -220,6 +224,11 @@ impl FusionBlossomDecoder {
220224 }
221225
222226 /// Create decoder from a standard QEC code
227+ ///
228+ /// # Errors
229+ ///
230+ /// This function currently does not return errors, but returns `Result` for API
231+ /// consistency and future extensibility.
223232 pub fn from_standard_code ( code : StandardCode , config : FusionBlossomConfig ) -> Result < Self > {
224233 let example_code: Box < dyn ExampleCode > = match code {
225234 StandardCode :: CodeCapacityPlanar {
@@ -318,6 +327,12 @@ impl FusionBlossomDecoder {
318327 }
319328
320329 /// Add an edge to the graph
330+ ///
331+ /// # Errors
332+ ///
333+ /// Returns [`FusionBlossomError::InvalidGraph`] if:
334+ /// - Either node index is out of bounds
335+ /// - The weight is negative
321336 pub fn add_edge (
322337 & mut self ,
323338 node1 : usize ,
@@ -358,6 +373,18 @@ impl FusionBlossomDecoder {
358373 }
359374
360375 /// Add a boundary edge (connects a node to the boundary)
376+ ///
377+ /// # Errors
378+ ///
379+ /// Returns [`FusionBlossomError::InvalidGraph`] if:
380+ /// - The node index is out of bounds
381+ /// - The weight is negative
382+ ///
383+ /// # Panics
384+ ///
385+ /// This function will not panic. The internal `unwrap()` is safe because
386+ /// `boundary_node` is always set before use (either already `Some` or set
387+ /// in the same code path).
361388 pub fn add_boundary_edge (
362389 & mut self ,
363390 node : usize ,
@@ -404,6 +431,13 @@ impl FusionBlossomDecoder {
404431 }
405432
406433 /// Create decoder from a check matrix
434+ ///
435+ /// # Errors
436+ ///
437+ /// Returns an error if:
438+ /// - [`FusionBlossomError::Configuration`] if `num_nodes` cannot be set
439+ /// - [`FusionBlossomError::InvalidCheckMatrix`] if a column has more than 2 non-zero entries
440+ /// - [`FusionBlossomError::InvalidGraph`] if edge addition fails
407441 pub fn from_check_matrix (
408442 check_matrix : & Array2 < u8 > ,
409443 weights : Option < & [ f64 ] > ,
@@ -498,6 +532,11 @@ impl FusionBlossomDecoder {
498532 }
499533
500534 /// Decode a syndrome with advanced options and decoding options
535+ ///
536+ /// # Errors
537+ ///
538+ /// This function currently does not return errors, but returns `Result` for API
539+ /// consistency and future extensibility.
501540 pub fn decode_with_options (
502541 & mut self ,
503542 syndrome_data : SyndromeData ,
@@ -601,11 +640,20 @@ impl FusionBlossomDecoder {
601640 }
602641
603642 /// Decode a syndrome with advanced options (backwards compatibility)
643+ ///
644+ /// # Errors
645+ ///
646+ /// Returns the same errors as [`Self::decode_with_options`].
604647 pub fn decode_advanced ( & mut self , syndrome_data : SyndromeData ) -> Result < DecodingResult > {
605648 self . decode_with_options ( syndrome_data, DecodingOptions :: default ( ) )
606649 }
607650
608651 /// Decode a syndrome (simple interface)
652+ ///
653+ /// # Errors
654+ ///
655+ /// Returns [`FusionBlossomError::InvalidSyndrome`] if the syndrome length doesn't
656+ /// match the number of nodes in the decoder.
609657 pub fn decode ( & mut self , syndrome : & ArrayView1 < u8 > ) -> Result < DecodingResult > {
610658 if syndrome. len ( ) != self . num_nodes {
611659 return Err ( FusionBlossomError :: InvalidSyndrome ( format ! (
0 commit comments