def __init__(
        self,
        terms: Mapping[TVector, cirq.TParamValComplex] | None = None,
        validator: Callable[[TVector], bool] | None = None,
    ) -> None:
        """Initializes linear combination from a collection of terms.

        Args:
            terms: Mapping of abstract vectors to coefficients in the linear
                combination being initialized.
            validator: Optional predicate that determines whether a vector is
                valid or not. Dictionary and linear algebra operations that
                would lead to the inclusion of an invalid vector into the
                combination raise ValueError exception. By default all vectors
                are valid.
        """
        self._has_validator = validator is not None
        self._is_valid = validator or (lambda x: True)
        self._terms: dict[TVector, cirq.TParamValComplex] = {}
        if terms is not None:
            self.update(terms)
Initializes linear combination from a collection of terms.

        Args:
            terms: Mapping of abstract vectors to coefficients in the linear
                combination being initialized.
            validator: Optional predicate that determines whether a vector is
                valid or not. Dictionary and linear algebra operations that
                would lead to the inclusion of an invalid vector into the
                combination raise ValueError exception. By default all vectors
                are valid.
        
cirq-core/cirq/value/linear_dict.py