iqm.qrisp_iqm.passes.routing.core.sabre_metric.compute_sabre_cost_change#
- iqm.qrisp_iqm.passes.routing.core.sabre_metric.compute_sabre_cost_change(instruction_data: ndarray, fl_inv_0: list[int], fl_inv_1: list[int], es_inv_0: list[int], es_inv_1: list[int], old_c2a: ndarray, swap_0: int, swap_1: int, exp_depth_array: ndarray, front_layer_prefactor: float, extended_layer_prefactor: float, distance_matrix: ndarray) float#
Compute the cost change induced by a given swap.
For this it only considers the terms that actually contribute, which is much more efficient.
Instead of receiving a full new_c2a array (which requires a copy per call), the swap is described by the two citizen indices (swap_0, swap_1). The new addresses are resolved inline with a branch, avoiding an array allocation per swap candidate.
The involvement lists are passed as 4 separate lists (two per layer type), one for each qubit of the swap. This avoids the allocation of a concatenated list per swap candidate.
- Parameters:
instruction_data (np.ndarray) – An array describing what instructions are available globally (see graph_processing_tools for more details).
fl_inv_0 (list[int]) – Front layer involvement list of the first swap qubit.
fl_inv_1 (list[int]) – Front layer involvement list of the second swap qubit.
es_inv_0 (list[int]) – Extended set involvement list of the first swap qubit.
es_inv_1 (list[int]) – Extended set involvement list of the second swap qubit.
old_c2a (np.ndarray) – An array indicating the current permutation of qubits.
swap_0 (int) – The citizen index of the first qubit being swapped.
swap_1 (int) – The citizen index of the second qubit being swapped.
exp_depth_array (np.ndarray) – An array containing the precomputed weight factors of each instruction.
front_layer_prefactor (float) – The precomputed factor that is used to weight the front layer part of the metric.
extended_layer_prefactor (float) – The precomputed factor that is used to weight the extended set part of the metric.
distance_matrix (np.ndarray) – The distance matrix from the topology tuple.
- Returns:
The computed metric change.
- Return type: