Skip to content

Handling Optimization Formats

With aqmodels you can define your optimization problem in a uniform way so that you can switch between standard optimization formats and access various solvers.

Solvers and algorithms often support specific optimization formats, and not all formats are compatible with every solver. To bridge this gap, LunaSolve provides a robust format translation feature. This allows you to use solvers even if they don’t natively support the format your problem is defined in.

For example, you can upload a problem in QUBO format and run it with a solver that expects LP—LunaSolve will automatically handle the conversion for you. This flexibility is powerful, but keep in mind that translations may impact solver performance, especially if the original problem was tailored to a specific format.

Translate Optimization Formats into Aqmodels

With Translators in aqmodels you can easily convert your QUBO, LP, BQM or CQM into a unified Model.

from pathlib import Path
from luna_quantum import LpTranslator

lp_file = Path("path/to/your_model.lp")
model = LpTranslator.to_aq(lp_file)
from luna_quantum import LpTranslator

lp_string = """
Maximize
obj: 3 x + 4 y
Subject To
c1: 2 x + y <= 100
c2: x + 2 y <= 80
Bounds
0 <= x <= 40
0 <= y <= 30
End
"""

model = LpTranslator.to_aq(lp_string)
import numpy as np
from luna_quantum import MatrixTranslator, Vtype

q = np.array([[1.0, -1.0],
            [-1.0, 2.0]])

model = MatrixTranslator.to_aq(q, name="qubo_model", vtype=Vtype.Binary)
import dimod
from luna_quantum import BqmTranslator

# Generate a random BQM with 5 variables and 10 interactions
bqm = dimod.generators.gnm_random_bqm(5, 10, "BINARY")

# Convert it into a Model
model = BqmTranslator.to_aq(bqm, name="bqm_model")
from luna_quantum import CqmTranslator

cqm = ...

model = CqmTranslator.to_aq(cqm, name="cqm_model")