Package: covalent-ecs-plugin
Covalent ECS PluginCovalent is a Pythonic workflow tool used to execute tasks on advanced computing hardware. This executor plugin interfaces Covalent with AWSElastic Container Service (ECS)where the tasks are run using Fargate.1. InstallationTo use this plugin with Covalent, install it usingpip:pipinstallcovalent-ecs-plugin2. Usage ExampleThis is an example of how a workflow can be constructed to use the AWS ECS executor. In the example, we train a Support Vector Machine (SVM) and use an instance of the executor to execute thetrain_svmelectron. Note that we also requireDepsPipwhich will be required to execute the electrons.fromnumpy.randomimportpermutationfromsklearnimportsvm,datasetsimportcovalentasctdeps_pip=ct.DepsPip(packages=["numpy==1.22.4","scikit-learn==1.1.2"])executor=ct.executor.ECSExecutor(s3_bucket_name="covalent-fargate-task-resources",ecs_cluster_name="covalent-fargate-cluster",ecs_task_execution_role_name="ecsTaskExecutionRole",ecs_task_role_name="CovalentFargateTaskRole",ecs_task_subnet_id="subnet-871545e1",ecs_task_security_group_id="sg-0043541a",ecs_task_log_group_name="covalent-fargate-task-logs",vcpu=1,memory=2,poll_freq=10,)# Use executor plugin to train our SVM model@ct.electron(executor=executor,deps_pip=deps_pip)deftrain_svm(data,C,gamma):X,y=dataclf=svm.SVC(C=C,gamma=gamma)clf.fit(X[90:],y[90:])returnclf@ct.electrondefload_data():iris=datasets.load_iris()perm=permutation(iris.target.size)iris.data=iris.data[perm]iris.target=iris.target[perm]returniris.data,iris.target@ct.electrondefscore_svm(data,clf):X_test,y_test=datareturnclf.score(X_test[:90],y_test[:90])@ct.latticedefrun_experiment(C=1.0,gamma=0.7):data=load_data()clf=train_svm(data=data,C=C,gamma=gamma)score=score_svm(data=data,clf=clf)returnscore# Dispatch the workflow.dispatch_id=ct.dispatch(run_experiment)(C=1.0,gamma=0.7)# Wait for our result and get result valueresult=ct.get_result(dispatch_id,wait=True).resultprint(result)During the execution of the workflow, one can navigate to the UI to see the status of the workflow. Once completed, the above script should also output a value with the score of our model.0.8666666666666667In order for the above workflow to run successfully, one has to provision the required cloud resources as mentioned in the sectionRequired AWS Resources.3. ConfigurationThere are many configuration options that can be passed into thect.executor.ECSExecutorclass or by modifying thecovalent config fileunder the section[executors.ecs]For more information about all of the possible configuration values, visit ourread the docs (RTD) guidefor this plugin.4. Required AWS ResourcesIn order for workflows to leverage this executor, users must ensure that all the necessary IAM permissions are properly setup and configured. This executor uses theS3,ECR, andECSservices to execute an electron, thus the required IAM roles and policies must be configured correctly. Precisely, the following resources are needed for the executor to run any dispatched electrons properly.ResourceConfig NameDescriptionIAM Roleecs_task_execution_role_nameThe IAM role used by the ECS agentIAM Roleecs_task_role_nameThe IAM role used by the container during runtimeS3 Buckets3_bucket_nameThe name of the S3 bucket where objects are storedECR repositoryecr_repo_nameThe name of the ECR repository where task images are storedECS Clusterecs_cluster_nameThe name of the ECS cluster on which your tasks are executedVPC Subnetecs_task_subnet_idThe ID of the subnet where instances are createdSecurity groupecs_task_security_group_idThe ID of the security group for task instancesCloudwatch log groupecs_task_log_group_nameThe name of the CloudWatch log group where container logs are storedCPUvCPUThe number of vCPUs available to a taskMemorymemoryThe memory (in GB) available to a taskGetting Started with CovalentFor more information on how to get started with Covalent, check out the projecthomepageand the officialdocumentation.Release NotesRelease notes are available in theChangelog.CitationPlease use the following citation in any publications:W. J. Cunningham, S. K. Radha, F. Hasan, J. Kanem, S. W. Neagle, and S. Sanand.Covalent.Zenodo, 2022.https://doi.org/10.5281/zenodo.5903364LicenseCovalent is licensed under the Apache License 2.0. See theLICENSEfile or contact thesupport teamfor more details.