qilisdk.cost_functions.observable_cost_function

Classes

ObservableCostFunction

Compute costs by taking the expectation value of a quantum observable.

Module Contents

class ObservableCostFunction(observable: qilisdk.core.qtensor.QTensor | qilisdk.analog.hamiltonian.Hamiltonian | qilisdk.analog.hamiltonian.PauliOperator)[source]

Bases: qilisdk.cost_functions.cost_function.CostFunction

Compute costs by taking the expectation value of a quantum observable.

The observable can be supplied as a QTensor, a Hamiltonian, or a PauliOperator. It is stored internally as a QTensor.

When a FunctionalResult (from a DigitalPropagation or AnalogEvolution) is passed to compute_cost(), the expectation value is computed either exactly from the final state or estimated from sampled probabilities.

Example

from qilisdk.analog.hamiltonian import Z
from qilisdk.cost_functions import ObservableCostFunction

cost_fn = ObservableCostFunction(Z(0))

Initialise an ObservableCostFunction.

Parameters:

observable (QTensor | Hamiltonian | PauliOperator) – Quantum observable whose expectation value defines the cost.

Raises:

ValueError – If the provided observable type is unsupported.

property observable: qilisdk.core.qtensor.QTensor[source]

Return the observable in QTensor form.

Returns:

The matrix representation of the observable.

Return type:

QTensor

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

Compute the cost from a FunctionalResult.

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

Parameters:

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

Returns:

The expectation value of the observable.

Return type:

Number

Raises:

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