AbsoluteAverage
class AbsoluteAverage
Bases: qiskit.algorithms.linear_solvers.observables.linear_system_observable.LinearSystemObservable
The deprecated observable for the absolute average of a linear system of equations solution.
For a vector , the absolute average is defined as .
Examples:
import warnings
import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms.linear_solvers.observables.absolute_average import \
AbsoluteAverage
from qiskit.opflow import StateFn
with warnings.catch_warnings():
warnings.simplefilter('ignore')
observable = AbsoluteAverage()
vector = [1.0, -2.1, 3.2, -4.3]
init_state = vector / np.linalg.norm(vector)
num_qubits = int(np.log2(len(vector)))
qc = QuantumCircuit(num_qubits)
qc.isometry(init_state, list(range(num_qubits)), None)
qc.append(observable.observable_circuit(num_qubits), list(range(num_qubits)))
# Observable operator
observable_op = observable.observable(num_qubits)
state_vec = (~StateFn(observable_op) @ StateFn(qc)).eval()
# Obtain result
result = observable.post_processing(state_vec, num_qubits)
# Obtain analytical evaluation
exact = observable.evaluate_classically(init_state)
Methods
evaluate_classically
AbsoluteAverage.evaluate_classically(solution)
Evaluates the given observable on the solution to the linear system.
Parameters
solution (Union
[array
, QuantumCircuit
]) – The solution to the system as a numpy array or the circuit that prepares it.
Return type
float
Returns
The value of the observable.
observable
AbsoluteAverage.observable(num_qubits)
The observable operator.
Parameters
num_qubits (int
) – The number of qubits on which the observable will be applied.
Return type
Union
[TensoredOp
, List
[TensoredOp
]]
Returns
The observable as a sum of Pauli strings.
observable_circuit
AbsoluteAverage.observable_circuit(num_qubits)
The circuit implementing the absolute average observable.
Parameters
num_qubits (int
) – The number of qubits on which the observable will be applied.
Return type
Union
[QuantumCircuit
, List
[QuantumCircuit
]]
Returns
The observable as a QuantumCircuit.
post_processing
AbsoluteAverage.post_processing(solution, num_qubits, scaling=1)
Evaluates the absolute average on the solution to the linear system.
Parameters
- solution (
Union
[float
,List
[float
]]) – The probability calculated from the circuit and the observable. - num_qubits (
int
) – The number of qubits where the observable was applied. - scaling (
float
) – Scaling of the solution.
Return type
float
Returns
The value of the absolute average.
Raises
ValueError – If the input is not in the correct format.