All Sets

All Sets#

class rizemind.strategies.contribution.sampling.all_sets.AllSets[source]

Bases: SetsSamplingStrategy

Sampling strategy that generates all possible combinations of trainers.

This strategy implements exhaustive sampling by generating the complete power set of trainers for each round. It creates all 2^n possible combinations (coalitions) where n is the number of trainers, including the empty set which corresponds to the previous rounds best model.

The strategy maintains state for the current round and caches the generated sets and participant mapping. If called multiple times for the same round, it returns the cached results. When a new round is detected, it regenerates all sets.

trainer_mapping

Maps trainer addresses to integer indices for set IDs.

Type:

rizemind.strategies.contribution.shapley.trainer_mapping.ParticipantMapping

current_round

The round number for which sets have been generated.

Type:

int

sets

Dictionary mapping set IDs to TrainerSet objects for the current round.

Type:

dict[str, rizemind.strategies.contribution.shapley.trainer_set.TrainerSet]

current_round: int
get_set(round_id: int, id: str) TrainerSet[source]

Returns a specific trainer set by ID for the given round.

Parameters:
  • round_id – The round identifier to retrieve the set from.

  • id – The unique identifier of the trainer set, generated by the participant mapping based on the set’s members.

Returns:

The TrainerSet object with the specified ID.

Raises:
  • ValueError – If the round_id does not match the current round, or

  • if no trainer set with the given ID exists in the current round.

get_sets(round_id: int) list[TrainerSet][source]

Returns all trainer sets for the given round.

Parameters:

round_id – The round identifier to retrieve sets for.

Returns:

A list of all TrainerSet objects generated for the specified round.

Raises:

ValueError – If the round_id does not match the current round.

get_trainer_mapping(round_id: int) ParticipantMapping[source]

Returns the participant mapping for the specified round.

Parameters:

round_id – The round identifier to retrieve the mapping for.

Returns:

The ParticipantMapping object containing all trainer address mappings for the specified round.

Raises:
  • ValueError – If the round_id does not match the current round, indicating

  • that a new round needs to be processed via sample_trainer_sets.

sample_trainer_sets(server_round: int, results: list[tuple[ClientProxy, FitRes]]) list[TrainerSet][source]

Generates all possible combinations of trainers for the given round.

If this is a new round, the method: 1. Extracts all trainer addresses from the results 2. Creates a participant mapping for ID generation 3. Generates all 2^n possible combinations (power set) using itertools 4. Creates a TrainerSet for each combination with a unique ID

If called again for the same round, it returns cached results without regeneration.

Parameters:
  • server_round – The current server round number.

  • results – Training results containing client proxies and fit results.

Returns:

A list of all possible TrainerSet combinations, including the empty set. For n trainers, returns 2^n sets.

Raises:

ValueError – if server_round is less than the current round.

sets: dict[str, TrainerSet]
trainer_mapping: ParticipantMapping