def _parse_checkpoint_options(
    checkpoint: bool, checkpoint_fn: str | None, checkpoint_other_fn: str | None
) -> tuple[str | None, str | None]:
    """Parse the checkpoint-oriented options in `measure_grouped_settings`.

    This function contains the validation and defaults logic. Please see
    `measure_grouped_settings` for documentation on these args.

    Returns:
        checkpoint_fn, checkpoint_other_fn: Parsed or default filenames for primary and previous
            checkpoint files.

    Raises:
        ValueError: If a `checkpoint_fn` was specified, but `checkpoint` was False, if the
            `checkpoint_fn` is not of the form filename.json, or if `checkout_fn` and
            `checkpoint_other_fn` are the same filename.
    """
    if not checkpoint:
        if checkpoint_fn is not None or checkpoint_other_fn is not None:
            raise ValueError(
                "Checkpoint filenames were provided but `checkpoint` was set to False."
            )
        return None, None

    if checkpoint_fn is None:
        checkpoint_dir = tempfile.mkdtemp()
        chk_basename = 'observables'
        checkpoint_fn = f'{checkpoint_dir}/{chk_basename}.json'

    if checkpoint_other_fn is None:
        checkpoint_dir = os.path.dirname(checkpoint_fn)
        chk_basename = os.path.basename(checkpoint_fn)
        chk_basename, dot, ext = chk_basename.rpartition('.')
        if chk_basename == '' or dot != '.' or ext == '':
            raise ValueError(
                f"You specified `checkpoint_fn={checkpoint_fn!r}` which does not follow the "
                f"pattern of 'filename.extension'. Please follow this pattern or fully specify "
                f"`checkpoint_other_fn`."
            )

        if ext != 'json':
            raise ValueError(
                "Please use a `.json` filename or fully "
                "specify checkpoint_fn and checkpoint_other_fn"
            )
        if checkpoint_dir == '':
            checkpoint_other_fn = f'{chk_basename}.prev.json'
        else:
            checkpoint_other_fn = f'{checkpoint_dir}/{chk_basename}.prev.json'

    if checkpoint_fn == checkpoint_other_fn:
        raise ValueError(
            f"`checkpoint_fn` and `checkpoint_other_fn` were set to the same "
            f"filename: {checkpoint_fn}. Please use two different filenames."
        )

    return checkpoint_fn, checkpoint_other_fn
Parse the checkpoint-oriented options in `measure_grouped_settings`.

    This function contains the validation and defaults logic. Please see
    `measure_grouped_settings` for documentation on these args.

    Returns:
        checkpoint_fn, checkpoint_other_fn: Parsed or default filenames for primary and previous
            checkpoint files.

    Raises:
        ValueError: If a `checkpoint_fn` was specified, but `checkpoint` was False, if the
            `checkpoint_fn` is not of the form filename.json, or if `checkout_fn` and
            `checkpoint_other_fn` are the same filename.
    
cirq-core/cirq/work/observable_measurement.py