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

QunaSys

VQE with QURI Parts: the Ising model

SoftwareQuantum algorithmsLicence: Apache-2.0Version: 0.27.08.9 KB

Official source: QunaSys/quri-sdk

Download ZIP (free)

VQE with the open-source QURI Parts library from Tokyo-based QunaSys: a tested example that compares the ground-state energy of a two-qubit transverse-field Ising model with the exact result.

What is QURI Parts?

QURI Parts is an open-source quantum algorithm library developed by the Tokyo-based company QunaSys. It offers parts such as circuits, operators, states and "estimators" as independent modules, so you can run the same algorithm unchanged on Qulacs, Qiskit or different hardware. Its source code now lives in the quri-parts folder of the QURI SDK repository.

When to use it

The example in this package

vqe_ising.py takes the two-qubit transverse-field Ising model

H = Z0 Z1 + 0.5 (X0 + X1)

and searches for the lowest energy by tuning a four-parameter circuit with SciPy's COBYLA optimiser, then compares the result with the exact eigenvalue of the matrix. In our test run both came out as −1.414214 (that is, −√2).

Next steps

  1. Change the coefficient 0.5 in the Hamiltonian and watch the phase transition.
  2. Increase the number of qubits to 4 and add another layer to the ansatz.
  3. Run the same code on the Qiskit simulator with quri-parts-qiskit.

Installation and running

pip install "quri-parts[qulacs]" scipy
python vqe_ising.py

Tested with: quri-parts 0.27.0, qulacs 0.6.14, 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.

vqe_ising.py

"""QURI Parts ile VQE: 2 kübitlik enine alanlı Ising modelinin taban enerjisini bul.

H = Z0 Z1 + 0.5 (X0 + X1)

Çalıştırma:
    pip install "quri-parts[qulacs]" scipy
    python vqe_ising.py
"""

import numpy as np
from scipy.optimize import minimize

from quri_parts.circuit import UnboundParametricQuantumCircuit
from quri_parts.core.operator import Operator, pauli_label
from quri_parts.core.state import ParametricCircuitQuantumState
from quri_parts.qulacs.estimator import create_qulacs_vector_parametric_estimator

hamiltonyen = Operator(
    {
        pauli_label("Z0 Z1"): 1.0,
        pauli_label("X0"): 0.5,
        pauli_label("X1"): 0.5,
    }
)

# Donanım verimli ansatz: her kübite RY, aralarında CNOT, tekrar RY.
ansatz = UnboundParametricQuantumCircuit(2)
ansatz.add_ParametricRY_gate(0)
ansatz.add_ParametricRY_gate(1)
ansatz.add_CNOT_gate(0, 1)
ansatz.add_ParametricRY_gate(0)
ansatz.add_ParametricRY_gate(1)

durum = ParametricCircuitQuantumState(2, ansatz)
tahminci = create_qulacs_vector_parametric_estimator()


def enerji(theta):
    return tahminci(hamiltonyen, durum, list(theta)).value.real


rng = np.random.default_rng(7)
sonuc = minimize(enerji, rng.uniform(0, np.pi, 4), method="COBYLA", options={"maxiter": 400})
print(f"VQE enerjisi : {sonuc.fun:.6f}")

# Karşılaştırma için 4x4 matrisi kesin olarak köşegenleştir.
I, X, Z = np.eye(2), np.array([[0, 1], [1, 0]]), np.diag([1, -1])
H = np.kron(Z, Z) + 0.5 * (np.kron(X, I) + np.kron(I, X))
kesin = np.linalg.eigvalsh(H)[0]
print(f"Kesin değer  : {kesin:.6f}")

assert abs(sonuc.fun - kesin) < 1e-3, (sonuc.fun, kesin)
print("Tamam: VQE taban enerjisini 0.001 hassasiyetle buldu.")

← All packages

Share: X · LinkedIn