> ## Documentation Index
> Fetch the complete documentation index at: https://dynex.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Simple BQM Sampling

> Basic example of sampling a Binary Quadratic Model

# Simple BQM Sampling

This example demonstrates the basic usage of Dynex SDK for sampling Binary Quadratic Models.

## Problem Setup

```python theme={null}
import dynex
import dimod

# Create a simple BQM
bqm = dimod.BinaryQuadraticModel(
    {0: 1.0, 1: -1.0},  # Linear coefficients
    {(0, 1): 0.5},      # Quadratic coefficients
    0.0,                # Offset
    'BINARY'
)
```

## CPU Sampling

```python theme={null}
from dynex import ComputeBackend, DynexConfig

# Configure for CPU backend
config = DynexConfig(compute_backend=ComputeBackend.CPU)

# Create model and sampler
model = dynex.BQM(bqm)
sampler = dynex.DynexSampler(model, config=config)

# Sample the problem
sampleset = sampler.sample(num_reads=100)

# Print results
print(f"Best solution: {sampleset.first.sample}")
print(f"Best energy: {sampleset.first.energy}")
```

## QPU Sampling

```python theme={null}
from dynex import QPUModel

# Configure for QPU backend
config = DynexConfig(
    compute_backend=ComputeBackend.QPU,
    qpu_model=QPUModel.APOLLO_RC1
)

sampler = dynex.DynexSampler(model, config=config)
sampleset = sampler.sample(num_reads=10, annealing_time=200)  # QPU: num_reads 1–100, annealing_time 10–1000

print(f"Quantum solution: {sampleset.first.sample}")
```

## Next Steps

* Try [BQM Usage Examples](/examples/basic/bqm-usage)
* Explore [Machine Learning Examples](/examples/ml/qrbm)
* Learn about [Configuration Options](/guides/configuration)
