【代码贡献】修复 Grover 自适应搜索丢失同值最小解的问题 - #98
Open
youshen2025 wants to merge 1 commit into
Open
youshen2025 wants to merge 1 commit into
youshen2025 wants to merge 1 commit into
Conversation
This was referenced Sep 22, 2026
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.
队伍 youshen,关联本源杯任务 #13,目标分支
develop。问题与结果
GroverAdaptiveSearch.run()会丢失已实际测得的同值最小解:先将outcome加入
indexes_measured,随后在v == 0分支又要求它不在该列表中才保存结果,因此这个追加分支永远不会执行。
例如初值为 2,并确定性地测得目标值为 2 的状态,原实现返回
([], 2);先改进到 2、随后测得另一个目标值也为 2 的状态时,原实现只保留第一个状态。
修复后保存已测得、达到当前最小值的不同状态;发现更小值时仍替换旧解集。
未测到达到初始阈值的状态时继续返回空列表,不伪造一个解。
改动
minimum_indexes;核心行为仅一行修改。Test_grover_run.py替换为可执行的 16 项 CPU 回归。测试通过公开
init_circuit回调制备计算基态,以真实阈值相位 oracle、真实CPUQVM 运行和真实测量验证结果。该电路在 Grover 反射下只改变全局相位,因而
测量确定;没有 mock 模拟器或把经典答案替换成量子输出。随机迭代模式固定
NumPy 种子 7,测试后恢复随机状态。
覆盖初值已最优、多个同值解、先改进再同值、改进后清除旧解、负目标、常数目标、
重复样本去重、较差样本排除,以及没有达到初值的样本;两种迭代模式均验证。
验证
环境为 PyQPanda3 0.4.1 CPU;3.12/3.13 使用 NumPy 2.5.3、SciPy 1.18.1,
3.11 使用 NumPy 2.4.6、SciPy 1.17.1,并保留上游 15 条转义弃用警告。
这些是本地验证,尚无本 PR 远程 CI 结果。
在已安装项目及 pytest/pytest-timeout/allure-pytest 的项目
.venv中运行:范围与查重
2026-09-22 检索 GroverAdaptiveSearch / GAS / minimum_indexes,并核对现有
#9/#36 的实际 diff。它们涉及文档拼写、迭代次数和标记输入,未修改本次的
自适应搜索同值解记录分支。#97 修复 QUBO 结果位宽,属于另一条独立路径。
本分支从官方 develop
5f973ef创建,只有两个现有文件改动,没有混入应用或其他库修复。保留现有有限采样和浮点精确相等语义,不声称保证枚举全部最优解。
附加集成验证:独立本地 checkout 合并应用 #92 与 #95/#96/#97/#98 的当前
修复后,Python 3.11 / 3.12 / 3.13 各 242 项测试全部通过(26.28 / 29.41 /
25.09 s),应用覆盖率均为 98.92%。其他 PR 的改动没有加入本分支;这些是
本地兼容性证据,不代替上游审核或 CI。
合并交互检查:另在本地合并第三方开放 #45(f829357)、#69(6f0fcb2)、
#36(e1992fb),均自动合并无冲突;Python 3.12 的 264 项测试通过(37.15 s),
应用覆盖率 98.92%。该记录仅覆盖这些提交的本地兼容性;他人的代码不进入本 PR。