compute

Not agent-based computation functions for Neuroevolution fitting.

cneuromax.fitting.neuroevolution.utils.compute.compute_generation_results(generation_results, generation_results_batch, fitnesses_and_num_env_steps_batch, agents_batch, num_pops)[source]

Fills the generation_results array with results.

Extracts the fitnesses & number of environment steps from fitnesses_and_num_env_steps_batch, computes the pickled agent sizes and stores all of this information in generation_results.

Parameters:
  • generation_results (ndarray[Shape[Pop_size, Num_pops, [fitness, num_env_steps, serialized_agent_size]], dtype[float32]] | None) – An array maintained solely by the primary process (secondary processes have this variable set to None) containing several pieces of information about the results of a given generation. The 3rd dimension contains the following information at the following indices: 0) Agent fitness, 1) Number of environment steps taken by the agent during the evaluation, 2) Size of the agent when serialized.

  • generation_results_batch (ndarray[Shape[Len_agents_batch, Num_pops, [fitness, num_env_steps, serialized_agent_size]], dtype[float32]]) – A sub-array of generation_results maintained by the process calling this function.

  • fitnesses_and_num_env_steps_batch (ndarray[Shape[Len_agents_batch, Num_pops, [fitness, num_env_steps]], dtype[float32]]) – The output values of the evaluation performed in evaluate_on_cpu() or evaluate_on_gpu() on the agents maintained by the process calling this function.

  • agents_batch (list[list[BaseAgent]]) – A 2D list of agents maintained by the process calling this function.

  • num_pops (int) – See num_pops().

Return type:

None

cneuromax.fitting.neuroevolution.utils.compute.compute_save_points(output_dir, total_num_gens, save_interval, *, save_first_gen)[source]

Compute generations at which to save the state.

Parameters:
Return type:

tuple[int, list[int]]

Returns:

The largest previous number of generations and

a list of generations at which to save the state.

cneuromax.fitting.neuroevolution.utils.compute.compute_start_time_and_seeds(generation_results, curr_gen, num_pops, pop_size, *, pop_merge)[source]

Compute the start time and seeds for the current generation.

Fetches the start time and generates the seeds for the current generation. If pop_merge is True, the seeds are shared between the populations.

Parameters:
Return type:

tuple[float | None, ndarray[Shape[Pop_size, Num_pops], dtype[uint32]] | None]

Returns:

The start time for the current generation,

seeds.

cneuromax.fitting.neuroevolution.utils.compute.compute_total_num_env_steps_and_process_fitnesses(generation_results, total_num_env_steps, curr_gen, start_time, *, pop_merge)[source]

Processes the generation results.

Parameters:
Return type:

Optional[int]

Returns:

The updated total number of environment steps.