Compute Flow
This page shows how you run a compute flow.
Last updated
This page shows how you run a compute flow.
Last updated
Copyright 2024 Ocean Protocol Foundation Ltd.
In this page, we provide the steps for publishing algorithm asset, run it on Ocean environment for C2D and retrieve the result logs, using ocean.py.
We assumed that you have completed the installation part with the preferred setup.
Here are the steps:
Alice publishes dataset
Alice publishes algorithm
Alice allows the algorithm for C2D for that data asset
Bob acquires datatokens for data and algorithm
Bob starts a compute job using a free C2D environment (no provider fees)
Bob monitors logs / algorithm output
Let's go through each step.
In the same python console:
In the same Python console:
In the same Python console:
In the same Python console:
Only inputs needed: DATA_did, ALGO_did. Everything else can get computed as needed. For demo purposes, we will use the free C2D environment, which requires no provider fees.
In the same Python console:
In the same Python console, you can check the job status as many times as needed:
Once the returned status dictionary contains the dateFinished
key, Bob can retrieve the job results using ocean.compute.result or, more specifically, just the output if the job was successful. For the purpose of this tutorial, let's choose the second option.
You can use the result however you like. For the purpose of this example, let's plot it.
Make sure you have matplotlib
package installed in your virtual environment.
You should see something like this:
In the "publish algorithm" step, to replace the sample algorithm with another one:
Use the image name and tag in the container
part of the algorithm metadata.
The image must have basic support for installing dependencies. E.g. "pip" for the case of Python. You can use other languages, of course.
The function to pay_for_compute_service
automates order starting, order reusing and performs all the necessary Provider and on-chain requests. It modifies the contents of the given ComputeInput as follows:
If the dataset/algorithm contains a transfer_tx_id
property, it will try to reuse that previous transfer id. If provider fees have expired but the order is still valid, then the order is reused on-chain.
If the dataset/algorithm does not contain a transfer_tx_id
or the order has expired (based on the Provider's response), then one new order will be created.
This means you can reuse the same ComputeInput and you don't need to regenerate it everytime it is sent to pay_for_compute_service
. This step makes sure you are not paying unnecessary or duplicated fees.
If you wish to upgrade the compute resources, you can use any (paid) C2D environment. Inspect the results of ocean.ocean_compute.get_c2d_environments(service.service_endpoint, DATA_ddo.chain_id)
and ocean.retrieve_provider_fees_for_compute(datasets, algorithm_data, consumer_address, compute_environment, duration)
for a preview of what you will pay. Don't forget to handle any minting, allowance or approvals on the desired token to ensure transactions pass.
To customise the privacy and accessibility of your compute service, add the compute_values
argument to create_url_asset
to set values according to the . The function assumes the documented defaults.
You can choose each method for getting access from.
This will output the status of the current job. Here is a list of possible results: .
This README has a simple ML algorithm. However, Ocean C2D is not limited to usage in ML. The file has examples from vision and other fields.
Use one of the standard or publish a custom docker image.
More info is available on the