Skip to content

Add cache-friendly qubit index remapping - #1075

Closed
xxie24 wants to merge 1 commit into
quantumlib:mainfrom
xxie24:remap_qubit
Closed

Add cache-friendly qubit index remapping#1075
xxie24 wants to merge 1 commit into
quantumlib:mainfrom
xxie24:remap_qubit

Conversation

@xxie24

@xxie24 xxie24 commented May 26, 2026

Copy link
Copy Markdown
Contributor

The remap scores circuit qubits by gate usage, places frequently used qubits on lower physical state-index bits, and rewrites gates so simulation preserves the original logical circuit semantics. This improves memory locality for hot qubits during gate application.

Summary:

  • Adds -r / cache_local_remap support.
  • Builds a logical-to-physical qubit map from gate usage.
  • Remaps gate targets, controls, and matrix ordering.
  • Supports fused-gate execution by scoring fused gates and rebuilding fused metadata after remap.
  • Remaps requested output amplitudes back to logical qubit order.

Benchmark note:

  • Measured about 9% runtime improvement on the q30 circuit in local testing.

@github-actions github-actions Bot added the size: XL lines changed >1000 label May 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces qubit remapping functionality (qubit_remap.h) to improve state-vector cache locality, adds a NEON-vectorized simulator (simulator_neon.h and statespace_neon.h), and updates the runner and build configurations to support these features. The code review identified critical issues in the new remapping logic, including a potential out-of-bounds memory access in RemapIndex, a logic bug in RemapMeasurementResult that corrupts measurement results by incorrectly rebuilding the bitstring, and undefined behavior in RemapControlQubits caused by shifting a boolean value by more than 31 bits.

Comment thread lib/qubit_remap.h
Comment thread lib/qubit_remap.h Outdated
Comment thread lib/qubit_remap.h Outdated
@github-actions github-actions Bot added size: L 250< lines changed <1000 and removed size: XL lines changed >1000 labels May 26, 2026
@xxie24
xxie24 force-pushed the remap_qubit branch 5 times, most recently from 2bd3c08 to a48e67d Compare May 26, 2026 14:10

@sergeisakov sergeisakov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! I took a look at the performance impact, but I'm not quite seeing the 9% runtime improvement on my end. Depending on the circuit and platform, my benchmarks show results fluctuating within about ±5% (runtime can increase). Because the gains seem marginal here, it might be worth exploring alternative strategies for optimizing performance.

@xxie24

xxie24 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

close this, the main work is shifted into the #1092 which has more effective optimization.

@xxie24 xxie24 closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants