将常见问题转换为qubo/ising形式的包

qubovert的Python项目详细描述


Travis-CIDocumentation Status

请看RepositoryDocs

将常见问题转换为Qubo形式。

到目前为止,我们刚刚实现了[Lucas]中的一些公式。qubovert的目标是成为一个映射到qubo和ising形式的大量问题集合,以帮助最近由于量子优化算法而增加对这些问题的研究。我希望有很多人参与,这样我们就可以汇编所有这些问题!

若要参与,请分叉存储库,添加您的贡献,然后提交请求。为您添加的任何功能添加测试。确保在提交任何内容之前运行python -m pytestpython -m pytest --codestyle--ignore=docs(是的,即使是测试也需要通过代码样式检查)和python -m pydocstyle convention=numpy qubovert,以确保生成通过。当您将更改推送到主分支时,travis ci将自动检查是否所有测试都通过。注意,所有问题都应该从qubovert.utils.Problem类派生!确保所有docstring都遵循numpydoc标准格式。

使用python的help函数!我对所有函数和类都有非常描述性的doc字符串。

安装

pip install qubovert

从源安装:

git clone https://github.com/jiosue/qubovert.git
cd QUBOVert
pip install -e .

然后您可以在python中使用它

importqubovert# get infohelp(qubovert)# see all the problems specifiedprint(qubovert.__all__)# or equivalentlyprint(qubovert.problems.__all__)# see the utilities definedhelp(qubovert.utils)print(qubovert.utils.__all__)# to see specifically the np problems:help(qubovert.problems.np)print(qubovert.problems.np.__all__)# to see specifically the benchmarking problems:help(qubovert.problems.benchmarking)print(qubovert.problems.benchmarking.__all__)# etc ...

请参阅下面的封面示例。所有其他问题都可以以类似的方式使用。

fromqubovertimportSetCoverfromany_moduleimportqubo_solver# or you can use my bruteforce solver...# from qubovert.utils import solve_qubo_bruteforce as qubo_solverU={"a","b","c","d"}V=[{"a","b"},{"a","c"},{"c","d"}]problem=SetCover(U,V)Q,offset=problem.to_qubo()obj,sol=qubo_solver(Q)obj+=offsetsolution=problem.convert_solution(sol)print(solution)# will print {0, 2}print(problem.is_solution_valid(solution))# will print True, since V[0] + V[2] covers all of Uprint(obj==len(solution))# will print True

改用伊辛公式:

fromqubovertimportSetCoverfromany_moduleimportising_solver# or you can use my bruteforce solver...# from qubovert.utils import solve_ising_bruteforce as ising_solverU={"a","b","c","d"}V=[{"a","b"},{"a","c"},{"c","d"}]problem=SetCover(U,V)h,J,offset=problem.to_ising()obj,sol=ising_solver(h,J)obj+=offsetsolution=problem.convert_solution(sol)print(solution)# will print {0, 2}print(problem.is_solution_valid(solution))# will print True, since V[0] + V[2] covers all of Uprint(obj==len(solution))# will print True

要查看问题的详细信息,请运行

help(qubovert.SetCover)help(qubovert.VertexCover)# etc

我有非常描述性的doc字符串,可以解释使用每个问题类需要知道的所有内容。

转换的技术细节

对于他提到的日志技巧,我们通常需要像sum(x) >= 1这样的约束。为了实施这个约束,我们在形式1 - sum(x) + sum(x[i] x[j] for i in range(len(x)) for j in range(i+1, len(x)))的qubo中添加了一个惩罚(这个想法来自[Glover])。

参考文献

[Lucas]Andrew Lucas. Ising formulations of many np problems. Frontiers in Physics, 2:5, 2014.
[Glover]Fred Glover, Gary Kochenberger, and Yu Du. A tutorial on formulating and using qubo models. arXiv:1811.11538v5, 2019.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Jboss LinkageError:加载程序约束冲突:解析重写的方法时   java Struts 1:如何使用表单bean设置<html:multibox/>值?   使用Fortify将字段设置为Null时的Java Null取消引用   用java对连接字符的图像进行分割   java无法使用Quarkus模拟,NullPointer异常,无法找到相关导入   html试图使iframe垫片与Java小程序上的CSS下拉菜单一起工作   java无法获取Base64。decodeBase64正常工作(Commons编解码器)   java为什么我不能通过点击打开jar文件?   java当用户第一次使用预先填充的sqlite数据库时,安卓应用程序如何添加新的列或表?   在tomcat中安装java GoDaddy SSL证书。。。没有与私钥匹配的证书   java试图实现一些伪代码、算法   java如何读取其他按钮id,避免所有转到第一个按钮   java使用单个   oop为什么Java Map不扩展集合?