🐛 Fix illegal number of qubits input#812
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdded explicit input validation and clarified docstrings across multiple benchmark circuit creators; several assertions were replaced with ValueError raises to prevent invalid circuit construction. Tests were updated to cover the new invalid-input behavior and one dedicated AE test was removed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@src/mqt/bench/benchmarks/full_adder.py`:
- Around line 24-25: The docstring for the function that documents the parameter
num_qubits is inconsistent with the runtime guard (the guard checks `num_qubits
< 4` and allows `num_qubits == 4`), so update the docstring sentence that
currently says "bigger than 4" to "at least 4" or "≥ 4" to match the validation
for the parameter `num_qubits`; locate the docstring referencing `num_qubits` in
the full adder function (the parameter named `num_qubits`) and change the
wording accordingly so it aligns with the existing guard `num_qubits < 4`.
In `@src/mqt/bench/benchmarks/half_adder.py`:
- Around line 24-25: The docstring for the function that builds the half-adder
circuit describes num_qubits as "bigger than 3" but the code validation allows
num_qubits == 3 (guard checks num_qubits < 3 and error text says "≥ 3"); update
the docstring wording for the num_qubits parameter to "at least 3" (or "≥ 3") to
match the validation and error message for the num_qubits parameter so the
documentation and guard (num_qubits) are consistent.
In `@src/mqt/bench/benchmarks/hhl.py`:
- Line 28: Update the docstring for the parameter num_qubits in hhl.py to state
it is the total number of qubits (including 1 system qubit, num_qpe_qubits =
num_qubits - 2 phase-estimation qubits, and 1 ancilla), not just the
phase-estimation register size; clarify the minimum requirement (at least 3) and
the relationship with num_qpe_qubits so callers understand how num_qubits maps
to phase-estimation precision.
In `@src/mqt/bench/benchmarks/modular_adder.py`:
- Around line 24-25: The docstring for the parameter num_qubits incorrectly says
"bigger than 2" while the validation allows num_qubits == 2; update the
docstring in modular_adder (the num_qubits parameter description) to say "at
least 2" or "≥ 2" to match the guard that checks num_qubits < 2 and the error
message.
There was a problem hiding this comment.
Pull request overview
This PR fixes input validation issues across multiple quantum benchmark circuits by replacing assertions with proper ValueError exceptions and adding comprehensive test coverage.
Changes:
- Replaced
assertstatements with properValueErrorexceptions inhhl.pyandbmw_quark_copula.py - Added input validation to
qpeexact.py(previously had no validation) - Consolidated validation tests into the existing parameterized
test_wrong_circuit_sizetest and removed redundant standalone test - Updated docstrings across 13 benchmark files to clarify input requirements
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_bench.py | Added test cases for hhl, qpeexact, bmw_quark_copula, and ae validation; removed redundant standalone ae test |
| src/mqt/bench/benchmarks/hhl.py | Replaced assertion with ValueError for num_qubits < 3 validation; updated docstring |
| src/mqt/bench/benchmarks/qpeexact.py | Added new validation for num_qubits <= 1; updated docstring |
| src/mqt/bench/benchmarks/bmw_quark_copula.py | Replaced assertion with ValueError for odd num_qubits validation; updated docstring |
| src/mqt/bench/benchmarks/ae.py | Updated docstring to clarify minimum qubit requirement |
| src/mqt/bench/benchmarks/shor.py | Minor docstring formatting improvement |
| src/mqt/bench/benchmarks/rg_qft_multiplier.py | Enhanced docstring with specific validation requirements |
| src/mqt/bench/benchmarks/multiplier.py | Enhanced docstring with specific validation requirements |
| src/mqt/bench/benchmarks/modular_adder.py | Minor docstring formatting improvement |
| src/mqt/bench/benchmarks/hrs_cumulative_multiplier.py | Enhanced docstring with specific validation requirements |
| src/mqt/bench/benchmarks/half_adder.py | Minor docstring formatting improvement |
| src/mqt/bench/benchmarks/full_adder.py | Minor docstring formatting improvement |
| src/mqt/bench/benchmarks/draper_qft_adder.py | Enhanced docstring with specific validation requirements |
| src/mqt/bench/benchmarks/cdkm_ripple_carry_adder.py | Enhanced docstring with specific validation requirements |
| src/mqt/bench/benchmarks/bv.py | Enhanced docstring to clarify hidden_string length requirement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
burgholzer
left a comment
There was a problem hiding this comment.
Nice. Great to have more consistency across the documentation and better error messages.
Looking forward to getting a release out with these changes. Probably after the dynamic circuits have been merged.
|
Ah, a changelog entry could have been nice.. maybe if you remember in your next PR, you could add one for this PR as well 🙂 |
Description
This PR fixes (#811) illegal number of qubits in qpeexact and harmonizes docstrings that specify num_qubits.
Checklist: