Deploying Swarms

After successfully connecting to the cluster, you can deploy swarms for execution on the nodes. The deployment process involves sending the swarm to the manager, registering it, and starting it.

The following is a step-by-step guide to deploying a swarm using the Cluster object.

  1. Initialize the Cluster: Connect to the Manta Manager by initializing the Cluster object with the appropriate host and port.

  2. Check Cluster Availability: Ensure that the cluster is available by using the is_available() method.

  3. Send the Swarm: Register your swarm with the manager using the send_swarm() method.

  4. Start the Swarm: Initiate the swarm’s execution using the start_swarm() method.

Example: Swarm Deployment and Execution

from manta import Cluster
from swarm import FLSwarm

# Initialize the Cluster object with the Manager's host and port
cluster = Cluster.connect(host="localhost", port=50051, ca_port=50050)

# Ensure the cluster is available
response = cluster.is_available()
print(response.message)  # Should print "Available"

# Define a Swarm object, e.g., a Federated Learning Swarm
swarm = FLSwarm()

# Send the Swarm to the Manager
swarm_response = cluster.send_swarm(swarm)
swarm_id = swarm_response.swarm_id
print(f"Swarm registered with ID: {swarm_id}")

# Start the Swarm
start_response = cluster.start_swarm(swarm_id)
print(start_response.message)  # Should confirm that the swarm has started

Explanation of key methods

  • Cluster Initialization: Connects to the Manta Manager at the specified host and port.

  • Swarm Deployment: The send_swarm() method registers the swarm with the manager. The returned swarm_id can be used to track the swarm’s status.

  • Swarm Execution: The start_swarm() method triggers the execution of the swarm on the connected nodes. The response indicates whether the swarm has started successfully.

Note

You can also use deploy_swarm instead of send_swarm and start_swarm to perform both actions with a single request.