qilisdk.cost_functions.model_cost_function
Classes
Evaluate the cost of a |
Module Contents
- class ModelCostFunction(model: qilisdk.core.model.Model)[font]
Bases:
qilisdk.cost_functions.cost_function.CostFunctionEvaluate the cost of a
FunctionalResultwith respect to aModel.The model encodes an objective function (and optional constraints) over binary variables. This cost function maps a
FunctionalResult– obtained from aDigitalPropagationorAnalogEvolution– 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.
- 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
resultscontains neither aStateTomographynor aSamplingreadout.