将常见问题转换为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类com。太阳运动衫果心标题。内容类型的FormDataContentDisposition:multipart/formdata;   自底向上展开树展开中的java空指针异常   我的java程序怎么了?   路由53 AWS中的java,如何处理重复子域   java set springs固定语言环境解析器(用于i18n)运行时的默认语言环境   actionscript 3如何用JAVA解析flash cookies(.SOL文件)   java Android facebook LikeView   Discord Java Bot(带有Javacord库)无法在Raspberry上播放音乐   java在每行求和时遇到问题   Java泛型,将一个列表复制到另一个列表   从Eclipse调用Rest API时java连接超时   java开发一个敏捷的wallweb工具的想法   jakarta ee如何在java(ee)服务器上存储单个特定于设备的id   java将javascript文件包含到JSP文件   java如何使用Jackson来反序列化对象一侧的对象数组?   控制鼠标坐标在Java中不准确?   java如何在不运行方法的情况下模拟方法调用和返回值?   java如何使用zip4j加密zip文件   JSF中convertDateTime的java奇怪行为