common.title

100 Qubit QAOA Tutorial

Yuichiro Minato 21 days ago

I will try to do QAOA with a large number of qubits. I haven't finished implementing it as a tool yet, so I'll try to implement it from scratch. First, bring the library and blueqat up to date.

pip install --no-deps -U git+https://github.com/jcmgray/quimb.git@develop autoray blueqat
Collecting git+https://github.com/jcmgray/quimb.git@develop

  Cloning https://github.com/jcmgray/quimb.git (to revision develop) to /tmp/pip-req-build-re4i9utl

  Running command git clone -q https://github.com/jcmgray/quimb.git /tmp/pip-req-build-re4i9utl

Requirement already satisfied: autoray in /opt/conda/lib/python3.8/site-packages (0.3.1)

Requirement already satisfied: blueqat in /opt/conda/lib/python3.8/site-packages (1.0.0)

Note: you may need to restart the kernel to use updated packages.

First Load the tool.

import numpy as np import scipy.optimize as optimize from blueqat import Circuit from blueqat.pauli import qubo_bit as q

Quantum bits should be 100.

N = 100

Next, put the social problem you want to solve into QUBO format. This time, make the adjacency join a loop.

hamiltonian = 0 for i in range(N): hamiltonian += np.random.rand()*q(i) hamiltonian += np.random.rand()*q(i)*q((i+1)%N)

From here on, it's just a matter of working through the process of changing QUBO to a time evolution operator. blueqat has such a function.

time_evolutions = [ term.get_time_evolution() for term in hamiltonian ]

This time we will use a simple X Hamiltonian as the mixer. We prepare the initial state as a superposition and then apply the time evolution of QUBO. Finally, we multiply the transverse magnetic field term by RX, which is the time evolution. p=1 QAOA has two angles to be optimized, one for the beta and one for the gamma. In this case we will optimize the beta/gamma.

We calculate the expectation value directly in the tensor network.

def f(params): c = Circuit(N).h[:] beta = params[0] gamma = params[1] for evo in time_evolutions: evo(c, gamma) c.rx(beta)[:] return c.run(backend="quimb", hamiltonian=hamiltonian)

Initially choose a random angle and use scipy to optimize the beta/gamma to minimize the expectation value.

initial_guess = [np.random.rand()*2*np.pi for _ in range(2)] result = optimize.minimize(f, initial_guess)

When the optimization is complete, you are done. 100 qubits, so it takes a crazy amount of time.

if result.success: fitted_params = result.x print(fitted_params) else: raise ValueError(result.message)
[5.38861753 3.15076607]

I would like to sample with optimized parameters.

