【代码贡献】修复 QARM 支持度与关联规则结果错误 - #50
Open
OnerGit wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue:#13(2026 本源杯开源创新赛道|代码贡献)
一、问题 / Problem
当前 QARM 实现在合法 transaction dataset 上可能返回错误的 frequent-itemset support 和 association rules,甚至产生大于 1 的支持度。
仓库自带
data2.txt包含 10 条 transaction,其中“面包”实际出现 7 次,因此:修复前,QARM 的一阶搜索可能恢复出 57 个所谓 matching states:
该错误会沿着:
继续传播。
例如:
因此这不是显示或精度问题,而是最终关联规则结果的 correctness defect。
二、原因 / Root Cause
当前 QARM 的一阶搜索对不同 target item 使用同一套、与实际 marked-state 数量
M无关的 amplitude-amplification schedule。对当前 QARM 双索引寄存器线路的概率行为验证表明,奇数
t对应:当 target item 较频繁时,原有较深 schedule 会发生 over-rotation,使 unmarked states 的概率反而高于 marked states。
以
data2.txt的“面包”为例:t=3时 marked states 构成最大概率平台;原 schedule 使用t=9时则已经发生明显 over-rotation。此外,原
_get_result():这会带来两个额外问题:
三、修复 / Fix
本 PR 保持现有 QARM architecture,只修改一阶搜索所需的最小范围。
1. 3 个及以上 item:固定浅层
t=3QARM 后续需要的是完整 matching row set,而不是只采样出一个 marked state,因此这里的目标并不是最大化单次 Grover success probability,而是保证:
设:
一次有效 Grover rotation 后:
因此只要:
即可形成严格 probability separation。
对当前 QARM,当 item 数量不少于 3 时:
且:
因此
t=3足以稳定区分 marked / unmarked states,而不需要预先知道M或额外执行 Quantum Counting。2. 直接按 probability key 解码
_get_result()现在:math.isclose(..., rel_tol=1e-10)聚合理论相等的最大概率 states;3. Two-item domain 使用 exact classical fallback
当只有两个 item 时:
合法输入可能达到:
此时 marked 和 unmarked per-state probability 无法通过 Grover rotation 分离。
因此该完整 domain 直接从 QARM 已有 transaction matrix 精确恢复 matching rows。
这样保持 downstream contract 不变:
而不引入 Quantum Counting、随机 unknown-M search 或更大的 architecture rewrite。
四、验证 / Validation
Committed regression tests
新增:
覆盖:
data2.txt的“面包” row recovery / support;牛奶 -> 面包confidence;M/N = 1/2boundary;执行结果:
Focused regression 连续执行两次均为
11 passed。Supplementary systematic validation
提交前另使用未随 PR 提交的 deterministic small-dataset validation,对修复进行了补充核验:
并覆盖 support / confidence threshold 的 below / equal / above boundary。
上述 systematic sweep 属于补充验证;PR 中可直接复现的权威 regression 仍为本次提交的测试文件。
五、资源影响 / Resource Impact
修复后的 3+ item quantum path 固定使用:
而原实现代表性 case 使用
t = 5或t = 9。在 9 个 correctness-aware benchmark case 中:
在 old / fixed 都正确的 6 个 case 中,修复版本的 median runtime 均较低。
这里的主要目标仍然是 correctness;runtime 变化仅作为 resource impact 记录,不作为独立性能优化 claim。
六、兼容性与行为变化 / Compatibility
run()API:不变;一个有意的细微行为差异是:
CPUQVM 路径已实际验证。
QCloud
full_amplitude路径从源码和 probability-dictionary contract 上与本修复兼容,但本 PR 未使用实时 QCloud credentials 执行验证。本修复依赖当前 QARM 使用的完整理想 probability distribution 来恢复最大概率平台,不声称等价适用于 finite-shot sampling。
七、已知限制 / Known Limitations
1.
_get_all_conf()的规则枚举范围当前
_get_all_conf()主要生成(k-1) -> 1类型规则,并不完整枚举所有 multi-item consequent。这是与本次 F1 quantum-search correctness 独立的既有问题,本 PR 不扩大范围处理。
2. 本 PR 修复的是当前仓库实现
本 PR 的目标是:
不声称修改或修复原始 QARM 论文中的完整算法架构。
八、Related Work / Non-overlap
【代码贡献】修正 Grover 最优迭代次数计算,补充输入校验与依赖声明 #36 修正 generic Grover 在已知 marked-state 数量
M时的最优 iteration selection。本 PR 中 QARM 的
M未知,而且目标是从完整 probability distribution 恢复完整 matching row set,因此问题和 repair objective 不同。【代码贡献】Add quantum counting (BHT) built on the existing Grover operator #47 新增 Quantum Counting,通过 phase estimation 估计
M。本 PR 利用当前 QARM domain 的
M/N上界,在 3+ item 情况下无需先估计M。因此两者与本 PR 技术相关,但不存在直接实现重复。
English Summary
This PR fixes a correctness defect in the current QARM implementation that can produce impossible support values and incorrect association rules on valid transaction datasets.
data2.txt, bread appears in 7 of 10 transactions, so its exact support is0.7; before the fix QARM can recover 57 states and report5.7.milk -> breadis reported as1.00instead of the exact0.80.M-independent amplification schedule that can over-rotate dense marked sets. For the current two-index-register QARM circuit, oddtfollowsk=(t-1)/2effective Grover rotations.M/N <= 1/4, sot=3provides marked/unmarked probability separation without first estimatingM. The two-item domain uses exact classical row recovery becauseM/Ncan reach1/2.29 passed. A separate deterministic 35-dataset validation produced zero F1, frequent-itemset or pair-rule mismatches against an exact classical reference.full_amplitudecompatibility was reviewed from the source path but was not live-tested with credentials. Higher-order consequent enumeration in_get_all_conf()remains a separate pre-existing limitation.