slice_by_coloring¶
- slice_by_coloring(circuit, coloring)[source]¶
Split a
QuantumCircuit
into slices using the provided edge coloring.Two-qubit gates acting on identically colored qubit connections (edges) will be grouped greedily into slices using
CollectOpColor
. This will be done in order of increasing color value (the integer values which each edge is mapped to).Warning
Note, that this does not mean that low valued color slices are guaranteed to be left-most in your circuit. Below is an example to emphasize this.
>>> from qiskit import QuantumCircuit >>> circuit = QuantumCircuit(5) >>> _ = circuit.cx(0, 1) >>> _ = circuit.cx(3, 4) >>> _ = circuit.cx(2, 3) >>> circuit.draw() q_0: ──■─────── ┌─┴─┐ q_1: ┤ X ├───── └───┘ q_2: ───────■── ┌─┴─┐ q_3: ──■──┤ X ├ ┌─┴─┐└───┘ q_4: ┤ X ├───── └───┘ >>> coloring = {(0, 1): 0, (2, 3): 0, (3, 4): 1} >>> from qiskit_addon_utils.slicing import combine_slices, slice_by_coloring >>> slices = slice_by_coloring(circuit, coloring) # for illustration purposes, we are recombining the slices with barriers >>> recombined = combine_slices(slices, include_barriers=True) >>> recombined.draw() ░ q_0: ──────░───■── ░ ┌─┴─┐ q_1: ──────░─┤ X ├ ░ └───┘ q_2: ──────░───■── ░ ┌─┴─┐ q_3: ──■───░─┤ X ├ ┌─┴─┐ ░ └───┘ q_4: ┤ X ├─░────── └───┘ ░
Single-qubit gates will be collected into a single slice using
CollectOpSize
.- Parameters:
- Returns:
A sequence of
QuantumCircuit
objects, one for each slice.- Raises:
ValueError – The input edge coloring is invalid.
ValueError – Could not assign a color to circuit instruction.
- Return type: