iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📈

Thinking about Matrix Product States (11) — Calculating a 50-Qubit Entangled State without NumPy

に公開

Purpose

In Thinking about Matrix Product States (9) — Entangled States of 100 Qubits, I observed the entangled states of a Matrix Product State (MPS) with a large number of qubits. In such MPS simulations of qubit counts, how much would performance be affected if I replaced NumPy with the self-made library I created in Creating a NumPy-like library (1)? I'm going to verify this somewhat trivial point.

That said, for this occasion, I will verify with 50 qubits due to a very uninteresting implementation detail. I created an implementation limit where only up to 50 indices can be used for contraction calculations; I figured that since I rarely use more than that anyway, I'd leave it as is for now even if I could extend it.

MPS-based Quantum Circuit Simulator

I will use a library version of the TT_SVD_Vidal and other implementations prepared in Thinking about Matrix Product States (10) — Calculating Expectation Values for 50 Qubits. This is managed at https://github.com/derwind/ttz. Also, I have replaced NumPy in a specific branch.
As a downside of this, calculations involving complex matrices like Rx(\theta) can no longer be executed. Since Ry(\theta) uses real matrices, it feels like a simple quantum binary classifier could be implemented, though I haven't tried it yet.

Creating an Entangled State with MPS + NumPy-like

I used Google Colab.

%%bash

pip install -qU "git+https://github.com/derwind/mynumpy.git@0.7"
pip install -qU "git+https://github.com/derwind/ttz.git@0.2a0.dev0"
pip uninstall -y numpy

You can install the branch with all the various implementations using the commands above. I'll uninstall NumPy just to be sure.

Found existing installation: numpy 1.25.2
Uninstalling numpy-1.25.2:
Successfully uninstalled numpy-1.25.2

With this,

! pip list | grep numpy

mynumpy 0.7

It's now in a state where only my self-made library is visible.

Creating an Entangled State and Calculating Probability Amplitudes

Run the following simulation to calculate the probability amplitudes for \ket{0}^{\otimes 50} and \ket{1}^{\otimes 50}. If the sum of the squares of their absolute values is 1, then the coefficients of the other computational bases are 0.

%%time

from ttz.mps import MPS


num_qubits = 50
mps = MPS(num_qubits)
mps.x(0)
mps.h(0)
for i in range(num_qubits - 1):
    mps.cx(i, i + 1)

amp_000 = mps.amplitude("0" * num_qubits).item()
amp_111 = mps.amplitude("1" * num_qubits).item()
print(amp_000, amp_111)

(0.7071067811865475+0j) (-0.7071067811865475+0j)
CPU times: user 176 ms, sys: 1.76 ms, total: 177 ms
Wall time: 179 ms

From this, it can be seen that:

\begin{align*} \ket{\psi} = \frac{1}{\sqrt{2}} \ket{0}^{\otimes 50} - \frac{1}{\sqrt{2}} \ket{1}^{\otimes 50} \end{align*}

I didn't expect the calculation to complete in 179 ms.
Thinking about it carefully, in this case, the amount of entanglement between MPS nodes is 2, and since it only involves performing small SVDs just under 50 times, it makes sense that the calculation doesn't take much time. However, I was surprised because I thought it might take a few seconds. This calculation is being done entirely in pure Python.

Summary

I performed the MPS simulation by linking my self-made tools out of pure curiosity, and I'm glad it worked better than expected. Actually, there was a bug in the SVD calculation for cases where multiple singular values in the singular value matrix were identical, which made it difficult for a while, but I was able to fix it by comparing it with the behavior in NumPy.

In any case, "seeing is believing," and there's much to learn from trying things out and seeing them for yourself.

GitHubで編集を提案

Discussion