groups_have_uniform_coeffs¶
- groups_have_uniform_coeffs(op, *, atol=1e-08, abs=True)¶
Returns, for each group, whether all of its coefficients are numerically equal.
With
abs(the default), the coefficient magnitudes are compared, which is the assumption thatgroup_coeff_means()makes when it averagesabs(coeff). Without it, the coefficients must match exactly. Note that a Hermitian group may legitimately fail the stricter form, since a conjugate pair with complex coefficients has equal magnitudes but unequal coefficients. If the operator tracks no groups, this returnsNone.An empty or single-term group is trivially uniform.
Note
This is not a weaker form of
groups_are_hermitian(): neither implies the other. Uniform coefficients do not make a group Hermitian, and a Hermitian group can mix magnitudes.>>> from qiskit_fermions.operators import FermionOperator >>> from qiskit_fermions.operators.terms.grouping import groups_have_uniform_coeffs >>> op = FermionOperator.from_dict( ... { ... ((True, 0), (False, 1)): 1.0j, ... ((True, 1), (False, 0)): -1.0j, ... } ... ) >>> op.groups = [0, 0] >>> groups_have_uniform_coeffs(op) # equal magnitudes [True] >>> groups_have_uniform_coeffs(op, abs=False) # but not equal coefficients [False]
- Parameters:
op – the operator whose groups to check.
atol – The numerical accuracy upto which coefficients are considered equal. This value defaults to
1e-8.abs – Whether to compare coefficient magnitudes rather than the coefficients themselves. This value defaults to
True.
- Returns:
One flag per group index, or
Noneif the operator tracks no groups.- Raises:
TypeError – if
opis not a supported operator type (seeOperatorTrait).