tqec.circuit.schedule.manipulation.remove_duplicate_instructions#

remove_duplicate_instructions(instructions: list[CircuitInstruction], mergeable_instruction_names: frozenset[str]) list[CircuitInstruction][source]#

Removes all the duplicate instructions from the given list.

Note

This function guarantees the following post-conditions on the returned results:

  • Instructions with a name that is not in mergeable_instruction_names are returned at the front of the returned list, in the same relative ordering as provided in instructions input.

  • Instructions with a name that is in mergeable_instruction_names will be returned after all the instructions with a name that does not appear in mergeable_instruction_names. The order in which these instructions are returned is not guaranteed and can change between executions.

Warning

this function does not keep instruction ordering. It is intended to be used with input instructions that, once de-duplication has been applied, form a valid moment, which means that each instruction can be executed in parallel, and so their order in the returned list does not matter.

If that is not your case, take extra care to the output of this function as it will likely introduce hard-to-debug issues. To prevent such potential misuse, this function checks for such cases and outputs a warning if it happens.

Returns:

a list containing a copy of the stim.CircuitInstruction instances from the given instructions but without any duplicate.