tqec.circuit.schedule.manipulation.relabel_circuits_qubit_indices#
- relabel_circuits_qubit_indices(circuits: Sequence[ScheduledCircuit]) tuple[list[ScheduledCircuit], QubitMap] [source]#
Relabel the qubit indices of the provided circuits to avoid collision.
When several
ScheduledCircuit
are constructed without a global knowledge of all the qubits, qubit indices used by each instance likely overlap. This is an issue when we try to merge such circuits because one index might represent a different qubit depending on the circuit it is used in.This function takes a sequence of circuits and relabel their qubits to avoid such collisions.
Warning
all the qubit targets used in each of the provided circuits should have a corresponding entry in the circuit qubit map for this function to work correctly. If that is not the case, a KeyError will be raised.
- Raises:
KeyError – if any of the provided circuit contains a qubit target that is not present in its qubit map.
- Parameters:
circuits – circuit instances to remap. This parameter is not mutated by this function and is only used in read-only mode.
- Returns:
the same circuits with update qubit indices as well as the global qubit indices map that has been used. Qubits in the returned global qubit map are assigned to an index such that:
the sequence of indices is range(0, len(qubit_map)).
qubits are assigned indices in sorted order.