Week 11 (10th August to 16th August)
This week shifted focus from benchmarking to profiling and optimizing core functions in toqito. With most of the benchmarking framework now stable, I began systematically profiling functions that occur frequently across the library and rewriting them for performance. The results have been very promising.
At the same time, discussions with my mentors (Vincent Russo and Purva Thakre) brought in ideas for the next phase: integrating benchmarking results into documentation, adding regression analysis, and expanding profiling to heavier functions like partial trace.
Progress:
I profiled and optimized widely used functions in toqito.states:
- PR # 1304 Bell States
- Removed the dependency on
toqito.states.basisand replacednp.kronwith precomputed arrays. - Result: reduced execution time for 1000 iterations across dimensions from ~ 1.4×10⁸ ns → ~ 0.9×10⁶ ns.
- Removed the dependency on
-
PR # 1305 Basis states
- Original implementation involved multiple
string→list→int→numpyconversions and a redundantconj(). -
New implementation uses direct zero initialization and index assignment, with improved input validation.
- Result: ~100× speedup across tested dimensions (4 <= dim <= 16384).
- Original implementation involved multiple
- PR # 1306 Maximally Entangled States
- Original code built a full identity matrix (dense or sparse) before reshaping.
- New approach uses stride indexing for dense arrays and direct sparse construction (
coo_array). - Result: reduced complexity from
O(dim^2)→O(dim). Profiling shows 3–5x speedups depending on sparsity.