c = Circuit(N).h[:] beta = fitted_params[0] gamma = fitted_params[1] for evo in time_evolutions: evo(c, gamma) c.rx(beta)[:] c.run(backend="quimb", shots=100)
Counter({'1010010010110100101010100110111110010010000111001001011011111100101110001001100011101011001111101011': 1,

         '0010000100101010100000111100101000101001111010110010011001111110100101001110101100011101001101010011': 1,

         '0011010000110010010001001110110110001010101100111000100100100010101000101110101000011110101010101011': 1,

         '1001010010110001001110010000110010010100000010101000101101001010011001001010101010101101111101001011': 1,

         '1101010010110001101001110101011110011101110111011000101010001000101000101110010001111101011001101001': 1,

         '0101001001000010101010101100110010010100101110110100101101000101101011010110000000010101010010100101': 1,

         '0010111010100100011010101101011011010100101011000010100011110001101000100101010101101100100101001001': 1,

         '1110110001001010100111001001101001001101001011001010111010110011100101001110101001110110110010100110': 1,

         '0101010001010111010010011001101011101000010110110101011001011100111010001101101110010101001001101011': 1,

         '0010101010101010010011110101101001001101010101001001010100100001000111110101110101101001001100100111': 1,

         '0100110010111100010011011010011110010100010100110100110101010011010010001110110100101101001011110101': 1,

         '0101010000110010010110011000110101001000101000110011111010101010011110110001101011101101000011011001': 1,

         '0010010001010001100100101111101011001010010100100111111010100111100110010101010011101100101110101011': 1,

         '1111110101010010011100101001110010011100101010010111110000110010100110001001110101101101010011011010': 1,

         '0010110100101100111000101101001000111100100011010011111011001010011101001111001001101011001001011010': 1,

         '1010010010101001011100101010011011001010101101000101011110101011011010101000101001111101101001100100': 1,

         '1110101000110001010001001010111010010111001110101000110101000110100101001101101101101011000011101011': 1,

         '0010110011000100011111110110100000010111101010110010001000100100001110000111101000011000101001101001': 1,

         '0100110001000000101000010110110011101101110111001011110101001001110011010010101010011011010011110101': 1,

         '0100110001000110000011000101111001111111110111010000110010010010011110001111100000011100110101100111': 1,

         '0101001011001000100010000010111001111111010110100100110100100110001010010110101001011011010011100101': 1,

         '0100110001001000011000101101011010011011110111010011010101001101100101110101011101011100111101111101': 1,

         '0110110101010100011000111100110101101010110011010010011010101001100010010010101101101011001001101011': 1,

         '1010010001000111100100110101011010100100110011010010011011001001011010010110110100101010111101101010': 1,

         '0010110010111111101001001101101010101111110100101111010101010010010010010101110101001011011001100111': 1,

         '0101010000111100100100011110110001111011110101010001000011011001001010100101101001110110101011000111': 1,

         '0111111010111011100010010110010101111001110111010011001100100110101010111110101101001101001101100101': 1,

         '1001010010110101011001001100110101110001010101000010010101111101001101101101101100100101101011100101': 1,

         '1001010101001010011100101101001010001100011011001010010110101110100111001101001000011100101011011000': 1,

         '1101011010100101010110101101011110101101001110100001011001001010001110101111011010111101011010101010': 1,

         '0010110100110100100100101110011000110010101101101011110100100101010101001110110001110101101011010101': 1,

         '1010010100101111101001001110111000010110101101000110001100110010011110110110110001110101000010101100': 1,

         '0110110001001100101110001101101110100111100110110000111010101110100101010101001101110100101001010111': 1,

         '1010110100101010011010110010011100010111000001010010011010001000100101101010010101011101001011101010': 1,

         '1010110100101011100101111000110101001101010101010011110101010010010010010110011111011001001001111000': 1,

         '1110111001011100011101110000110110101100101110101001010110100101100110101111101100101101011011010110': 1,

         '0100110101010010010100101101011111111001011010101001010100011000000110110110101001111101000011100101': 1,

         '0001110010111001101010111100111011101100010101000000101101001001100110111001010101101010101010100101': 1,

         '0110110100100100100110010101011101001101001110001000111101010010111100010101101100101100100100101011': 1,

         '1011001010111100101110010101001010111010101101000001010101010010100111010101001000010100101110110101': 1,

         '1001010001001100011100010101110001111100100101011000111010100101100100111010101101101100110111011111': 1,

         '1001101010101010100111010100110100010100100110110001011000100101010010001101101000010010110100110010': 1,

         '0010110001010010011110010110101000100101011010101010011010010100100100110101110100001000101110100001': 1,

         '1101011010110100100111100010110101001100111111000010011010100100110110101110100100011101010011010110': 1,

         '0101010011010010010000010001101011001010101011011000101100010010101001101110101101011100111011100111': 1,

         '1010110100110001011000101001110110101111111110100000101000110011111100101110101010010101010010100101': 1,

         '1010101001010001011010010101100101001101010000101001011100110010010011010101101101011101001110101011': 1,

         '1001001011001010110010101110100110101111001010101111010101010100101010101101110100011100101011100000': 1,

         '0110110011110010010101010110111001111011101011000011110100111100010101010110101101011101000011100111': 1,

         '1001010011011101000010011001011001001010010011101011110100100100111001101101010011101101101000111001': 1,

         '1011010001010010100001001110110100111010010101001000101101001001101111010000000100111100110011001001': 1,

         '1010110010110001011001111100101010101110000110101001011010001011011100110110101001011010101100101111': 1,

         '0110110101010100101100101101101101110010101111010111111010101111101000001111001011101101010011111011': 1,

         '0111110001011101011101010110100101111000011010101000111100010100101011010110101110011000100101101010': 1,

         '0100110010101000010000100101011010100101011011100000110011001100010010100110100100010101000010101011': 1,

         '0011010100111000101010100101110000001101100111011001011011101001010110101101010101011100111011110111': 1,

         '1010110000101000011010100100111001001010010100101110111010011110010100001001101001110100101101100100': 1,

         '1101001010110010111001110110101100110010010010101110011100100100010101101110101101001100011011100111': 1,

         '1010010010110010010001000011101001010111100111000101011110011001100101010101101100101100101011001100': 1,

         '0101010001001001101010010110101100001110010111011010011011111110010010010101001100001100101011101100': 1,

         '0100110011010010011111001101001110001010010101010011111010110010100010101100000100001011011100100100': 1,

         '1101011010111110010010010101111000101011110110011001011011001010101100100101101010011010101100100110': 1,

         '0110110010110011101010101010101100010100111011000100110100101110101001001101101011001010101011011001': 1,

         '1010110100110101100100101101111011110111110000011010011011110100100010010000011101011101001011101001': 1,

         '1010110010101100101110001101101010000010100111010011110100110101100110010001110000001101001011000101': 1,

         '1010101011001000100010010101101000001101010110100001001111111111100111010111100101110010111011011010': 1,

         '1101001100110010010111100110101000010100000110110100111001001000111110110101110101000100000011101010': 1,

         '1101010000101010111001000010101000001101010110111101011010010101011110010010101100001110110010110100': 1,

         '1100110010101011101111100110111111001011101111010011111011001110100011001110110111101011011101101011': 1,

         '1011110001010110000111001110100101100000101011010011110100110010010100101001110010011100010101100110': 1,

         '1011110100110011101000100101111001110001001110100100110101111111111010001110101000111100101001101100': 1,

         '1010101100110000100010010100101010010100011010110111010101111010011110101110101001001101010101001010': 1,

         '1000010001010100011010100101011001101010010111000010111011010100011110010101010001001100101101101010': 1,

         '1100101000111101100100110010111010010111000101100011111111101001100110101110010101110011001110111011': 1,

         '1001010101101010100010010101001001110100101101011000111010110010101010010110110000111010101001101000': 1,

         '1011110010111011100011001110101001100000110011001100010100101000100101110000000101011111011111110101': 1,

         '0101010011010010100110100100101010100101001100110011000011000100010101110010110001100101011100101011': 1,

         '0101000100111100100001001101010011111100110111010010000110011000101010101101010001111011011110100101': 1,

         '1100110010101100100000101010111101110001010101010010000100010011011011001100100100010010101110101011': 1,

         '1010110101011111101001001001110101111010010110010100110100010010001010110101110100011001001011101011': 1,

         '1100101101010010100000010110011001000001011010101010010101011101010101111101110000011101101001010110': 1,

         '1000001010111000010001011010111010010111111011011001111110110010101010101111011111110011011100101010': 1,

         '1001001011001110011111110101101101101001001011000011110100101010101010001000010001001010111101000001': 1,

         '0101000000101010011010010000101010101111100111000011010001111001100110010110010100010100111101100101': 1,

         '1001010000100010010000010001101100100100110100010001010101011100100110010101010111110100010101101101': 1,

         '0001011001001010100100101010101010010011111000110010011010111100000111101110110000100110110010110010': 1,

         '1010110011101000100111110111110110100101011010101110110100101100001010110011010011101100011011100101': 1,

         '0111110011001001110111001010101000010110010110100110011011010010101010110101011101011101011000101011': 1,

         '0110110010101000010010010001011001000001111011011001011010111101011110010001110001001010101011101011': 1,

         '1001001010100100011110001010101011110100101011010101000010100100000110101110101011001100101001011010': 1,

         '0111110100110011110010101110110110101111001101011000110101001100100110101111101101110100110011100111': 1,

         '1001010010101111101111010101010111110110011011011011111010110100100101110100001100111010101110101011': 1,

         '1010010001010010011010111101011000001010101110100110010101110100011010110010101001011101011111000110': 1,

         '1111001001010010010100110110101101111010010100110111011010100100001010101101011010101110101100101011': 1,

         '1100101010110010011001001001100010010100011000100111011001110010101010100110101001001100101011101010': 1,

         '0100111001010101011010101110101000100010101010100010111011001010101010101001101101001000110011011011': 1,

         '0101001100101000101110001101100001110010000011000001011000100111000101100110011111001101001000101101': 1,

         '1000010101010011100001000111011110010101010110101000100010101010010010010001101010001101011000100100': 1,

         '0010110011011011101000010101101001100101100011010001011000100101101011000101001101011101001101011001': 1,

         '1111010000111110111100110000111010010010101101010011111011000110010010110001011100101101100011000001': 1})

It is quite nice to be able to solve a fairly large problem. That's all.

Yuichiro Minato

@yuichiro_minato2

blueqat CEO/CTO

About us ©2022 Copyright © 2022 blueqat Inc. All rights reserved