Skip to content

Added Dynamical QFT + Measurement#807

Open
morrishuismans wants to merge 9 commits intomunich-quantum-toolkit:mainfrom
morrishuismans:dynamic_QFT
Open

Added Dynamical QFT + Measurement#807
morrishuismans wants to merge 9 commits intomunich-quantum-toolkit:mainfrom
morrishuismans:dynamic_QFT

Conversation

@morrishuismans
Copy link

@morrishuismans morrishuismans commented Jan 23, 2026

Description

Adds the Dynamical QFT + Measurement circuit as a dynamical benchmarking circuit.

Fixes #798

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@morrishuismans
Copy link
Author

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a Dynamical Quantum Fourier Transform with Measurement benchmark circuit.
  • Tests

    • Added a unit test validating creation and key operations of the new benchmark circuit.
  • Chores

    • Updated Qiskit dependency requirement to 2.0.0 or newer.
  • Documentation

    • Updated changelog and contributor list to reflect the addition.

Walkthrough

Adds a new Dynamical Quantum Fourier Transform + Measurement benchmark module, a test for a 5-qubit circuit, a changelog entry, and bumps the Qiskit dependency to >=2.0.0. The benchmark builds H gates, mid-circuit measurements, and measurement-conditioned phase rotations.

Changes

Cohort / File(s) Summary
Dynamical QFT Benchmark Implementation
src/mqt/bench/benchmarks/dynamical_qft.py
New module registering create_circuit(num_qubits: int) -> QuantumCircuit with @register_benchmark. Builds a circuit named dynamical_qft: applies H to each qubit, measures each qubit into a corresponding classical bit, and applies conditional P(2π/2^(j+1)) rotations to subsequent qubits based on each measurement.
Benchmark Tests
tests/test_bench.py
Added test_dynamical_qft that constructs a 5-qubit/5-classical-bit circuit and asserts circuit name, counts of Hadamard gates (5), measurements (5), and presence/count of conditional/if_else blocks (5).
Changelog
CHANGELOG.md
Added an "Unreleased" entry for the Dynamical QFT + Measurement benchmark, updated PR links, and added the contributor entry.
Project Metadata
pyproject.toml
Bumped Qiskit requirement from qiskit[qasm3-import]>=1.3.2 to qiskit[qasm3-import]>=2.0.0 (comment updated regarding mid-circuit measurement/support).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hop through qubits with a careful chart,
H first, then I measure — a tiny art.
Bits whisper numbers, phases take flight,
Rotations twirl by classical light.
Dynamical QFT, I sing tonight! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Added Dynamical QFT + Measurement' directly and specifically describes the main change: introduction of a dynamical QFT circuit with measurement capability.
Description check ✅ Passed PR description includes a clear summary, references the fixed issue #798, and completes all checklist items, demonstrating comprehensive coverage of required template elements.
Linked Issues check ✅ Passed The implementation fully satisfies issue #798 objectives: the new dynamical_qft.py module implements QFT with measurement using O(n) mid-circuit measurements and classical feed-forward instead of O(n^2) gates, with supporting tests and documentation updates.
Out of Scope Changes check ✅ Passed The Qiskit version bump (1.3.2 to 2.0.0) is a necessary dependency update to support mid-circuit measurements required by the dynamical QFT implementation, making it in-scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@morrishuismans
Copy link
Author

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@src/mqt/bench/benchmarks/dynamical_qft.py`:
- Line 21: The description string passed to the register_benchmark decorator for
"dynamical_qft" contains a leading space; update the decorator usage (the
`@register_benchmark` call for "dynamical_qft") to remove the leading space so the
description reads "Dynamic Quantum Fourier Transformation and Measurement (DQFT
+ M)" instead of " Dynamic...".

In `@tests/test_bench.py`:
- Around line 227-234: Add a circuit name assertion to test_dynamical_qft to
match other tests: after creating qc via create_circuit("dynamical_qft", 5)
assert that qc.name (or the circuit's name property used elsewhere) equals
"dynamical_qft" to ensure consistency with tests like test_bv and
test_graphstate_seed; update the test_dynamical_qft function to include this
assertion immediately after the circuit is created.
- Around line 236-245: The test_dynamical_qft_gates currently only checks
Hadamard and measurement counts; add an assertion to verify the conditional
phase rotations by counting entries in qc.data where inst.operation.name is "p"
or the phase gate identifier used by create_circuit for dynamical_qft, and
assert that for num_qubits=5 the phase/controlled-phase gate count equals 10
(4+3+2+1+0). Locate the test function test_dynamical_qft_gates and use qc.data
iteration (same pattern as hadamard_count) to compute phase_count and add the
assert phase_count == 10 so the dynamical QFT's conditional rotations are
covered.

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@morrishuismans
Copy link
Author

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@pyproject.toml`:
- Around line 22-24: The pyproject currently pins "qiskit[qasm3-import]>=2.0.0"
while the comment references fixes present in Qiskit 1.3.2; either lower the
minimum to the appropriate older version (e.g., "qiskit[qasm3-import]>=1.3.2" or
the exact earliest release containing the OpenQASM3 export fixes) or add a clear
justification next to the dependency line explaining why 2.0.0 is required
(mentioning the specific features like BoxOp or control-flow changes if relied
upon); update the dependency string "qiskit[qasm3-import]>=2.0.0" or the
adjacent comment accordingly.

