【代码贡献】修复 QmRMR 星号导入报错、8 个无法运行的示例及文档中的过时接口 - #39
Open
CREVIOS wants to merge 1 commit into
Open
Conversation
Fixes the problems reported in OriginQ#38. pyqpanda_alg/QmRMR/__init__.py stored the class object in __all__ rather than its name, so `from pyqpanda_alg.QmRMR import *` raised TypeError: Item in pyqpanda_alg.QmRMR.__all__ must be str, not type Every other subpackage already uses strings. Eight of the eleven scripts under example/QAlgBase failed to run. Two causes: they imported pyqpanda_alg.QFinance, a package that no longer exists and whose contents are now QUBO, QCmp, QSVR and QSEncode; and they were still written against pyqpanda v2 (initQVM, qAlloc_many, prob_run_dict), which is not a dependency of this project. They are ported to pyqpanda3 and all eleven now run. testeg_QmRMR.py imported `all_code`, which does not exist; the module is QmRMR_core. Five docstring examples told the reader to use the removed pyqpanda v2 API (pq.QMachine, import pyqpanda as pq) in plugin.qft, plugin.QFT, plugin.bind_nonnegative_data, QSVM.quantum_kernel_svm and QAOA.qaoa. Copying them raised ModuleNotFoundError. They now use CPUQVM and QProg, and the three plugin examples import what they use. The parse_quantum_result_dict example called parse_quantum_result, which does not exist, and its select_max=2 output listed three entries instead of two. Grover.cir's example used QProg without importing it. The module docstrings of Grover/__init__.py and QmRMR/__init__.py both described "the QFinance module"; they now describe their own module. Six local variables were assigned but never read, in QAE, QKmeans, QSVD, QSVM and QUBO. Verification: 18 existing tests pass; docstring examples that execute cleanly go from 33/40 to 39/40 (the remaining one uses '...' continuation that the checker cannot parse, and is correct as written). Not addressed here: example/QAlgBase/testeg_QSVD.py does not finish within 300 s. This reproduces on an unmodified develop checkout, so it is pre-existing and left for a separate change.
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.
修复 #38 中报告的全部问题。
关联 Issue:#38、#13 | 参赛队伍:DU_Fanta
一、修复内容
1【Bug】
from pyqpanda_alg.QmRMR import *抛出 TypeError__all__中存放的是类对象而非名称字符串:修复前:
包内其余 12 个子模块本就使用字符串,此处为唯一例外。
2【Bug】
example/QAlgBase/中 8 个示例无法运行两类原因,逐个修复:
pyqpanda_alg.QFinance已不存在:内容已拆分为QUBO/QCmp/QSVR/QSEncode;initQVM、qAlloc_many、prob_run_dict),而本项目依赖为 pyqpanda3。testeg_QmRMR.py引用的all_code模块实际名为QmRMR_core。newtest.pytesteg_QUBO.pytesteg_QmRMR.pytesteg_class_qsvr.pytesteg_comparator.pytesteg_grover_markdata.pytesteg_t_spare.pyQmRMR/testeg_QmRMR.py11 个示例现全部可运行(
testeg_QSVD.py见下方说明)。3【文档】5 处示例使用已移除的 pyqpanda v2 接口
pq.QMachine(pq.QMachineType.CPU)/import pyqpanda as pq→CPUQVM()/QProg(),涉及plugin.qft、plugin.QFT、plugin.bind_nonnegative_data、QSVM.quantum_kernel_svm、QAOA.qaoa。plugin的三处示例同时补上了所需的 import,可直接复制运行。4【文档】
parse_quantum_result_dict示例调用不存在的函数parse_quantum_result→parse_quantum_result_dict(3 处)。另修正select_max=2的示例输出:原文档列出 3 个条目,实际返回 2 个。5【文档】
Grover.cir示例缺少QProg导入6【文档】两个模块 docstring 描述了错误的模块
Grover/__init__.py与QmRMR/__init__.py原均写作「The QFinance module provides...」,现改为各自模块的说明。7【清理】6 处已赋值但从未读取的局部变量
QAE、QKmeans、QSVD、QSVM(2 处)、QUBO。ruff check --select F841现无告警。二、验证
可正常执行的 docstring 示例从 33/40 提升到 39/40。剩余 1 处为
plugin.apply_QGate,其使用标准...续行,本身写法正确,仅是检查脚本无法解析。所有文件的 CRLF 行尾均保持不变,diff 中不含无关的行尾变动。
三、本 PR 未处理的问题
example/QAlgBase/testeg_QSVD.py运行超过 300 秒未结束。已在未修改的 develop 上复现,确认为既有问题,与本 PR 无关,留待单独处理。English summary
Fixes everything reported in #38:
pyqpanda_alg/QmRMR/__init__.pyput the class object in__all__instead of its name, sofrom pyqpanda_alg.QmRMR import *raisedTypeError.pyqpanda_alg.QFinancepackage, or were still written against pyqpanda v2, which is not a dependency. All are ported to pyqpanda3.pq.QMachine,import pyqpanda as pq) and raisedModuleNotFoundErrorwhen copied.parse_quantum_result_dict's example called a non-existentparse_quantum_result, and itsselect_max=2output showed three entries instead of two.Grover.cir's example usedQProgwithout importing it.Grover/__init__.pyandQmRMR/__init__.pyboth described "the QFinance module".ruff --select F841is now clean.18 existing tests still pass; executable docstring examples go from 33/40 to 39/40. CRLF line endings preserved throughout.
Not addressed:
testeg_QSVD.pyexceeds 300 s, which reproduces on unmodifieddevelopand is therefore pre-existing.