posted on 2023-05-07 21:05 read(1222) comment(0) like(2) collect(2)
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)
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:
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:
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.
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:
Enter the above statement, we can create a virtual environment wildqat, activate this virtual environment:
activate wildqat
The result is as follows:
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:
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:
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:
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.
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]
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.
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.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!