D-Wave PyTorch Plugin
This plugin provides an interface between D-Wave’s quantum computers and the PyTorch framework, including neural network modules for building and training Boltzmann Machines along with various sampler utility functions.
Example
Boltzmann Machines are probabilistic generative models for high-dimensional binary data. The following example walks through a typical workflow for fitting Boltzmann Machines via maximum likelihood.
Define a Graph-Restricted Boltzmann Machine with a square graph
import torch
from torch.optim import SGD
from dwave.plugins.torch.models import GraphRestrictedBoltzmannMachine as GRBM
from dwave.plugins.torch.samplers import BlockSampler
grbm = GRBM(nodes=["a", "b", "c", "d"], edges=[("a", "b"), ("b", "c"), ("c", "d"), ("d", "a")])
print("Linear weights:", grbm.linear)
print("Quadratic weights:", grbm.quadratic)
Instantiate a block-Gibbs sampler. Variables “a” and “c” are in block 0; variables “b” and “d” are in block 1. The sampler consists of three parallel Markov chains of length ten each. Each Markov chain samples at a constant unit inverse temperature.
sampler = BlockSampler(grbm=grbm, colouring=lambda v: v in {"b", "d"}, num_chains=3, schedule=[1]*10)
Create a batch of data and perform one likelihood-optimization step
x_data = torch.tensor([[1, -1, 1, -1], [-1, 1, 1, 1]], dtype=torch.float32)
optimizer = SGD(grbm.parameters(), lr=1)
x_model = sampler.sample()
grbm.quasi_objective(x_data, x_model).backward()
optimizer.step()
print("Updated quadratic weights:", grbm.quadratic)
To use a dimod sampler, replace the sampler = BlockSampler(...) line with
from dwave.plugins.torch.samplers import DimodSampler
from dwave.samplers import RandomSampler
sampler = DimodSampler(grbm=grbm, sampler=RandomSampler(),
prefactor=1, sample_kwargs=dict(num_reads=5))
License
Released under the Apache License 2.0. See LICENSE file.
Metadata
Release files for dwave-pytorch-plugin 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dwave_pytorch_plugin-0.4.0.tar.gz | 71.0 kB | Without provenance | Details for dwave_pytorch_plugin-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dwave_pytorch_plugin-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for dwave_pytorch_plugin-0.4.0-py3-none-any.whl |
Total release size: 171.4 kB
Release files / dwave_pytorch_plugin-0.4.0.tar.gz
| Download URL | dwave_pytorch_plugin-0.4.0.tar.gz |
|---|---|
| Size | 71.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c73473e8ff79d7645cb002908e86d9ae44099ccbebe2f33ffe3dea60b0da8b69
|
|
BLAKE2b-256 checksum How to use checksums |
f5470b5535d6d00afc242267f1836d7b7270f1ee200d4d98081c78e3b9d5e878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / dwave_pytorch_plugin-0.4.0-py3-none-any.whl
| Download URL | dwave_pytorch_plugin-0.4.0-py3-none-any.whl |
|---|---|
| Size | 100.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37e0c8e0fe8c3a374bd197ae0371a3d2333a26009cfc1301257b57dd957bf3cd
|
|
BLAKE2b-256 checksum How to use checksums |
91f9ed88a9ef28ea910ce33bab5e76d7fc2e1613bedef6927c01869443dbda83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for dwave-pytorch-plugin 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.