CloudRuntime

class lightning.app.runners.cloud.CloudRuntime(app=None, entrypoint=None, start_server=True, host='http://127.0.0.1', port=7501, processes=<factory>, threads=<factory>, work_runners=<factory>, done=False, backend='cloud', env_vars=<factory>, secrets=<factory>, run_app_comment_commands=False, enable_basic_auth='')

Bases: Runtime

_api_create_cloudspace_if_not_exists(project_id, name, existing_cloudspace)

Create the cloudspace if it doesn’t exist.

Return the cloudspace ID.

Return type

str

_api_create_run(project_id, cloudspace_id, run_body)

Create and return the run.

Return type

V1LightningRun

_api_create_run_instance(cluster_id, project_id, run_name, cloudspace_id, run_id, desired_state, queue_server_type=None, env_vars=None, auth=None, source_app=None, keep_machines_after_stop=None)

Create a new instance of the given run with the given specification.

Return type

Externalv1LightningappInstance

static _api_package_and_upload_repo(repo, run)

Package and upload the provided local source code directory to the provided run.

Return type

None

_api_stop_existing_run_instance(project_id, existing_run_instance)

If an existing instance is provided and it isn’t stopped, stop it.

Return type

None

_api_transfer_run_instance(project_id, run_id, instance_id, desired_state, queue_server_type=None, env_vars=None, auth=None)

Transfer an existing instance to the given run ID and update its specification.

Return the instance.

Return type

Externalv1LightningappInstance

static _get_auth(credentials)

If credentials are provided, parse them and return the auth spec.

Return type

Optional[V1LightningAuth]

static _get_drives(work)

Get the list of drive specifications for the provided work.

Return type

List[V1LightningworkDrives]

static _get_env_vars(env_vars, secrets, run_app_comment_commands)

Generate the list of environment variable specs for the app, including variables set by the framework.

Return type

List[V1EnvVar]

_get_flow_servers()

Collect a spec for each flow that contains a frontend so that the backend knows for which flows it needs to start servers.

Return type

List[V1Flowserver]

static _get_mounts(work)

Get the list of mount specifications for the provided work.

Return type

List[V1LightningworkDrives]

static _get_network_configs(flow_servers)

Get the list of network configs for the run if multiple works in default container is enabled.

Return type

Optional[List[V1NetworkConfig]]

_get_run_body(cluster_id, flow_servers, network_configs, works, no_cache, root, start_server, should_mount_cloudspace_content=False, absolute_entrypoint=False)

Get the specification of the run creation request.

Return type

CloudspaceIdRunsBody

_get_works(cloudspace=None)

Get the list of work specs from the app.

Return type

List[V1Work]

static _print_specs(run_body, print_format)

Print the given run body in either web or gallery format.

Return type

None

_resolve_cloudspace(project_id, cloudspace_id)

Returns a cloudspace by project_id and cloudspace_id, if exists.

Return type

Optional[V1CloudSpace]

_resolve_cloudspace_name(cloudspace_name, existing_cloudspace, existing_cloudspaces)

If there are existing cloudspaces but not on the cluster - choose a randomised name.

Return type

str

_resolve_cluster_id(cluster_id, project_id, existing_cloudspaces)

If cloudspaces exist and cluster is None, mimic cluster selection logic to choose a default.

Return type

Optional[str]

_resolve_config(name, load=True)

Find and load the config file if it exists (otherwise create an empty config).

Override the name if provided.

Return type

AppConfig

_resolve_env_root()

Determine whether the root of environment sync files exists.

Return type

Optional[Path]

_resolve_existing_cloudspaces(project_id, cloudspace_name)

Lists all the cloudspaces with a name matching the provided cloudspace name.

Return type

List[V1CloudSpace]

_resolve_existing_run_instance(cluster_id, project_id, existing_cloudspaces)

Look for an existing run and instance from one of the provided cloudspaces on the provided cluster.

Return type

Tuple[Optional[V1CloudSpace], Optional[Externalv1LightningappInstance]]

static _resolve_needs_credits(project)

Check if the user likely needs credits to run the app with its hardware.

Returns False if user has 1 or more credits.

_resolve_open_ignore_functions()

Used by the open method.

If the entrypoint is a file, return an ignore function that will ignore everything except that file so only the file gets uploaded.

Return type

List[Callable[[Path, List[Path]], List[Path]]]

_resolve_project(project_id=None)

Determine the project to run on, choosing a default if multiple projects are found.

Return type

V1Membership

_resolve_queue_server_type()

Resolve the cloud queue type from the environment.

Return type

V1QueueServerType

_resolve_repo(root, ignore_functions=None, default_ignore=True, package_source=True, sys_customizations_root=None)

Gather and merge all lightningignores from the app children and create the LocalSourceCodeDir object.

Return type

LocalSourceCodeDir

_resolve_root()

Determine the root of the project.

Return type

Path

_resolve_run_instances_by_name(project_id, name)

Get all existing instances in the given project with the given name.

Return type

List[Externalv1LightningappInstance]

_resolve_run_name(name, existing_instances)

If there are existing instances with the same name - choose a randomised name.

Return type

str

_validate_cluster_id(cluster_id, project_id)

Check that the provided cluster exists and ensure that it is bound to the given project.

_validate_drives()

Check that all drives in the app have a valid protocol.

Return type

None

_validate_mounts()

Check that all mounts in the app have a valid protocol.

Return type

None

static _validate_repo(root, repo)

This method is used to inform the users if their folder files are large and how to filter them.

Return type

None

_validate_work_build_specs_and_compute()

Check that the cloud compute and build configs are valid for all works in the app.

Return type

None

cloudspace_dispatch(project_id, cloudspace_id, name, cluster_id, source_app=None, keep_machines_after_stop=None)

Slim dispatch for creating runs from a cloudspace. This dispatch avoids resolution of some properties such as the project and cluster IDs that are instead passed directly.

Parameters
  • project_id (str) – The ID of the project.

  • cloudspace_id (str) – The ID of the cloudspace.

  • name (str) – The name for the run.

  • cluster_id (str) – The ID of the cluster to run on.

  • source_app (Optional[str]) – Name of the source app that triggered the run.

  • keep_machines_after_stop (Optional[bool]) – If true, machines will be left running after the run is finished and reused after

Raises
  • ApiException – If there was an issue in the backend.

  • RuntimeError – If there are validation errors.

  • ValueError – If there are validation errors.

Return type

Externalv1LightningappInstance

Returns

The spec the created app instance.

dispatch(name='', cluster_id=None, open_ui=True, no_cache=False, **kwargs)

Method to dispatch and run the LightningApp in the cloud.

Return type

None

classmethod load_app_from_file(filepath, env_vars={})

Load a LightningApp from a file, mocking the imports.

Return type

LightningApp

open(name, cluster_id=None)

Method to open a CloudSpace with the root folder uploaded.