Skip to content

Luna 1.2.0

Luna 1.2.0

Breaking Changes

Luna 1.2.0 now uses the standalone luna-model package from PyPI. While the core modeling functionality remains the same, several API changes have been introduced to align with Python conventions and improve consistency.

Luna 1.2.0 introduces a significant architectural improvement by migrating to the public luna-model package on PyPI. This transition streamlines dependency management and provides access to enhanced modeling capabilities.


📋 Migration Guide

Enum Value Changes

All enumeration values now follow UPPER_CASE_WITH_UNDERSCORES naming convention (PEP 8 style for constants) instead of PascalCase:

Variable Types (Vtype)

Python
from luna_quantum import Vtype, Variable

x = Variable("x", vtype=Vtype.BINARY)
y = Variable("y", vtype=Vtype.SPIN)
z = Variable("z", vtype=Vtype.INTEGER)
w = Variable("w", vtype=Vtype.REAL)
Python
from luna_quantum import Vtype, Variable

x = Variable("x", vtype=Vtype.Binary)
y = Variable("y", vtype=Vtype.Spin)
z = Variable("z", vtype=Vtype.Integer)
w = Variable("w", vtype=Vtype.Real)

Optimization Sense

Python
from luna_quantum import Model, Sense

model = Model()
model.set_sense(Sense.MIN)  # or Sense.MAX
Python
from luna_quantum import Model, Sense

model = Model()
model.set_sense(Sense.Min)  # or Sense.Max

Constraint Comparators

Python
from luna_quantum import Comparator, Constraint

# Using comparators directly
c1 = Constraint(expr, 0.0, Comparator.EQ)
c2 = Constraint(expr, 1.0, Comparator.LE)
c3 = Constraint(expr, 2.0, Comparator.GE)
Python
from luna_quantum import Comparator, Constraint

# Using comparators directly
c1 = Constraint(expr, 0.0, Comparator.Eq)
c2 = Constraint(expr, 1.0, Comparator.Le)
c3 = Constraint(expr, 2.0, Comparator.Ge)

ConstraintCollection Indexing

ConstraintCollection can now only be indexed by constraint name, not by integer index.

Python
from luna_quantum import ConstraintCollection

constraints = ConstraintCollection()
constraints.add_constraint(c1, "constraint_1")
constraints.add_constraint(c2, "constraint_2")

# Only name-based indexing works
named = constraints["constraint_1"] # ✅ Name indexing only
# first = constraints[0]            # ❌ No longer supported

# Iterate using .items() instead
for name, constraint in constraints.items():
    print(f"{name}: {constraint}")
Python
from luna_quantum import ConstraintCollection

constraints = ConstraintCollection()
constraints.add_constraint(c1, "constraint_1")
constraints.add_constraint(c2, "constraint_2")

# Both indexing methods worked
first = constraints[0]              # ✅ Integer indexing
named = constraints["constraint_1"] # ✅ Name indexing

Translator Method Renaming

All translator methods have been renamed from to_aq/from_aq to to_lm/from_lm to reflect the migration to luna-model.

Affected Model translator classes (convert to/from Model):

  • QuboTranslator - QUBO matrix translator
  • LpTranslator - Linear Programming file translator
  • BqmTranslator - Binary Quadratic Model translator
  • CqmTranslator - Constrained Quadratic Model translator
Python
from luna_quantum.translator import QuboTranslator
import numpy as np

qubo_matrix = np.array([[4, -2], [-2, 5]])
model = translator.QuboTranslator.to_lm(qubo_matrix)
qubo = translator.QuboTranslator.from_lm(model)
Python
from luna_quantum.translator import LpTranslator

model = translator.LpTranslator.to_lm("problem.lp")
lp_string = translator.LpTranslator.from_lm(model)
Python
from luna_quantum.translator import BqmTranslator
import dimod

bqm = dimod.BinaryQuadraticModel(...)
model = BqmTranslator.to_lm(bqm)
bqm = BqmTranslator.from_lm(model)
Python
from luna_quantum.translator import CqmTranslator
import dimod

