CqmTranslator ¶
CQM to AQM translator.
Utility class for converting between dimod.BinaryQuadraticModel (CQM) and symbolic models.
CqmTranslator provides methods to: - Convert a CQM into a symbolic Model - Convert a Model (with quadratic objective) into a CQM
These conversions are especially useful when interacting with external solvers or libraries that operate on CQMs.
Examples:
>>> import dimod
>>> import numpy as np
>>> from luna_quantum.translator import CqmTranslator, 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) -> ConstrainedQuadraticModel
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 CQM. |
Raises:
| Type | Description |
|---|---|
TranslationError | If the translation fails for some reason. |
to_aq staticmethod ¶
to_aq(cqm: ConstrainedQuadraticModel) -> Model
Convert a CQM into a symbolic Model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cqm | ConstrainedQuadraticModel | The CQM. | required |
Returns:
| Type | Description |
|---|---|
Model | A symbolic model representing the given CQM. |
Raises:
| Type | Description |
|---|---|
TypeError | If |
TranslationError | If the translation fails for some reason. |