# !pip install boto3

# !aws configure

"""
Explanation: <center><h2>Scale your pandas workflows by changing one line of code</h2>
Exercise 5: Setting up cluster environment
GOAL: Learn how to set up a cluster for Modin.
NOTE: This exercise has extra requirements. Read instructions carefully before attempting. 
This exercise instructs the user on how to start a 700+ core cluster, and it is not shut down until the end of Exercise 5. Read instructions carefully.
Often in practice we have a need to exceed the capabilities of a single machine. Modin works and performs well in both local mode and in a cluster environment. The key advantage of Modin is that your notebook does not change between local development and cluster execution. Users are not required to think about how many workers exist or how to distribute and partition their data; Modin handles all of this seamlessly and transparently.

Extra Requirements for this exercise
Detailed instructions can be found here:  https://docs.ray.io/en/latest/cluster/cloud.html
From command line:
- pip install boto3
- aws configure
- ray up modin-cluster.yaml
Included in this directory is a file named modin-cluster.yaml. We will use this to start the cluster.
End of explanation
"""


# !ray up modin-cluster.yaml

"""
Explanation: Starting and connecting to the cluster
This example starts 1 head node (m5.24xlarge) and 7 workers (m5.24xlarge), 768 total CPUs.
Cost of this cluster can be found here: https://aws.amazon.com/ec2/pricing/on-demand/.
End of explanation
"""


# !ray attach modin-cluster.yaml

# DO NOT CHANGE THIS CODE!
# Changing this code risks breaking further exercises

import time
time.sleep(600) # We need to give ray enough time to start up all the workers
import ray
ray.init(address="auto")
from modin.config import NPartitions
assert NPartitions.get() == 768, "Not all Ray nodes are started up yet"
ray.shutdown()

"""
Explanation: Connect to the cluster with ray attach
End of explanation
"""


