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)[fuente]

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.

Ejemplo

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ámetros:

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

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

Return the underlying optimisation model.

Devuelve:

The Model instance passed at construction time.

Tipo del valor devuelto:

Model

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

Compute the cost from a FunctionalResult.

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

Parámetros:

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

Devuelve:

Cost value computed from the results.

Tipo del valor devuelto:

Number

Muestra:

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