def METHOD_NAME(groups: dict[Index, set[Element]]) -> dict[Index, set[Element]]:
    indices = set(groups.keys())
    expanded_groups: dict[Index, set[Element]] = defaultdict(set)
    for index, elements in groups.items():
        expanded_groups[index] |= elements
    with tqdm(desc="expanding groups", total=len(indices)) as progress_bar:
        while len(indices) > 0:
            target = indices.pop()
            candidates = indices.copy()
            for candidate in candidates:
                if candidate == target:
                    continue
                keys = set(target.keys()).intersection(candidate.keys())
                if not all(candidate[key] == target[key] for key in keys):
                    continue  # candidate is not compatible with target
                index = pmap({key: target[key] for key in keys})
                logger.debug(f"Merging {target} and {candidate} into {index}")
                target_elements = expanded_groups.pop(target)
                candidate_elements = expanded_groups.pop(candidate)
                expanded_groups[index] |= target_elements
                expanded_groups[index] |= candidate_elements
                indices.remove(candidate)
                indices.add(index)
                break
            progress_bar.update()
    return expanded_groups