← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Johnnie Gray (Caltech) and the quimb community

A 50-qubit tensor network simulation with quimb

SoftwareSimulationLicence: Apache-2.0Version: 1.15.05.7 KB

Official source: jcmgray/quimb

Download ZIP (free)

A tested example that simulates a 50-qubit GHZ circuit, whose full state vector would take 18 petabytes, in seconds on a laptop using tensor networks (MPS).

What is quimb?

quimb is an open-source quantum information and tensor network library developed by Johnnie Gray. It represents large quantum systems as a network of small, connected tensors, without storing the whole state vector.

Why does it matter?

Simulating n qubits exactly on a classical computer needs 2ⁿ complex numbers: 30 qubits take about 16 GB and 50 qubits about 18 petabytes. But in many circuits the entanglement between qubits is limited. An MPS (matrix product state) uses this structure to keep memory proportional to the amount of entanglement.

The example in this package

mps_50_kubit.py builds the 50-qubit GHZ state (all 0 or all 1).

When running it you may see a warning that the kahypar package was not found. It is harmless for this small example.

When is it not enough?

As entanglement grows, the bond dimension grows exponentially. In random, deep circuits tensor networks get stuck too; the debate around Google's 2019 "quantum supremacy" experiment is about exactly this limit.

Next steps

  1. Set N to 200; the time and memory hardly change.
  2. Add random rx rotations on every qubit and layers of neighbouring CNOTs; watch how max_bond() grows.

Installation and running

pip install quimb
python mps_50_kubit.py

Tested with: quimb 1.15.0, Python 3.12.

Official source

Links

Package contents

Licence

The example code and the guide in this package were written by the Quantum Store editors and are MIT licensed. The project it uses is subject to its own licence (Apache-2.0).


Quantum Store — https://hakanerdogan.com/en

Example code

The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.

mps_50_kubit.py

"""quimb ile 50 kübitlik GHZ durumu: tensör ağıyla (MPS) devasa devreyi dizüstünde simüle et.

Çalıştırma:
    pip install quimb
    python mps_50_kubit.py
"""

import quimb.tensor as qtn

N = 50

# Tam durum vektörü 2**50 karmaşık sayı = yaklaşık 18 petabayt olurdu.
# MPS (matris çarpım durumu) yalnızca kübitler arasındaki dolanıklık kadar bellek kullanır.
devre = qtn.CircuitMPS(N)
devre.h(0)
for i in range(N - 1):
    devre.cx(i, i + 1)

tam_bellek_pb = (2**N) * 16 / 1e15
bag = devre.psi.max_bond()
print(f"Kübit sayısı: {N}")
print(f"Tam durum vektörü için gereken bellek: ~{tam_bellek_pb:,.0f} PB")
print(f"MPS'teki en büyük bağ boyutu: {bag} (dolanıklığın ölçüsü)")

sifirlar = complex(devre.amplitude("0" * N))
birler = complex(devre.amplitude("1" * N))
karisik = complex(devre.amplitude("01" * (N // 2)))
print(f"|00…0⟩ genliği: {sifirlar.real:.4f}")
print(f"|11…1⟩ genliği: {birler.real:.4f}")
print(f"|0101…⟩ genliği: {abs(karisik):.4f}")

ornekler = list(devre.sample(6, seed=5))
for o in ornekler:
    print("ölçüm:", o)

assert bag == 2, bag
assert abs(sifirlar - 2**-0.5) < 1e-9 and abs(birler - 2**-0.5) < 1e-9
assert abs(karisik) < 1e-9
assert all(o in ("0" * N, "1" * N) for o in ornekler), ornekler
print("Tamam: 50 kübit ya hep 0 ya hep 1; bunu birkaç kilobaytla hesapladık.")

← All packages

Share: X · LinkedIn