From b718a13a3ce86a04c5bf5782269136bade65f72a Mon Sep 17 00:00:00 2001 From: Manideep3969 Date: Mon, 24 Aug 2026 10:51:44 +0530 Subject: [PATCH] perf(#60): replace O(n^2) circuits.index(c) with O(1) id lookup _measurement_based_batch called circuits.index(c) inside a loop, making overall complexity O(n^2). Build an {id(circuit): index} dictionary before the loop for O(1) lookups. --- src/qc_compiler/batching.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qc_compiler/batching.py b/src/qc_compiler/batching.py index 8b1e969..97bd9fe 100644 --- a/src/qc_compiler/batching.py +++ b/src/qc_compiler/batching.py @@ -182,6 +182,8 @@ def _measurement_based_batch( """ core_groups = self._group_by_unitary_core(circuits) + circuit_indices = {id(c): i for i, c in enumerate(circuits)} + batches = [] measurement_groups = {} unitary_core_groups = {} @@ -189,7 +191,7 @@ def _measurement_based_batch( for core_hash, group in core_groups.items(): batches.append(group) unitary_core_groups[core_hash] = [ - circuits.index(c) for c in group + circuit_indices[id(c)] for c in group ] basis_labels = []