def drop_empty_moments(
    circuit: cirq.AbstractCircuit, *, context: cirq.TransformerContext | None = None
) -> cirq.Circuit:
    """Removes empty moments from a circuit.

    Args:
          circuit: Input circuit to transform.
          context: `cirq.TransformerContext` storing common configurable options for transformers.

    Returns:
          Copy of the transformed input circuit.
    """
    if context is None:
        context = transformer_api.TransformerContext()
    return transformer_primitives.map_moments(
        circuit.unfreeze(False),
        lambda m, _: m if m else [],
        deep=context.deep,
        tags_to_ignore=context.tags_to_ignore,
    )
Removes empty moments from a circuit.

    Args:
          circuit: Input circuit to transform.
          context: `cirq.TransformerContext` storing common configurable options for transformers.

    Returns:
          Copy of the transformed input circuit.
    
cirq-core/cirq/transformers/drop_empty_moments.py