Package: block-cascade
cascadeCascade is a library for submitting and managing jobs across multiple cloud environments. It is designed to integrate seamlessly into existing Prefect workflows or can be used as a standalone library.Getting StartedInstallationpoetryaddblock-cascadeorpip install block-cascadeExample Usagefromblock_cascadeimportremotefromblock_cascadeimportGcpEnvironmentConfig,GcpMachineConfig,GcpResourcemachine_config=GcpMachineConfig("n2-standard-4",1)environment_config=GcpEnvironmentConfig(project="example-project",region="us-west1",service_account=f"example-project@vertex.iam.gserviceaccount.com",image="us.gcr.io/example-project/cascade/cascade-test",network="projects/123986066123/global/networks/neteng-shared-vpc-prod")gcp_resource=GcpResource(chief=machine_config,environment=environment_config,)@remote(resource=gcp_resource)defaddition(a:int,b:int)->int:returna+bresult=addition(1,2)assertresult==3ConfigurationCascade supports defining different resource requirements via a configuration file titled either cascade.yaml or cascade.yml. This configuration file must be located in the working directory of the code execution to be discovered at runtime.calculate:type:GcpResourcechief:type:n1-standard-1You can even define a default configuration that can be overridden by specific tasks to eliminate redundant definitions.default:GcpResource:environment:project:example-projectservice_account:example-project@vertex.iam.gserviceaccount.comregion:us-central-1chief:type:n1-standard-4AuthorizationCascade requires authorization both to submit jobs to either GCP or Databricks and to stage picklied code to a cloud storage bucket. In the GCP example below, an authorization token is obtained via IAM by running the following command:gcloudauthlogin--update-adcNo additional configuration is required in your application's code to use this token.However, for authenticating to Databricks and AWS you will need to provide a token and secret key respectively. These can be passed directly to theDatabricksResourceobject or set as environment variables. The following example shows how to provide these values in the configuration file.Persistent Resources in GCPCascade supports creating persistent resources in GCP. These resources can be reused across multiple tasks and will persist until deleted manually by the user. This can be useful for debugging tasks that involve large images that take a long time to be loaded onto a node or for reserving scarce resources like A100 GPUs.You can create a persistent resource using thecascadeCLI and suppling acascade.ymlwith a configuration block that contains apersistent_resource_idfield. This field will be used to identify the persistent resource when submitting tasks to it. It is recommended that you use the configuration file to define the resource as well as the tasks that will be submitted to it. This will ensure that the resource specified for your task is compatible with the shape of the persistent resource.persistent-resource:type:GcpResourceenvironment:project:example-projectservice_account:example-project@example-project.iam.gserviceaccount.comregion:us-west1image:us.gcr.io/example-project/cascade/block-cascadechief:type:n1-standard-4persistent_resource_id:my-persistent-resourcecreate the persistent resourcecascadecreate-persistent-resource--configpersistent-resourceYou can then submit cascade tasks to this persistent resourcefromblock_cascadeimportremote@remote(config_name="persistent-resource",job_name="hello-world")deftest_job():print("Hello World")test_job()Don't forget to delete the persistent resource when you are done with itcascadedelete-persistent-resource-imy-persistent-resourceNote: persistent resource ids can not be reused. If you delete a persistent resource, you will need to create a new one with a different id.For DevelopersUsing hermit for managing PythonWhen developing cascade, you can optionally usehermitto manage the Python executable used by cascade. Together with using poetry to manage dependencies, this will ensure that your development environment is identical to other contributors. Follow the linked instructions for installing hermit and then you can create a virtualenv with Python@3.9 by running:. ./bin/activate-hermitThen, install the dependencies with poetry:poetry install