Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Order of tags: should TaggedOperation(op, "tag1", "tag2")==TaggedOperation(op, "tag2", "tag1")?

Open babacry opened this issue 8 months ago • 2 comments

Now

TaggedOperation(op, "tag1", "tag2")!=TaggedOperation(op, "tag2", "tag1") and TaggedOperation(op, "tag1", "tag2")==TaggedOperation(op, "tag1", "tag2")

wonder why does the order of tags matter? if not, should serialization/deserialization take tag sorting into consideration?

babacry avatar Apr 19 '25 01:04 babacry

Discussed in Cirq Cynq 2025-04-30: trying to recall the reasons for the current design (which is a tuple, not a set), the sense is that it was probably created at a time when people weren't thinking about multiple tags. This is likely not an intentional behavior, but rather a bug.

mhucka avatar Apr 30 '25 17:04 mhucka

Some context: I am writing some tag transformers in #7306, in tests, I need to do some extra steps to compare TaggedOperation, it's not a blocker for me, but looks like it's a bug, so I am asking here.

babacry avatar Apr 30 '25 22:04 babacry

Drive-by comment, but I believe we have internal code where the order of tags matters.

andbe91 avatar Jul 09 '25 18:07 andbe91

Discussed with @andbe91 offline, the order of tags is necessary for now, e.g., in the use case of "converting circuits with DetAnnotation into stim", though it's worth discussing the possibility of "setify" tags in the future.

Label the issue for triaging, and consider closing the issue in the triage.

babacry avatar Jul 09 '25 19:07 babacry

@babacry (I apologize for my ignorance) Can you elaborate about what "setify" tags are?

mhucka avatar Aug 06 '25 16:08 mhucka

Due to backwards incompatible and current code relies on the order of tags, we will not do this.

dstrain115 avatar Aug 06 '25 17:08 dstrain115