Some checks are pending
Build wheels / build (ubuntu-latest, 3.11) (push) Waiting to run
Build wheels / build (ubuntu-latest, 3.12) (push) Waiting to run
Build wheels / build (ubuntu-latest, 3.13) (push) Waiting to run
Tests / check (push) Waiting to run
Tests / build (ubuntu-latest, 3.11) (push) Blocked by required conditions
Tests / build (ubuntu-latest, 3.12) (push) Blocked by required conditions
Tests / build (ubuntu-latest, 3.13) (push) Blocked by required conditions
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""Bond dimension sweep for 32-qubit variational circuit."""
|
|
import os
|
|
import sys
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
from benchmark_mps import make_circuit, run_qibojit, run_quimb_mps, compare, jit_cache_path, DATA_DIR
|
|
|
|
NQUBITS = 32
|
|
NLAYERS = 5
|
|
BOND_VALUES = [1, 8, 16, 32, 64, 128, 256]
|
|
SVD_CUTOFF = 1e-6
|
|
OPTIMIZER = "auto-hq"
|
|
|
|
if __name__ == "__main__":
|
|
cache_path = jit_cache_path("variational", NQUBITS, NLAYERS)
|
|
|
|
if os.path.exists(cache_path):
|
|
sv_ref = np.load(cache_path)
|
|
print(f"[qibojit] loaded from cache: {cache_path}\n")
|
|
else:
|
|
np.random.seed(42)
|
|
circuit_ref = make_circuit("variational", NQUBITS, NLAYERS)
|
|
sv_ref, t_ref = run_qibojit(circuit_ref)
|
|
np.save(cache_path, sv_ref)
|
|
print(f"[qibojit] time={t_ref:.4f}s (saved to {cache_path})\n")
|
|
|
|
print(f"{'bond':>6} {'time(s)':>10} {'fidelity':>12} {'l2_err':>10}")
|
|
print("-" * 46)
|
|
|
|
for bond in BOND_VALUES:
|
|
np.random.seed(42)
|
|
circuit_mps = make_circuit("variational", NQUBITS, NLAYERS)
|
|
try:
|
|
sv_mps, t_mps = run_quimb_mps(circuit_mps, bond, SVD_CUTOFF, OPTIMIZER)
|
|
fidelity, l2_err = compare(sv_ref, sv_mps)
|
|
print(f"{bond:>6} {t_mps:>10.4f} {fidelity:>12.8f} {l2_err:>10.2e}")
|
|
except Exception as e:
|
|
print(f"{bond:>6} FAILED: {e}")
|