Cluster Classes and Testing Implementation #656
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves GlacioHack/xdem#681.
Overview
This PR introduces a set of classes designed to handle the execution of tasks in either a basic or a multi-processing cluster. It also includes a series of tests that verify the correct behavior of the cluster functionalities.
Key changes
ClusterGenerator
: A factory class that decides which type of cluster to create based on the given configuration (basic
ormultiprocessing
). It can initialize aBasicCluster
orMpCluster
with a specified number of worker processes.AbstractCluster
: The base class for bothBasicCluster
andMpCluster
. It defines methods to launch tasks, retrieve results, and manage resources such as opening and closing the cluster.BasicCluster
: A subclass ofAbstractCluster
where tasks are run synchronously (i.e., in a single process). The launch_task method simply executes the provided function immediately.MpCluster
: A subclass ofAbstractCluster
that utilizes Python’smultiprocessing
module for parallel task execution. The cluster pool is initialized with a defined number of worker processes, and tasks are executed asynchronously usingapply_async
. The results of tasks can be retrieved via theget_res
method.Test Suite
TestClusterGenerator
: A test suite implemented withpytest
to validate the functionality of the cluster system.test_basic_cluster
: Verifies that tasks are executed synchronously in theBasicCluster
.test_mp_cluster_task
: Confirms that tasks are launched asynchronously in theMpCluster
.test_mp_cluster_parallelism
: Tests that multiple tasks can be executed concurrently with multiple workers inMpCluster
.test_mp_cluster_termination
: Ensures that the cluster terminates correctly and no tasks can be launched after termination.