Skip to content

Add cache-friendly qubit index remapping#1075

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

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

Conversation

@xxie24
Copy link
Copy Markdown
Contributor

@xxie24 xxie24 commented May 26, 2026

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
Copy link
Copy Markdown
Contributor

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

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
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.

1 participant