News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

【建议收藏】基于python解决的QUBO计算库——wildqat的安装与求解

posted on 2023-05-07 21:05     read(1094)     comment(0)     like(2)     collect(2)


introduction

In the process of calculating QUBO to solve the minimum value of Hamiltonian operator H, the wildqat package needs to be used, and then the simulated annealing algorithm is called to calculate the result.

However, many problems will be encountered in the process of installing wildqat. This article will introduce the installation process of wildqat from the pits I have stepped on, and give a simple example.

In addition, I also updated how to calculate the QUBO expression based on python simulated annealing. The detailed code is attached. Friends who need it can learn about it
. code)

wildqat installation

In the process of installing wildqat, I first tried the installation using the conventional conda installation method, the code is as follows:

conda install wildqat

But the following error occurred:
insert image description here
This is a very common error, which probably means that the package was not found in conda.

So I tried to use the following code to install:

pip install wildqat

But I encountered the following problem:
insert image description here
Obviously, this is caused by our version error. Simply put, the numpy version does not meet the requirements, but pip will not help us configure the environment.

Solving installation problems

After searching for a long time, I found a solution. That is to create a new conda virtual environment, which must be an empty environment. Use the following code to create a new virtual environment:

conda create -n wildqat

The result is as follows:
insert image description here

Enter the above statement, we can create a virtual environment wildqat, activate this virtual environment:

activate wildqat

The result is as follows:
insert image description here

Then we need to use pip3 (make sure your python version is 3.X, and use the latest pip) to install wildqat version 1.1.9, as follows:

pip3 install wildqat==1.1.9

At this time, the second error will appear, and the error is as follows:
insert image description here
It probably means that matplotlib-3.0.0.tar.gz has not been found, so we need to pre-install matplotlib=3.0.0, so we continue to use conda to install matplotlib 3.0. 0 version, the code is as follows:

conda install matplotlib==3.0.0

The result is as follows:
insert image description here
After we have installed it, we can continue to execute the above installation code:

pip3 install wildqat==1.1.9

The result is as follows:
insert image description here
You can see an error message, which indicates that our numpy version is too low, but this is not important, we just need this library to run.

Use of wildqat

To use wildqat to calculate the results we need, we must first determine our QUBO calculation expression. Here we assume that our expression is:

[[1,2,3],
[1,2,3],
[1,2,3]]

Next, we need to create a new opt class and call sa to view its solution using the simulated annealing algorithm. The code is as follows:

import wildqat as wq
# 定义序列
list_value = [[1,2,3],
[1,2,3],
[1,2,3]]
# 创建opt类
wpt_new = wq.opt()
# 将我们的qubo赋值
wpt_new.qubo = list_value
print(wpt_new.sa())
# 得出结果
>>>[0,0,0]

conclusion

In this paper, the problems and solutions encountered in the process of configuring wildqat are described in detail, and the brief calculation process of QUBO is described.

I will continue to update the details of the use of more functions. If this article is helpful to you, I hope you can like, bookmark, and forward it.

If you have any questions, you can discuss with me in the comment area, and we will see you next time.



Category of website: technical article > Blog

Author:cindy

link:http://www.pythonblackhole.com/blog/article/384/e18352dbeb9054e5782f/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

2 0
collect article
collected

Comment content: (supports up to 255 characters)