5-OpenJij GPU¶
This document is deprecated. Please go to the next chapter.
In this section, we introduce a method of Simulated Quantum Annealing (SQA) with GPU.
Setup and installation in Google Colab¶
The average PC may not have a CUDA environment, or may not have an NVIDIA GPU. However, with Google colaboratory, anyone can use GPGPUs.
GPU Settings¶
We open Jupyter Notebook file we want to run on GPU with Google Colab.
Runtime > Change runtime type > choose Hardware accelerator GPU
This setting allows you to run Jupyter Notebook on GPU.
Installation of OpenJij¶
To use GPU modules from OpenJij, one has to build from source codes when installing OpenJij. We first update CMake, which is needed for the installation, to the latest version.
[ ]:
!pip install -U cmake
After that, we uninstall & reinstall OpenJij with option --no-binary :all:
, which forces to build from source codes during installation.
[ ]:
!pip uninstall openjij -y
!pip install openjij --no-binary :all: --no-cache-dir
Calculation with GPUSQA¶
[3]:
import openjij as oj
sampler = oj.GPUSQASampler(num_reads=100, unit_num_L=2)
unit_num_L
specifies the length of one side of the two-dimensional lattice of chimera-unit cells.Since a chimera-unit cell consists of one 8-bit, the total number of bits is calculated as follows.
\({\rm total\_num} = {\rm unit\_num\_L}^2 \times 8\)
The GPUSQASampler perform SQA calculations for the size of the system of chimeragraphs created here, even if you specify fewer variables, such as sampler_qubo, later. We note that unit_num_L
is not too large. Also, unit_num_L
is not specified in the constructor but is used as an argument to run sample_qubo
.
Execution¶
Next we execute SQA. As with Sampler before we introduce, we can use sample_qubo
(or sample_ising
). However, if you specify an interaction for a subscript that does not satisfy the chimeragraph, error occurs.
[4]:
Q = {(0, 4): -1, (0, 5): -1, (4, 12): 1}
response = sampler.sample_qubo(Q)
response
[4]:
Response(rec.array([([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1),
([1, 1, 1, 0], -2., 1), ([1, 1, 1, 0], -2., 1)],
dtype=[('sample', 'i1', (4,)), ('energy', '<f8'), ('num_occurrences', '<i8')]), [0, 4, 5, 12], {'system': [], 'sampling_time': 1006372.1469999792, 'execution_time': 8902.872740002294, 'list_exec_times': array([230796.36600005, 8290.07499999, 8871.43699998, 8162.024 ,
8042.78700002, 8098.51899999, 8169.03100002, 8717.89000001,
8071.55399997, 8079.75599997, 8075.238 , 6575.44399996,
6622.51900002, 6544.86100001, 6475.21600001, 6579.81400002,
6559.83600001, 6517.41999997, 6585.95900001, 6518.605 ,
6509.76200001, 6516.95900001, 6503.829 , 6554.55100002,
6598.15200004, 6559.86600003, 6580.816 , 6562.29000003,
6500.42199999, 6466.57100003, 6406.80800001, 6390.24500003,
6659.54599998, 6464.876 , 6436.83500004, 6504.48300001,
6446.07499999, 6446.44600004, 6454.87499997, 6475.223 ,
6496.00200001, 6466.11100001, 6495.32799997, 6542.35499997,
6453.81700002, 6432.13699999, 6491.07499999, 6461.52799999,
6558.50099997, 6534.26299999, 6422.665 , 6566.92900003,
6421.17799998, 6433.25700003, 6465.06299995, 6422.80899996,
6564.92299998, 6492.88800003, 6604.65999999, 6561.19299998,
6598.88999996, 6510.924 , 6470.13299999, 6447.51300001,
6428.63399997, 6432.77900002, 6463.92600004, 6585.03200003,
6444.74300003, 6514.35600003, 6400.51799996, 6425.93499998,
6458.08000002, 6452.91300003, 6434.88699995, 6418.80799998,
6496.19200004, 6432.80900005, 6431.72100001, 6411.84699998,
6447.61000001, 6426.49400004, 6448.77500002, 6412.73499997,
6453.15699995, 6386.89399995, 6430.19299997, 6480.221 ,
6432.088 , 6409.78600001, 6450.62400002, 6441.75000002,
6413.32800001, 6472.07700001, 6458.86699999, 6480.93900003,
6443.80400001, 6411.399 , 6422.54800005, 6423.68199999]), 'schedule': {'beta': 10.0, 'gamma': 1.0, 'num_sweeps': 100}}, 'BINARY')
Embedding the All-Coupled Model in Chimeragraph¶
We introduced the calculation of only those interactions that exist on the chimeragraph. Below is script for embedding comples interactions into chimeragraph, such as problems of all-coupled.
In order to embed in chimeragraph, we use EmbeddingComposite
of dwave
. We install dwave-system
with pip
.
[ ]:
!pip install dwave-system
Then we rewrite the sampler part of the script as follows.
[15]:
from dwave.system.composites import EmbeddingComposite
gpusqa = oj.GPUSQASampler(num_reads=100, unit_num_L=2)
sampler = EmbeddingComposite(gpusqa)