Repository navigation
fix: keep every bound in a chained comparison - #124
Conversation
Python parses a < b < c as one Compare node carrying every operator, but visit_Compare read only ops[0] and comparators[0], so each bound after the first was discarded and the emitted OpenQASM silently implemented different logic than the source. Iterate the whole chain and fold the pairs with ag__.and_, matching how the upstream logical_expressions pass decomposes chains for operators it overloads. Mixed chains still fall through to that pass unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #124 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 52 52
Lines 2290 2296 +6
Branches 266 268 +2
=========================================
+ Hits 2290 2296 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rmshaffer
left a comment
There was a problem hiding this comment.
Thank you for taking the initiative to fix this! I think it's in the right direction; just left a couple comments that I'd appreciate if you could address.
Addresses review feedback: moves the rationale out of the docstring, folds the end-to-end regression case into test_comparison_ops_py, and adds coverage for a four-operator chain and for a chain containing an equality operator. Both new cases fail against the unmodified converter.
|
All three are in 9121ce0, which I pushed without commenting, so this still shows as blocked. Docstring rationale removed, and the standalone test is now the Both chains you named are covered, using your examples. Reverting Restoring it:
|
|
Correction to my last line, I read the rollup too quickly. The four workflows did run on So they are waiting on your approval to run, not missing. Sorry for the noise. |
The two chain tests asserted only that each comparison appeared somewhere in the IR, which passes even if the operands are folded together wrongly. Assert the full expected IR, matching how the rest of this file tests generated code, so a mis-folded chain fails. Also extend test_comparison_ops_py with a three-operator chain whose last bound is the failing one, so dropping a late bound cannot pass unnoticed.
|
All three addressed, thanks for the review. Worth flagging from the validation you asked for: Both chain tests now assert the full expected IR instead of substrings, since a substring check passes even when the operands are folded together wrongly. |
Issue #, if available: none filed.
Description of changes:
Python parses
a < b < cas oneComparenode holding every operator, butvisit_Compareread onlyops[0]andcomparators[0]. Every bound after the first was discarded, so the emitted OpenQASM silently implemented different logic than the source. On mainif 0 <= n < 10withn = 1000emitsh __qubits__[0];unconditionally; it now emitsx.The fix walks the chain and folds the pairs with
ag__.and_, the helper the upstreamlogical_expressionspass already uses. Single and mixed chains are unchanged.Testing done:
494 passed, 2 xfailed. Reverting only the source and keeping the two new tests leaves exactly those two failing, at 492 passed.
ruffis clean apart from five pre-existingunused-noqafindings present either way.Merge Checklist
General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.