Add support for comparing DEMs up to instruction ordering#1042
Conversation
65e7973 to
f505004
Compare
|
Two major problems with this method as currently implemented.
and and a simple solution would be to first flatten the dem, but that would make the method take far too long when applied to circuits with high repetition counts. There are a few exceptions, but basically all methods in stim are efficient when applied to high-loop-count circuits. This method would also need to meet that bar. |
|
Yeah I guess this is a flat world theory :D |
1fe660f to
a4d2230
Compare
a4d2230 to
4a0ca5d
Compare
| // check reps | ||
| if (structural_op_a.repeat_block_rep_count() != structural_op_b.repeat_block_rep_count()) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
At this point, you might ask why I don't simply check op_a != op_b before handling the dedicated shift/repeat cases. For repeats, that would result in unexpected failures, i.e., where the the DEMs have the same repeat blocks but they are stored in different orders in the backing blocks arrays. That seems like an implementation detail that should not result in this member function reporting inequality.
|
Have another look at this PR when you get the chance. I updated the ordering-insensitive comparison to handle shifts/repeats efficiently by treating them as structural barriers (must match exactly) and comparing the instruction segments between barriers order-insensitively, so large repeats don’t need to be unrolled. I still think the most general isomorphic check would be a semantic flatten + canonicalise + sort + compare (where shifts/repeats only matter via their effects), but that’s expensive. DEM construction seems to be becoming an active area of research, including tools that try to automatically infer detector/logical observable definitions. Utilities like this are useful for validating those approaches against Stim as a golden reference, using an equality notion that’s less strict than == while still being equivalent from the perspective of decoders. Feel free to reject the PR if you feel these utilities should live elsewhere. I will anyway keep it on my fork. |
The current
==overload of theDetectorErrorModelonly returns true if the DEMs have the same instruction ordering. It is sometimes useful to be able to compare two DEMs for equality when this is not the case, so I implemented anis_equal_up_to_instruction_orderingmember function. I opted not to change the==operator because (a) checking for equality up to instruction ordering requires sorting so turns an O(n) op into an O(n log n) op; and (b) it's possible some of the backend simulation code depends on the ordering constraint.