tqecd.fragment.split_stim_circuit_into_fragments#

split_stim_circuit_into_fragments(circuit: Circuit) list[Fragment | FragmentLoop][source]#

Split the circuit into fragments.

The provided circuit should check a few pre-conditions:

  • If there is one measurement (resp. reset) instruction between two TICK annotation, then only measurement (resp. reset) instructions, annotations and noisy gates can appear between these two TICK. Any other instruction will result in an exception being raised.

  • The circuit should be (recursively if it contains one or more instance of stim.CircuitRepeatBlock) composed of a succession of layers that should have the same shape:

    • starts with zero or more moments containing exclusively reset operations,

    • continuing with zero or more moments containing any non-collapsing operation (i.e., anything except reset and measurement operations).

    • ends with one moment containing exclusively measurement operations.

    For the above reasons, be careful with reset/measurement combined operations (e.g., the stim instruction MR that performs in one instruction a measurement and a reset in the Z basis). These instructions are not supported by the tqec library and it is up to the user to check that the input circuit does not contain combined measurements/resets instructions.

Parameters:

circuit (stim.Circuit) – the circuit to split into Fragment instances.

Raises:
  • TQECDException – If the circuit contains at least one moment (i.e., group of instructions between two TICK annotations) that are composed of at least one measurement (resp. one reset) and at least one non-annotation, non-measurement (resp. non-reset) instruction.

  • TQECDException – If the circuit contains combined measurement/reset instructions.

  • TQECDException – If the provided circuit could not be split into fragments due to an invalid structure.

Returns:

the resulting fragments.