common.title

Docs
Quantum Circuit
TYTAN CLOUD

QUANTUM GAMING


autoQAOA
Desktop RAG

Overview
Terms of service

Privacy policy

Contact
Research

Sign in
Sign up
common.title

QUBO annealing with MPS on Mac + Torch Tytan / macのMPS + Torch TytanでQUBOアニーリング

Yuichiro Minato

2024/02/19 15:46

In a previous announcement, I mentioned creating a tool that performs QUBO annealing on a GPU using PyTorch, and the benchmarks were very promising. This time, I'll introduce GPU computing using MPS through PyTorch for Macs that do not have NVIDIA GPUs. For reference, the previous article discussed...

https://blueqat.com/yuichiro_minato2/e09f3c90-f004-49bf-b50a-2e8e5e73f39b

以前PyTorchを使ってGPUでのQUBOアニーリングを実行するツールを作ったとアナウンスしました。ベンチマークも大変いい感じです。今回はMac向けにNVIDIA GPUを積んでいない場合でも、PyTorch経由でMPSを使ったGPU計算を紹介します。ちなみに以前の記事は、

https://blueqat.com/yuichiro_minato2/ffdbc078-5258-47ce-a45c-e84bb03982f5

In the current code, MPS did not work as is (though it's probable that this article will be used as a basis for corrections in the future). Essentially, Torch tensors need to be explicitly set to float32. This was achieved by specifying float32 in the following section of the ArminSampler.

現在のコードではMPSはそのままでは動きませんでした。(おそらく今後この記事をベースに修正されると思いますが。)基本的には、Torchテンソルをfloat32にする必要があります。該当箇所はArminSamplerの下記部分でfloat32を明示的に指示すればOKでした。

qmatrix = torch.tensor(qmatrix, dtype=torch.float32, device=self.device).float()

dtype=torch.float32

So finally we get,

最終的には、

from tytan.tytan import *
import random
import time

N = 5000

qubits

q = symbols_list(N, 'q{}')

hamiltonian

H = 0

biases

for i in range(N):
  H += random.randint(-10, 10) * q[i]

Jij but set 1000 as it takes a long time to finish if we set all of connections

for i in range(1000):
  H += random.choice([-1, 1]) * q[random.randint(0,N-1)] * q[random.randint(0,N-1)]

compile

qubo, offset = Compile(H).get_qubo()

sampler

solver = sampler.ArminSampler(seed=None, mode='GPU', device='cuda:0', verbose=1)

start = time.time()

#sampling
result = solver.run(qubo, shots=1)

print(time.time() - start)

It felt like a difference only began to emerge around 5000 qubits, similar to what you'd expect with NVIDIA GPUs.

NVIDIAのGPUと同様に5000量子ビットでようやく差が出るような感じでした。

MODE: GPU
DEVICE: mps:0
54.36705923080444

solver = sampler.ArminSampler(seed=None, mode='CPU', verbose=1)

start = time.time()
result = solver.run(qubo, shots=1)
print(time.time() - start)

MODE: CPU
DEVICE: cpu
105.90340304374695

It nicely achieved acceleration with MPS as well.

いい感じでMPSでも高速化ができましたね。

© 2025, blueqat Inc. All rights reserved