Skip to main contentIBM Quantum Documentation

slicing

qiskit_addon_utils.slicing

Utility methods for circuit slicing.

For more information, check out the how-to guide which discusses this submodule.

combine_slices

combine_slices(slices, include_barriers=False)

GitHub

Combine N-qubit slices of a circuit into a single circuit.

Parameters

  • slices (Sequence[QuantumCircuit]) – The N-qubit circuit slices.
  • include_barriers (bool) – If True, place barriers between each slice.

Returns

A QuantumCircuit with the slices appended in sequential order.

Raises

ValueError – Two input slices were defined on different numbers of qubits.

Return type

QuantumCircuit | None

slice_by_barriers

slice_by_barriers(circuit)

GitHub

Split a QuantumCircuit into slices around full-circuit barriers.

Barriers which do not act on all circuit qubits will be treated as normal operations and included in the slices. Barriers which act on all qubits will be interpreted as slice locations and will not be included in the output slices.

Parameters

circuit (QuantumCircuit) – The circuit to be split.

Returns

A sequence of QuantumCircuit objects, one for each slice.

Return type

list[QuantumCircuit]

slice_by_coloring

slice_by_coloring(circuit, coloring)

GitHub

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

  • circuit (QuantumCircuit) – The circuit to be split.
  • coloring (dict[tuple[int, int], int]) – A dictionary mapping edges (pairs of integers) to color values.

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

list[QuantumCircuit]

slice_by_depth

slice_by_depth(circuit, max_slice_depth)

GitHub

Split a QuantumCircuit into slices based on depth.

This function transforms the input circuit into a DAGCircuit and batches the sequence of depth-1 layers output from layers() into slices of depth not exceeding max_slice_depth. This is achieved by composing layers into slices until the max slice depth is reached and then starting a new slice with the next layer. The final slice may be composed of fewer than max_slice_depth layers.

Parameters

  • circuit (QuantumCircuit) – The circuit to be split.
  • max_slice_depth (int) – The maximum depth of a given slice.

Returns

A sequence of QuantumCircuit objects, one for each slice.

Return type

list[QuantumCircuit]

slice_by_gate_types

slice_by_gate_types(circuit)

GitHub

Split a QuantumCircuit into depth-1 slices of operations of the same type.

Warning

Note: Adjacent slices sharing no qubits in common may be ordered arbitrarily.

Parameters

circuit (QuantumCircuit) – The circuit to be split.

Returns

A sequence of QuantumCircuit objects, one for each slice.

Return type

list[QuantumCircuit]

Was this page helpful?
Report a bug or request content on GitHub.