@morrishuismans morrishuismans marked this pull request as ready for review January 27, 2026 08:35
@morrishuismans morrishuismans marked this pull request as draft January 27, 2026 08:36
@morrishuismans morrishuismans marked this pull request as ready for review January 28, 2026 17:19
@morrishuismans
Copy link
Author

@flowerthrower @burgholzer Dear Lukas and Patrick, could you please review my code? Thanks in advance!

@morrishuismans morrishuismans marked this pull request as draft February 2, 2026 14:25
Signed-off-by: morrishuismans <97433985+morrishuismans@users.noreply.github.com>
@morrishuismans morrishuismans marked this pull request as ready for review February 2, 2026 16:10
@burgholzer burgholzer self-requested a review February 3, 2026 20:36
@burgholzer burgholzer added python Pull requests that update Python code feature New feature or request labels Feb 4, 2026
Copy link
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this!
This looks like great progress already.
You can find some suggestions/feedback in the comments below.
I hope none of them should really be hard to address.

You will also need to merge in the latest changes from main so that the conflicts are resolved.

Comment on lines +8 to +9

# QFT & M v.1
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# QFT & M v.1

The docstring here feels a bit arbitrary


# QFT & M v.1

"""Dynamical QFT + M benchmark definition."""
Copy link
Member

Choose a reason for hiding this comment

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

I would have a slight tendency to consistently refer to this as Dynamic QFT (instead of "dynamical" or "QFT+M"). This applies to all occurrences where the name is used.


@register_benchmark("dynamical_qft", description="Dynamic Quantum Fourier Transformation and Measurement (DQFT + M)")
def create_circuit(num_qubits: int) -> QuantumCircuit:
"""Returns a quantum circuit implementing the Dynamic Quantum Fourier Transform and Measurement algorithm.
Copy link
Member

Choose a reason for hiding this comment

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

This docstring could be made a little more detailed and explain a little bit more about the algorithm itself. From this docstring alone, no one would have an idea of what the algorithm is doing. There is also no reference to some kind of resource this is based on.

Comment on lines +25 to +40
Arguments:
num_qubits: number of qubits of the returned quantum circuit

Returns:
QuantumCircuit: a quantum circuit implementing the Dynamic Quantum Fourier Transform and Measurement algorithm
"""
q = QuantumRegister(num_qubits, "q")
cl = ClassicalRegister(num_qubits, "cl")
qc = QuantumCircuit(q, cl, name="dynamical_qft")
for i in range(num_qubits):
qc.h(q[i])
qc.measure(q[i], cl[i])
with qc.if_test((cl[i], 1)):
for j in range(1, num_qubits - i):
qc.p(2 * np.pi / 2 ** (j + 1), q[j + i])
return qc
Copy link
Member

Choose a reason for hiding this comment

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

Initially I was thinking this isn't really the way I imagined this to be written, because I would have imagined this to be a single-qubit circuit that repeatedly resets the qubit and applies phase corrections to it based on previous measurements (similar to iQPE from #806).
However, after thinking about it a little more, this kind of does make sense to portray as an n qubit circuit. This also allows using this circuit as a benchmark for circuit optimization techniques that would, e.g., introduce qubit reuse to shrink the circuit.

Copy link
Member

Choose a reason for hiding this comment

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

Micro optimization: The phase computation can be simplified a bit here

qc.p(2 * np.pi / 2 ** (j + 1), q[j + I])

is equivalent to

qc.p(np.pi / (2 ** j), q[j + I])

Copy link
Member

Choose a reason for hiding this comment

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

Slight naming tweak: The canonical name for classical registers in Qiskit is c (not cl) might be worth adapting that.

Copy link
Member

Choose a reason for hiding this comment

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

Similar to #806, this will need an upper bound on the number of qubits since the shift operation only makes sense up to a certain number of qubits and is not well defined afterwards.

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

Labels

feature New feature or request python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Dynamical QFT

2 participants