BoxKey

class samplomatic.utils.BoxKey(instruction: CircuitInstruction)[source]

Bases: object

An immutable snapshot of an instruction that owns a box, suitable for comparison and hashing.

Instances of this class can be used, for example, as keys for a dictionary or as elements of a set. Mutating the original box does not mutate this class.

At construction time, this class computes a standardized, immutable form of the instruction, which is the used when comparing two instances of this class, or when hashing one. In particular, this form is chosen so that properties such as instruction order within topological layers of the box, or order of symmetric instructions like "cz" are not relevant; we do not want cz(0, 1) and cz(1, 0), for example, to result in inequality or distinct hashes.

Annotation comparison is unordered. It is assumed that all annotation types present are hashable (and consequently, immutable). Behavior is not defined when multiple equal annotations are present.

Parameters:

instruction – The instruction to create an immutable snapshot of.

Raises:

ValueError – If the instruction does not own a BoxOp.