Added Dynamical QFT + Measurement#807
Added Dynamical QFT + Measurement#807morrishuismans wants to merge 9 commits intomunich-quantum-toolkit:mainfrom
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
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.
|
@flowerthrower @burgholzer Dear Lukas and Patrick, could you please review my code? Thanks in advance! |
Signed-off-by: morrishuismans <97433985+morrishuismans@users.noreply.github.com>
burgholzer
left a comment
There was a problem hiding this comment.
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.
|
|
||
| # QFT & M v.1 |
There was a problem hiding this comment.
| # QFT & M v.1 |
The docstring here feels a bit arbitrary
|
|
||
| # QFT & M v.1 | ||
|
|
||
| """Dynamical QFT + M benchmark definition.""" |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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])
There was a problem hiding this comment.
Slight naming tweak: The canonical name for classical registers in Qiskit is c (not cl) might be worth adapting that.
There was a problem hiding this comment.
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.
Description
Adds the Dynamical QFT + Measurement circuit as a dynamical benchmarking circuit.
Fixes #798
Checklist: