qilisdk.cost_functions.model_cost_function

Classes

ModelCostFunction

Evaluate the cost of a FunctionalResult with respect to a Model.

Module Contents

class ModelCostFunction(model: qilisdk.core.model.Model)[font]

Bases: qilisdk.cost_functions.cost_function.CostFunction

Evaluate the cost of a FunctionalResult with respect to a Model.

The model encodes an objective function (and optional constraints) over binary variables. This cost function maps a FunctionalResult – obtained from a DigitalPropagation or AnalogEvolution – onto a scalar by evaluating the model against either the final quantum state or the sampled probability distribution.

Exemple

from qilisdk.core import BinaryVariable, Model, LEQ
from qilisdk.cost_functions import ModelCostFunction

model = Model("demo")
x0, x1 = BinaryVariable("x0"), BinaryVariable("x1")
model.set_objective(x0 + x1)
model.add_constraint("limit", LEQ(x0 + x1, 1))
cost_fn = ModelCostFunction(model)

Initialise a ModelCostFunction.

Paràmetres:

model (Model) – Classical model describing objective and constraints.

property model: qilisdk.core.model.Model[font]

Return the underlying optimisation model.

Retorna:

The Model instance passed at construction time.

Tipus de retorn:

Model

compute_cost(results: qilisdk.functionals.functional_result.FunctionalResult) qilisdk.core.types.Number[font]

Compute the cost from a FunctionalResult.

Uses the final state if available (via StateTomography), otherwise falls back to sampling-based estimation.

Paràmetres:

results (FunctionalResult) – The result from executing a functional.

Retorna:

Cost value computed from the results.

Tipus de retorn:

Number

Llença:

ValueError – If results contains neither a StateTomography nor a Sampling readout.