Skip to content

Port the Quantum Fourier Transform (QFT) all-to-all implementation to Rust - #16789

Merged
Cryoris merged 6 commits into
Qiskit:mainfrom
simona-rc:qft_full_to_rust
Aug 19, 2026
Merged

Port the Quantum Fourier Transform (QFT) all-to-all implementation to Rust#16789
Cryoris merged 6 commits into
Qiskit:mainfrom
simona-rc:qft_full_to_rust

Conversation

@simona-rc

@simona-rc simona-rc commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates synth_qft_full from a pure-Python implementation to Rust. The implementation includes:

  • crates/synthesis/src/qft/qft_decompose_full.rs - construct the textbook Quantum Fourier Transform (QFT) circuit.
  • qiskit/synthesis/qft/qft_decompose_full.py - thin Python wrapper that delegates circuit construction to Rust. The inverse, when needed, is performed in Python because the Rust API currently does not provide an equivalent CircuitData function.
  • All existing tests passed. Additinally, tested correctness by comparing the current implementation against the original version as follows:
    • Unitary equivalence - exact Operator comparison for all parameter combinations up to 12 qubits.
    • Gate-sequence match - instruction-level comparison (gate name, qubit indices, angles rounded to 12 decimal places) up to 100 qubits.
    • Gate-count formula - verifies H, CP, and Swap counts against the closed-form formula for circuits up to 1000 qubits.

Performance

Benchmarking compares the Rust implementation (current branch) against the original Python version (main branch):

Number of qubits Python (ms) Rust (ms) Speedup
5 0.0548 0.0060 9.2x
10 0.1675 0.0098 17.2x
20 0.5802 0.0208 28.0x
50 3.3801 0.1020 33.1x
100 13.6543 0.4142 33.0x
200 53.9664 1.7819 30.3x
500 361.6054 20.0564 18.0x
1000 1405.1210 128.3175 11.0x

Speedup ranges from ~9x at 5 qubits up to ~30x at 200 qubits. The decrease at large sizes reflects that circuit construction overhead becomes dominated by memory allocation for the instruction list rather than Python dispatch cost.

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description: IBM Bob 2.0.3; I reviewed and checked the tool's suggestions. I also used it to create the local correctness tests.
  • I used the following tool to generate or modify code:

@simona-rc
simona-rc requested a review from a team as a code owner August 18, 2026 09:32
@simona-rc
simona-rc requested a review from gadial August 18, 2026 09:32
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Aug 18, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@CLAassistant

CLAassistant commented Aug 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ShellyGarion ShellyGarion removed the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Aug 18, 2026
@ShellyGarion ShellyGarion added this to the 2.6.0 milestone Aug 18, 2026
@ShellyGarion ShellyGarion added Rust This PR or issue is related to Rust code in the repository performance Changelog: Performance Performance improvements without API and semantic changes. synthesis labels Aug 18, 2026
@ShellyGarion
ShellyGarion self-requested a review August 18, 2026 09:45

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

Thanks for having a stab at this! I left some comments below.

Vec::new() // not used in the fast path
};

for j in (0..num_qubits).rev() {

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.

I think this structure can be optimized, we can avoid iterating over the instruction twice and having different code paths for barrier/no barrier. This should also improve the performance a bit. There's two options that would make sense

  1. Write a single loop that calls .push_standard_gate or .push_packed_operation for barriers. This is the simpler one.
  2. Build a single large iterator over PackedOperations and construct the final circuit using CircuitData::from_packed_operations -- see e.g. code in the pauli_evolution.rs module doing that.

I would suggest going with 1 for starters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review!
I updated the code using option 1 in
a50c6da

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks, I agree that the code looks better now when considering both "with barriers" and "no barrier" options :)

Comment thread crates/synthesis/src/qft/qft_decompose_full.rs Outdated
Comment thread crates/synthesis/src/qft/qft_decompose_full.rs Outdated
Comment thread crates/synthesis/src/qft/qft_decompose_full.rs Outdated
Comment thread releasenotes/notes/improve_qft_full_performance_via_rust-6877d92b7470e344.yaml Outdated
@ShellyGarion
ShellyGarion removed the request for review from gadial August 19, 2026 04:33
@simona-rc
simona-rc requested a review from Cryoris August 19, 2026 13:20

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

LGTM thanks for your contribution @simona-rc !

@Cryoris

Cryoris commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Before merging -- did you want to re-run the benchmarks after the current restructuring?

@simona-rc

Copy link
Copy Markdown
Contributor Author

I already did a re-run of the benchmarks and upddated this PR description with the results.

@Cryoris
Cryoris added this pull request to the merge queue Aug 19, 2026
Merged via the queue into Qiskit:main with commit 74b7256 Aug 19, 2026
31 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.6 Aug 19, 2026
raynelfss pushed a commit to raynelfss/qiskit that referenced this pull request Aug 19, 2026
… Rust (Qiskit#16789)

* port qft_full to rust

* Reduce duplicated code for insert_barriers=true and insert_barriers=false

* Add release notes

* Updated release notes

* Updated to a single loop that generates the circuit directly

* Updated release notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Performance Performance improvements without API and semantic changes. Rust This PR or issue is related to Rust code in the repository synthesis

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants