Using the PassManager
The PassManager executes transformation, analysis, control-flow passes, and pipelines in order.
Overview
PassManager:
- runs configured passes on a model
- returns a
TransformationOutput - exposes:
output.model(transformed model)output.record(replay/backward record)output.context(analysis context)
Basic usage
Python
from luna_model import Model, Vtype
from luna_model.transformation import PassManager
from luna_model.transformation.passes import IntegerToBinaryPass, BinarySpinPass
model = Model()
x = model.add_variable("x", vtype=Vtype.INTEGER, lower=0, upper=3)
model.objective = 2 * x
pm = PassManager([
IntegerToBinaryPass(),
BinarySpinPass(vtype=Vtype.SPIN),
])
output = pm.run(model)
print(output.model)
Accessing analyses and artifacts after execution
Python
from luna_model.transformation.passes import MaxBiasAnalysis
pm = PassManager([MaxBiasAnalysis()])
output = pm.run(model)
# typed analysis lookup via context
max_bias = output.context.require_analysis(MaxBiasAnalysis.key())
print(max_bias.val)
Backward mapping
Use the record returned by run to map a solution back to the original model space:
Python
# transformed_solution = solve(output.model)
# original_solution = output.record.backward(transformed_solution)
The old PassManager.backwards(...) helper is deprecated in favor of output.record.backward(...).
Adding passes
You can provide all passes up front or append later: