Metadata-Version: 2.1
Name: covalent-gcpbatch-plugin
Version: 0.9.0rc0
Summary: Covalent GCP Batch Plugin
Home-page: https://github.com/AgnostiqHQ/covalent-gcpbatch-plugin
Download-URL: https://github.com/AgnostiqHQ/covalent-gcpbatch-plugin/archive/v0.9.0.tar.gz
Author: Agnostiq
Author-email: support@agnostiq.ai
Maintainer: Agnostiq
License: GNU Affero GPL v3.0
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Plugins
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: License :: Other/Proprietary License
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Adaptive Technologies
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
Classifier: Topic :: Software Development
Classifier: Topic :: System :: Distributed Computing
Description-Content-Type: text/markdown
License-File: LICENSE

&nbsp;

<div align="center">

<img src="https://raw.githubusercontent.com/AgnostiqHQ/covalent/master/doc/source/_static/covalent_readme_banner.svg" width=150%>

</div>


## Covalent Google Cloud Platform (GCP) Batch Plugin

Covalent is a Pythonic workflow tool used to execute tasks on advanced computing hardware. This executor plugin interfaces Covalent with [GCP Batch](https://cloud.google.com/batch).

## 1. Installation

To use this plugin with Covalent, install it using `pip`:

```sh
pip install covalent-gcpbatch-plugin
```

## 2. Usage Example

This is an example of how a workflow can be constructed to use the GCP Batch executor. In the example, we train a Support Vector Machine (SVM) and use an instance of the executor to execute the `train_svm` electron. Note that we also require [DepsPip](https://covalent.readthedocs.io/en/latest/concepts/concepts.html#depspip) which will be required to execute the electrons.


```python
from numpy.random import permutation
from sklearn import svm, datasets
import covalent as ct


deps_pip = ct.DepsPip(
    packages=["numpy==1.22.4", "scikit-learn==1.1.2"]
)

executor = ct.executor.GCPBatchExecutor(
    project_id='covalent_gcp_batch',
    region='us-east1',
    bucket_name='covalent-storage-bucket',
    container_image_uri='us-east1-docker.pkg.dev/covalent_gcp_batch_/covalent/covalent-gcpbatch-executor',
    service_account_email='covalentsaaccount@covalenttesting.iam.gserviceaccount.com',
    vcpus = 2,  # Number of vCPUs to allocate
    memory = 512,  # Memory in MB to allocate
    time_limit = 300,  # Time limit of job in seconds
    poll_freq = 3,  # Number of seconds to pause before polling for the job's status
  )


# Use executor plugin to train our SVM model
@ct.electron(
    executor=executor,
    deps_pip=deps_pip
)
def train_svm(data, C, gamma):
    X, y = data
    clf = svm.SVC(C=C, gamma=gamma)
    clf.fit(X[90:], y[90:])
    return clf

@ct.electron
def load_data():
    iris = datasets.load_iris()
    perm = permutation(iris.target.size)
    iris.data = iris.data[perm]
    iris.target = iris.target[perm]
    return iris.data, iris.target

@ct.electron
def score_svm(data, clf):
    X_test, y_test = data
    return clf.score(
    	X_test[:90],y_test[:90]
    )

@ct.lattice
def run_experiment(C=1.0, gamma=0.7):
    data = load_data()
    clf = train_svm(
    	data=data,
	    C=C,
	    gamma=gamma
    )
    return score_svm(
    	data=data,
	    clf=clf
    )

# Dispatch the workflow.
dispatch_id = ct.dispatch(run_experiment)(
        C=1.0,
        gamma=0.7
)

# Wait for our result and get result value
result = ct.get_result(dispatch_id, wait=True).result

print(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.

```sh
0.8666666666666667
```

In order for the above workflow to run successfully, one has to provision the required cloud resources as mentioned in the section [Required GCP Batch Resources](#-required-gcp-batch-resources).

## 3. Configuration

There are many configuration options that can be passed in to the class `ct.executor.GCPBatchExecutor` or by modifying the [covalent config file](https://covalent.readthedocs.io/en/latest/how_to/config/customization.html) under the section `[executors.gcpbatch]`.

For more information about all of the possible configuration values visit our [read the docs (RTD) guide](https://covalent.readthedocs.io/en/latest/api/executors/gcpbatch.html#overview-of-configuration) for this plugin.

## 4. Required GCP Resources

In order to run your workflows with covalent there are a few notable GCP resources that need to be provisioned first. The required resources are Google storage bucket, docker artifact registry and service account.

For more information regarding which cloud resources need to be provisioned visit our [read the docs (RTD) guide](https://covalent.readthedocs.io/en/latest/api/executors/gcpbatch.html#required-cloud-resources) for this plugin.

## Getting Started with Covalent

For more information on how to get started with Covalent, check out the project [homepage](https://github.com/AgnostiqHQ/covalent) and the official [documentation](https://covalent.readthedocs.io/en/latest/).

## Release Notes

Release notes are available in the [Changelog](https://github.com/AgnostiqHQ/covalent-gcpbatch-plugin/blob/main/CHANGELOG.md).

## Citation

Please 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.5903364

## License

Covalent is licensed under the GNU Affero GPL 3.0 License. Covalent may be distributed under other licenses upon request. See the [LICENSE](https://github.com/AgnostiqHQ/covalent-gcpbatch-plugin/blob/main/LICENSE) file or contact the [support team](mailto:support@agnostiq.ai) for more details.


