BqmTranslator ¶
Utility class for converting between dimod.BinaryQuadraticModel (BQM) and symbolic models.
BqmTranslator
provides methods to:
- Convert a BQM into a symbolic Model
- Convert a Model
(with quadratic objective) into a BQM
These conversions are especially useful when interacting with external solvers or libraries that operate on BQMs.
Examples:
>>> import dimod
>>> import numpy as np
>>> from luna_quantum import BqmTranslator, Vtype
>>> bqm = dimod.generators.gnm_random_bqm(5, 10, "BINARY")
Create a model from a matrix:
Convert it back to a dense matrix:
from_aq
staticmethod
¶
from_aq(model: Model) -> BinaryQuadraticModel
Convert a symbolic model to a dense QUBO matrix representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
The symbolic model to convert. The objective must be quadratic-only and unconstrained. |
required |
Returns:
Type | Description |
---|---|
BinaryQuadraticModel
|
The resulting BQM. |
Raises:
Type | Description |
---|---|
TranslationError
|
Generally if the translation fails. Might be specified by one of the four following errors. |
ModelNotQuadraticError
|
If the objective contains higher-order (non-quadratic) terms. |
ModelNotUnconstrainedError
|
If the model contains any constraints. |
ModelSenseNotMinimizeError
|
If the model's optimization sense is 'maximize'. |
ModelVtypeError
|
If the model contains different vtypes or vtypes other than binary and spin. |