@@ -249,7 +249,7 @@ struct DecomposedDemError {
249249 // / The probability of this error occurring.
250250 double probability;
251251 // / Effects of the error.
252- stim::FixedCapVector <UserEdge, 8 > components;
252+ std::vector <UserEdge> components;
253253
254254 bool operator ==(const DecomposedDemError& other) const ;
255255 bool operator !=(const DecomposedDemError& other) const ;
@@ -283,6 +283,7 @@ void iter_dem_instructions_include_correlations(
283283 component->node1 = SIZE_MAX ;
284284 component->node2 = SIZE_MAX ;
285285 size_t num_component_detectors = 0 ;
286+ bool instruction_contains_separator = false ;
286287 for (auto & target : instruction.target_data ) {
287288 // Decompose error
288289 if (target.is_relative_detector_id ()) {
@@ -309,30 +310,46 @@ void iter_dem_instructions_include_correlations(
309310 } else if (target.is_observable_id ()) {
310311 component->observable_indices .push_back (target.val ());
311312 } else if (target.is_separator ()) {
312- // If the previous error in the decomposition had 3 or more components, we ignore it.
313- if (component->node1 == SIZE_MAX ) {
313+ instruction_contains_separator = true ;
314+ // If the previous error in the decomposition had 3 or more detectors, we throw an exception.
315+ if (num_component_detectors > 2 ) {
314316 throw std::invalid_argument (
315317 " Encountered a decomposed error instruction with a hyperedge component (3 or more detectors). "
316318 " This is not supported." );
317- } else if (p > 0 ) {
319+ } else if (num_component_detectors == 0 ) {
320+ throw std::invalid_argument (
321+ " Encountered a decomposed error instruction with an undetectable component (0 detectors). "
322+ " This is not supported." );
323+ } else if (num_component_detectors > 0 ) {
324+ // If the previous error in the decomposition had 1 or 2 detectors, we handle it
318325 handle_dem_error (p, {component->node1 , component->node2 }, component->observable_indices );
326+ decomposed_err.components .push_back ({});
327+ component = &decomposed_err.components .back ();
328+ component->node1 = SIZE_MAX ;
329+ component->node2 = SIZE_MAX ;
330+ num_component_detectors = 0 ;
319331 }
320- decomposed_err.components .push_back ({});
321- component = &decomposed_err.components .back ();
322- component->node1 = SIZE_MAX ;
323- component->node2 = SIZE_MAX ;
324- num_component_detectors = 0 ;
325332 }
326333 }
327- // If the final error in the decomposition had 3 or more components, we ignore it.
328- if (component-> node1 == SIZE_MAX ) {
334+
335+ if (num_component_detectors > 2 ) {
329336 // Undecomposed hyperedges are not supported
330337 throw std::invalid_argument (
331338 " Encountered an undecomposed error instruction with 3 or mode detectors. "
332339 " This is not supported when using `enable_correlations=True`. "
333340 " Did you forget to set `decompose_errors=True` when "
334341 " converting the stim circuit to a detector error model?" );
335- } else if (p > 0 ) {
342+ } else if (num_component_detectors == 0 ) {
343+ if (instruction_contains_separator) {
344+ throw std::invalid_argument (
345+ " Encountered a decomposed error instruction with an undetectable component (0 detectors). "
346+ " This is not supported." );
347+ } else {
348+ // Ignore errors that are undetectable, provided they are not a component of a decomposed error
349+ return ;
350+ }
351+
352+ } else if (num_component_detectors > 0 ) {
336353 if (component->node2 == SIZE_MAX ) {
337354 handle_dem_error (p, {component->node1 }, component->observable_indices );
338355 } else {
0 commit comments