qilisdk.cost_functions.observable_cost_function
Classes
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)[fuente]
Bases:
qilisdk.cost_functions.cost_function.CostFunctionCompute costs by taking the expectation value of a quantum observable.
The observable can be supplied as a
QTensor, aHamiltonian, or aPauliOperator. It is stored internally as aQTensor.When a
FunctionalResult(from aDigitalPropagationorAnalogEvolution) is passed tocompute_cost(), the expectation value is computed either exactly from the final state or estimated from sampled probabilities.Ejemplo
from qilisdk.analog.hamiltonian import Z from qilisdk.cost_functions import ObservableCostFunction cost_fn = ObservableCostFunction(Z(0))Initialise an
ObservableCostFunction.- Parámetros:
observable (
QTensor | Hamiltonian | PauliOperator) – Quantum observable whose expectation value defines the cost.- Muestra:
ValueError – If the provided observable type is unsupported.
- property observable: qilisdk.core.qtensor.QTensor[fuente]
Return the observable in
QTensorform.- Devuelve:
The matrix representation of the observable.
- Tipo del valor devuelto:
- 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 (exact expectation value via
StateTomography), otherwise falls back to sampling-based estimation.- Parámetros:
results (
FunctionalResult) – The result from executing a functional.- Devuelve:
The expectation value of the observable.
- Tipo del valor devuelto:
Number
- Muestra:
ValueError – If
resultscontains neither aStateTomographynor aSamplingreadout.