Skip to main content

Quantum annealing sampler using QuTiP sesolve

Project description

qutip-sampler

Tests codecov PyPI Python License: MIT

A dimod-compatible quantum annealing sampler backed by QuTiP sesolve.

It maps an Ising / QUBO problem onto a transverse-field Ising Hamiltonian, evolves the ground state via a linear annealing schedule, and draws bitstring samples from the final quantum state.

Installation

pip install qutip-sampler

Quick start

import dimod
from qutip_sampler import QuTipSampler

# SPIN (Ising) problem
bqm = dimod.BinaryQuadraticModel({'a': -1.0, 'b': -1.0}, {('a', 'b'): 0.5}, 0.0, 'SPIN')
result = QuTipSampler().sample(bqm, num_reads=100, seed=42)
print(result.first.sample)   # e.g. {'a': 1, 'b': 1}

# Ising directly
result = QuTipSampler().sample_ising({'a': -1.0}, {('a', 'b'): 0.5}, num_reads=50)

# QUBO
Q = {('x', 'x'): -1.0, ('y', 'y'): -1.0, ('x', 'y'): 0.5}
result = QuTipSampler().sample_qubo(Q, num_reads=50, seed=0)
print(result.first.sample)   # e.g. {'x': 1, 'y': 1}

Parameters

Parameter Default Description
anneal_time 10.0 Total annealing time T passed to sesolve
n_steps 200 Number of time steps in the annealing schedule
num_reads 100 Number of bitstring samples drawn from the final state
seed None RNG seed for reproducible sampling

anneal_time and n_steps can be set at construction time or overridden per call.

How it works

  1. Collect all variables from the problem and sort them.
  2. Build the Ising Hamiltonian H_ising = Σ hᵢ σᵢᶻ + Σ Jᵢⱼ σᵢᶻ σⱼᶻ.
  3. Build the transverse-field Hamiltonian H_T = −Σ σᵢˣ, whose ground state is |+⟩⊗ⁿ.
  4. Evolve H(t) = (1 − t/T) H_T + (t/T) H_ising from t=0 to t=T using QuTiP sesolve.
  5. Sample bitstrings from the probability distribution |ψ(T)|².

Release flow

Releases are fully automated via GitHub Actions:

  1. Every push / PR — the Tests workflow runs the test suite and uploads coverage to Codecov.
  2. On a version tag — the Publish workflow runs tests first, then builds and publishes to PyPI if they pass.

To cut a release:

uvx bump-my-version bump patch   # or minor / major
git push && git push --tags

bump-my-version updates the version in pyproject.toml, commits, and creates the tag. Pushing the tag triggers the publish workflow.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qutip_sampler-0.2.0.tar.gz (76.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qutip_sampler-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file qutip_sampler-0.2.0.tar.gz.

File metadata

  • Download URL: qutip_sampler-0.2.0.tar.gz
  • Upload date:
  • Size: 76.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for qutip_sampler-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2612071f1cbf8210b59ab13c58d54aa6b39f84d58f9feca7f53daf737ed439b0
MD5 41ed0bdcf8abe5bb328a1a6a2d8ccea1
BLAKE2b-256 c559ad052679a8d994c6e14f4a4179d7d280feb6408d8482c7d4cd4f4d505fa2

See more details on using hashes here.

File details

Details for the file qutip_sampler-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: qutip_sampler-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for qutip_sampler-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04de1ee48090e61e298280806b62e2c7c28165002101f77849b650e7245f7758
MD5 c5c2d342489b4ad9c7e282190f7ca749
BLAKE2b-256 4d4ddd320d2a806c13761fad9c505293ca7801976cd0ff301c3d68ffb85b5a19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page