Last time, I checked the operation of VQE using blueqat. This time, I will try to solve the virtual machine optimization problem (simplified version) with VQE of blueqat.
In a nutshell, it is a problem that requires ** "What kind of placement of virtual machines can be reasonably packed in a virtualization platform?" **. I'm calling it that way now, but is there an official name ...?
My daily work is to use VMware products to provide virtual machines in an on-premise environment and to operate and maintain the entire platform. The platform is a medium-scale platform of about 700VM. What I think about my business is, "Isn't it possible to free up a little more resources (especially CPU and memory) by devising the layout of virtual machines?"
I think that every infrastructure administrator is the same, but when providing a new virtual machine, isn't it particularly conscious of the following?
--Does the physical machine to be equipped with the virtual machine have spare resources?
This perspective is very important because overloading a single physical machine can affect the performance of the virtual machine. Also, as a platform administrator, when new requirements for creating a virtual machine come out, it is easy because you only have to check the remaining capacity of the current platform. But what about the following perspectives?
--Is the layout so that the resources of physical machines can be effectively used throughout the platform?
Thinking about placement from this perspective can be a daunting task. What is meant by "utilizing" here is whether virtual machines can be packed and placed without strain. Therefore, it is necessary to judge whether it is optimal as a whole, including the virtual machine currently running. Of course, this is not the case when load distribution functions such as DRS are enabled, but in my experience, many legacy companies do not rely on such functions and are managed by humans. And these optimizations as a whole can be considered not only for on-premise environment managers but also for cloud operators by replacing virtual machines with instances, etc., which is a very important element for operation management of huge infrastructure.
Assuming that there are 1000 virtual machines and 100 physical machines, the total number of combinations is 100000 (1000 x 100). Well, this is quite the case with classic computers, but if you become a cloud operator, this number will not be enough ...
If you suddenly pack too many things, you will get a flat tire, so gradually complicate the problem. This time, we will solve the problem under the following conditions.
--One physical machine --The only resource to be evaluated for deciding the placement is the CPU
I'm sorry to impose various conditions, but this time let me go with this.
Consider a state in which a virtual machine with the following required specifications is installed in a physical machine with 6 CPU cores (upper limit).
--VM0: 2 cores --VM1: 4 cores --VM2: 5 cores --VM3: 8 cores
When not considering overcommitment, what is the combination of virtual machines that can make the best use of the performance of physical machines? This time, we will not place virtual machines that exceed the CPU limit (6 cores) of physical machines. In the case of this problem setting, it is recommended that only VM0 and VM2 (2 cores + 4 cores = 6 cores) be placed.
This time Hamiltonian is as follows
H = -A\sum _{\alpha \in \rm{VM}}w_{\alpha}x_{\alpha} + B_{1}(W_{limit}-\sum _{\alpha \in \rm{VM}}w_{\alpha}x_{\alpha})^{2}
It is expressed by.
$ x_ {\ alpha} $ indicates whether the $ \ alpha $ th virtual machine is installed in the physical machine (1: installed, 0: not installed). And $ W_ {\ rm {limit}} $ represents the CPU limit of the physical machine (6 cores in this case), and $ w_ {\ alpha} $ represents the CPU resources required by the $ \ alpha $ th virtual machine. I am. Also, $ A $ and $ B_1 $ are parameters that express the weight of each term. If you are familiar with it, this problem is ** [Knapsack problem](https://ja.wikipedia.org/wiki/%E3%83%8A%E3%83%83%E3% Very similar to 83% 97% E3% 82% B5% E3% 83% 83% E3% 82% AF% E5% 95% 8F% E9% A1% 8C) **. However, unlike the normal knapsack problem, the "value" and "volume" are the same (CPU in this case).
Around this time, I wanted to do simple development on the iPad Pro, so I ran it on the Google Colaboratory.
First, install blueqat. Not required if you are using a local Jupyter notebook and have already installed it.
pip install blueqat
Library import
from blueqat.pauli import qubo_bit as q
from blueqat.vqe import Vqe, QaoaAnsatz
import numpy as np
Virtual machine definition class
class VirtualMachine():
def __init__(self, number, cost):
self.__number = number
self.__cost = cost
@property
def cost(self):
return self.__cost
Hamiltonian construction function
def create_Hamiltonian(CpuLimit, vms, params):
# first term of Hamiltonian
h1 = 0.0
for i in range(len(vms)):
h1 -= vms[i].cost * q(i)
# second term of Hamiltonian
h2 = 0.0
vmtotalCpu = 0.0
for j in range(len(vms)):
vmtotalCpu += vms[j].cost * q(j)
h2 = (CpuLimit - vmtotalCpu)**2
return params[0] * h1 + params[1] * h2
Main processing
#Physical Machine CPUlimit
CpuLimit = 6
#create Virtual Machine
vms = []
vms.append(VirtualMachine(number=0, cost=2))
vms.append(VirtualMachine(number=1, cost=4))
vms.append(VirtualMachine(number=2, cost=5))
vms.append(VirtualMachine(number=3, cost=8))
#Hyper Parameter(A=100)
Params =[1.0, 100.0]
#Create Hamiltonian
h = create_Hamiltonian(CpuLimit, vms, Params)
ansatz = QaoaAnsatz(h, 20)
runner = Vqe(ansatz)
result = runner.run()
print("mode:")
print(result.most_common(10))
mode:
(((1, 1, 0, 0), 0.7896332746515127), ((1, 0, 1, 0), 0.08187420835800963), ((0, 0, 1, 0), 0.0748323470871601), ((0, 1, 0, 0), 0.04708791984791466), ((0, 0, 0, 1), 0.005451806960418528), ((1, 0, 0, 1), 0.0005107132984061434), ((1, 1, 1, 0), 0.00015463766513252268), ((0, 1, 1, 0), 0.00014643503666132072), ((0, 0, 1, 1), 0.0001069655788835076), ((0, 0, 0, 0), 8.715493427846994e-05))
As for how to read the output, it is ((((solution combination 1, appearance probability of combination 1), (solution combination 2, appearance probability of combination 2), ...)). (The output order is the order with the highest probability of appearance) (1,1,0,0) indicates that VM0 and VM1 are placed, and the probability of appearance is 78%. It was a good result. However, in reality, the probability of occurrence of a solution changes each time it is executed, and the solution that is most likely to appear may also fluctuate. why···? This execution result is executed about 3 or 4 times and the best one is posted. If anyone knows the cause, please let me know.
Next, I would like to optimize when there are multiple physical machines. I wonder if I can do it well
Recommended Posts