cqm = dimod.ConstrainedQuadraticModel(...)
model = CqmTranslator.to_lm(cqm)
cqm = CqmTranslator.from_lm(model)
Python
from luna_quantum.translator import QuboTranslator
import numpy as np

qubo_matrix = np.array([[4, -2], [-2, 5]])
model = translator.QuboTranslator.to_aq(qubo_matrix)
qubo = translator.QuboTranslator.from_aq(model)
Python
from luna_quantum.translator import LpTranslator

model = translator.LpTranslator.to_aq("problem.lp")
lp_string = translator.LpTranslator.from_aq(model)
Python
from luna_quantum.translator import BqmTranslator
import dimod

bqm = dimod.BinaryQuadraticModel(...)
model = BqmTranslator.to_aq(bqm)
bqm = BqmTranslator.from_aq(model)
Python
from luna_quantum.translator import CqmTranslator
import dimod

cqm = dimod.ConstrainedQuadraticModel(...)
model = CqmTranslator.to_aq(cqm)
cqm = CqmTranslator.from_aq(model)

Affected Solution translator classes (convert external results to Solution):

  • AwsTranslator - AWS Braket results translator
  • DwaveTranslator - D-Wave results translator
  • IbmTranslator - IBM Qiskit results translator
  • NumpyTranslator - NumPy arrays translator
  • QctrlTranslator - Q-CTRL results translator
  • ZibTranslator - ZIB solver results translator
Python
from luna_quantum.translator import AwsTranslator

sol = AwsTranslator.to_lm(...)
Python
from luna_quantum.translator import DwaveTranslator

sol = DwaveTranslator.to_lm(...)
Python
from luna_quantum.translator import IbmTranslator

sol = IbmTranslator.to_lm(...)
Python
from luna_quantum.translator import NumpyTranslator

sol = NumpyTranslator.to_lm(...)
Python
from luna_quantum.translator import QctrlTranslator

sol = QctrlTranslator.to_lm(...)
Python
from luna_quantum.translator import ZibTranslator

sol = ZibTranslator.to_lm(...)
Python
from luna_quantum.translator import AwsTranslator

sol = AwsTranslator.to_aq(...)
Python
from luna_quantum.translator import DwaveTranslator

sol = DwaveTranslator.to_aq(...)
Python
from luna_quantum.translator import IbmTranslator

sol = IbmTranslator.to_aq(...)
Python
from luna_quantum.translator import NumpyTranslator

sol = NumpyTranslator.to_aq(...)
Python
from luna_quantum.translator import QctrlTranslator

sol = QctrlTranslator.to_aq(...)
Python
from luna_quantum.translator import ZibTranslator

sol = ZibTranslator.to_aq(...)

In addition, you can now call the translation capa


🚀 New Features

New Quantum Backend, IBMQuantum, is now available for use with Luna.

The luna-model package provides enhanced capabilities:

  • Extended Expression Utilities Additional methods for working with expressions, including better iteration and inspection of terms.

  • Improved Type Safety Enhanced type hints and stub files (.pyi) for better IDE support and static type checking.

  • Performance Optimizations Various performance improvements in the modeling layer.


📝 Migration Checklist

When upgrading from luna-quantum < 1.2.0, update your code as follows:

  • Replace all enum values with UPPER_CASE_WITH_UNDERSCORES equivalents:
    • Vtype.BinaryVtype.BINARY
    • Vtype.SpinVtype.SPIN
    • Vtype.IntegerVtype.INTEGER
    • Vtype.RealVtype.REAL
    • Sense.MinSense.MIN
    • Sense.MaxSense.MAX
    • Comparator.EqComparator.EQ
    • Comparator.LeComparator.LE
    • Comparator.GeComparator.GE
  • Remove integer indexing from ConstraintCollection objects
  • Update to use .items() for iterating over constraints
  • Replace all to_aq() with to_lm() in translator classes
  • Replace all from_aq() with from_lm() in translator classes