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.basis and replaced np.kron with precomputed arrays.
    • Result: reduced execution time for 1000 iterations across dimensions from ~ 1.4×10⁸ ns → ~ 0.9×10⁶ ns.
  • PR # 1305 Basis states

    • Original implementation involved multiple stringlistintnumpy conversions and a redundant conj().
    • New implementation uses direct zero initialization and index assignment, with improved input validation.

    • Result: ~100× speedup across tested dimensions (4 <= dim <= 16384).
  • 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.

<
Previous Post
Week 10 (3rd August to 9th August)
>
Next Post
Week 12 (17th August to 23rd August)