group_coeff_means¶
- group_coeff_means(op)¶
Returns the mean absolute coefficient magnitude of each group.
The
i-th entry is the sum ofabs(coeff)over the terms in groupi, divided by the number of terms in that group. If the operator tracks no groups, this returnsNone.This is the sampling weight of a randomized product formula (for example, qDRIFT) that draws whole groups rather than individual terms: it is the magnitude of one atomic group, which is the relevant scale because grouping is what makes each sampled piece Hermitian (and hence its time evolution unitary) in the first place.
Computing it natively is considerably cheaper than reducing
get_coeffs()andgroupsin NumPy, because those two accessors each copy one value per ungrouped term out of the operator only for it to be aggregated back down to one value per group, whereas this returns just thenum_groups()reduced values.Note
A group index that no term carries weighs
0.0, which keeps it out of the sample.>>> from qiskit_fermions.operators import FermionOperator >>> from qiskit_fermions.operators.terms.grouping import group_coeff_means >>> op = FermionOperator( ... [1.0, 2.0, -1.0, -2.0], ... [True, False, True, False, True, False, True, False], ... [0, 1, 2, 3, 1, 0, 3, 2], ... [0, 2, 4, 6, 8], ... ) >>> print(group_coeff_means(op)) None >>> op.groups = [0, 1, 0, 1] >>> group_coeff_means(op) [1.0, 2.0]
- Parameters:
op – the operator whose groups to reduce.
- Returns:
The mean absolute coefficient magnitude of each group index, or
Noneif the operator tracks no groups.- Raises:
TypeError – if
opis not a supported operator type (seeOperatorTrait).