(
        sys_metrics,
        aggregate_window=20,
        max_num_clients=20,
        figsize=(25, 15),
        title_fontsize=16,
        max_name_len=10,
        range_rounds=None)
Plots the clients' local computations against round number.

    Args:
        sys_metrics: pd.DataFrame as written by writer.py.
        aggregate_window: Number of rounds that are aggregated. e.g. If set to 20, then
            rounds 0-19, 20-39, etc. will be added together.
        max_num_clients: Maximum number of clients to plot.
        figsize: Size of the plot as specified by plt.figure().
        title_fontsize: Font size for the plot's title.
        max_name_len: Maximum length for a client's id.
        range_rounds: Tuple representing the range of rounds to be plotted. The rounds
            are subsampled before aggregation. If None, all rounds are considered.
Plots the clients' local computations against round number.
Plots the clients local computations against round number .
def plot_client_computations_vs_round_number(
        sys_metrics,
        aggregate_window=20,
        max_num_clients=20,
        figsize=(25, 15),
        title_fontsize=16,
        max_name_len=10,
        range_rounds=None):
    """Plots the clients' local computations against round number.

    Args:
        sys_metrics: pd.DataFrame as written by writer.py.
        aggregate_window: Number of rounds that are aggregated. e.g. If set to 20, then
            rounds 0-19, 20-39, etc. will be added together.
        max_num_clients: Maximum number of clients to plot.
        figsize: Size of the plot as specified by plt.figure().
        title_fontsize: Font size for the plot's title.
        max_name_len: Maximum length for a client's id.
        range_rounds: Tuple representing the range of rounds to be plotted. The rounds
            are subsampled before aggregation. If None, all rounds are considered."""
    plt.figure(figsize=figsize)

    num_rounds = sys_metrics[NUM_ROUND_KEY].max()
    clients = sys_metrics[CLIENT_ID_KEY].unique()[:max_num_clients]

    comp_matrix = []
    matrix_keys = [c[:max_name_len] for c in clients]

    for c in clients:
        client_rows = sys_metrics.loc[sys_metrics[CLIENT_ID_KEY] == c]
        client_rows = client_rows.groupby(NUM_ROUND_KEY, as_index=False).sum()
        client_computations = [0 for _ in range(num_rounds)]

        for i in range(num_rounds):
            computation_row = client_rows.loc[client_rows[NUM_ROUND_KEY] == i]
            if not computation_row.empty:
                client_computations[i] = computation_row.iloc[0][LOCAL_COMPUTATIONS_KEY]
        comp_matrix.append(client_computations)

    if range_rounds:
        assert range_rounds[0] >= 0 and range_rounds[1] > 0
        assert range_rounds[0] <= range_rounds[1]
        assert range_rounds[0] < len(comp_matrix[0]) and range_rounds[1] < len(comp_matrix[0]) + 1
        assert range_rounds[1] - range_rounds[0] >= aggregate_window
        new_comp_matrix = []
        for i in range(len(comp_matrix)):
            new_comp_matrix.append(comp_matrix[i][range_rounds[0]:range_rounds[1]])
        comp_matrix = new_comp_matrix

    agg_comp_matrix = []
    for c_comp_vals in comp_matrix:
        num_rounds = len(c_comp_vals)
        agg_c_comp_vals = []
        for i in range(num_rounds // aggregate_window):
            agg_c_comp_vals.append(
                np.sum(c_comp_vals[i * aggregate_window:(i + 1) * aggregate_window]))
        agg_comp_matrix.append(agg_c_comp_vals)

    plt.title(
        'Total Client Computations (FLOPs) vs. Round Number (x %d)' % aggregate_window,
        fontsize=title_fontsize)
    im = plt.imshow(agg_comp_matrix)
    plt.yticks(range(len(matrix_keys)), matrix_keys)
    plt.colorbar(im, fraction=0.02, pad=0.01)
    plt.show()
def plot_client_computations_vs_round_number ( sys_metrics , aggregate_window = 20 , max_num_clients = 20 , figsize = ( 25 , 15 ) , title_fontsize = 16 , max_name_len = 10 , range_rounds = None ) : plt . figure ( figsize = figsize ) num_rounds = sys_metrics [ NUM_ROUND_KEY ] . max ( ) clients = sys_metrics [ CLIENT_ID_KEY ] . unique ( ) [ : max_num_clients ] comp_matrix = [ ] matrix_keys = [ c [ : max_name_len ] for c in clients ] for c in clients : client_rows = sys_metrics . loc [ sys_metrics [ CLIENT_ID_KEY ] == c ] client_rows = client_rows . groupby ( NUM_ROUND_KEY , as_index = False ) . sum ( ) client_computations = [ 0 for _ in range ( num_rounds ) ] for i in range ( num_rounds ) : computation_row = client_rows . loc [ client_rows [ NUM_ROUND_KEY ] == i ] if not computation_row . empty : client_computations [ i ] = computation_row . iloc [ 0 ] [ LOCAL_COMPUTATIONS_KEY ] comp_matrix . append ( client_computations ) if range_rounds : assert range_rounds [ 0 ] >= 0 and range_rounds [ 1 ] > 0 assert range_rounds [ 0 ] <= range_rounds [ 1 ] assert range_rounds [ 0 ] < len ( comp_matrix [ 0 ] ) and range_rounds [ 1 ] < len ( comp_matrix [ 0 ] ) + 1 assert range_rounds [ 1 ] - range_rounds [ 0 ] >= aggregate_window new_comp_matrix = [ ] for i in range ( len ( comp_matrix ) ) : new_comp_matrix . append ( comp_matrix [ i ] [ range_rounds [ 0 ] : range_rounds [ 1 ] ] ) comp_matrix = new_comp_matrix agg_comp_matrix = [ ] for c_comp_vals in comp_matrix : num_rounds = len ( c_comp_vals ) agg_c_comp_vals = [ ] for i in range ( num_rounds // aggregate_window ) : agg_c_comp_vals . append ( np . sum ( c_comp_vals [ i * aggregate_window : ( i + 1 ) * aggregate_window ] ) ) agg_comp_matrix . append ( agg_c_comp_vals ) plt . title ( 'Total Client Computations (FLOPs) vs. Round Number (x %d)' % aggregate_window , fontsize = title_fontsize ) im = plt . imshow ( agg_comp_matrix ) plt . yticks ( range ( len ( matrix_keys ) ) , matrix_keys ) plt . colorbar ( im , fraction = 0.02 , pad = 0.01 ) plt . show ( )