def _setup_outputs(root_output_dir, experiment_name, rounds_per_profile=0):
    'Set up directories for experiment loops, write hyperparameters to disk.'
    if (not experiment_name):
        raise ValueError('experiment_name must be specified.')
    create_if_not_exists(root_output_dir)
    checkpoint_dir = os.path.join(root_output_dir, 'checkpoints', experiment_name)
    create_if_not_exists(checkpoint_dir)
    checkpoint_mngr = tff.simulation.FileCheckpointManager(checkpoint_dir)
    results_dir = os.path.join(root_output_dir, 'results', experiment_name)
    create_if_not_exists(results_dir)
    csv_file = os.path.join(results_dir, 'experiment.metrics.csv')
    metrics_mngr = tff.simulation.CSVMetricsManager(csv_file)
    summary_logdir = os.path.join(root_output_dir, 'logdir', experiment_name)
    tb_mngr = tff.simulation.TensorBoardManager(summary_dir=summary_logdir)
    logging.info('Writing...')
    logging.info('    checkpoints to: %s', checkpoint_dir)
    logging.info('    metrics csv to: %s', metrics_mngr.metrics_filename)
    logging.info('    summaries to: %s', summary_logdir)

    @contextlib.contextmanager
    def profiler(round_num):
        if ((rounds_per_profile > 0) and ((round_num % rounds_per_profile) == 0)):
            with tf.profiler.experimental.Profile(summary_logdir):
                (yield)
        else:
            (yield)
    return (checkpoint_mngr, metrics_mngr, tb_mngr, profiler)
Set up directories for experiment loops, write hyperparameters to disk.
def _setup_outputs(root_output_dir, experiment_name, rounds_per_profile=0):
    
    if (not experiment_name):
        raise ValueError('experiment_name must be specified.')
    create_if_not_exists(root_output_dir)
    checkpoint_dir = os.path.join(root_output_dir, 'checkpoints', experiment_name)
    create_if_not_exists(checkpoint_dir)
    checkpoint_mngr = tff.simulation.FileCheckpointManager(checkpoint_dir)
    results_dir = os.path.join(root_output_dir, 'results', experiment_name)
    create_if_not_exists(results_dir)
    csv_file = os.path.join(results_dir, 'experiment.metrics.csv')
    metrics_mngr = tff.simulation.CSVMetricsManager(csv_file)
    summary_logdir = os.path.join(root_output_dir, 'logdir', experiment_name)
    tb_mngr = tff.simulation.TensorBoardManager(summary_dir=summary_logdir)
    logging.info('Writing...')
    logging.info('    checkpoints to: %s', checkpoint_dir)
    logging.info('    metrics csv to: %s', metrics_mngr.metrics_filename)
    logging.info('    summaries to: %s', summary_logdir)

    @contextlib.contextmanager
    def profiler(round_num):
        if ((rounds_per_profile > 0) and ((round_num % rounds_per_profile) == 0)):
            with tf.profiler.experimental.Profile(summary_logdir):
                (yield)
        else:
            (yield)
    return (checkpoint_mngr, metrics_mngr, tb_mngr, profiler)