Polymorphs

Flexibility with IPLD

Many fields in Computes support something we call polymorphs. A Polymorph allows you to interchangeably use an IPLD merkle-link, or the actual data.

Sometimes using merkle-links to all your data is cumbersome and unnecessary. We want to make using Computes as easy as possible, even though it is a complex system. We will automatically detect if a polymorph is a link or raw-data and handle it transparently.

Example

A very common usage of the polymorph is in the Task and Task Definition. Let's look at a simple task without any merkle-links.

{
  "input": {
    "dataset": 2
  },
  "taskDefinition": {
    "runner": {
      "type": "docker-json-runner",
      "manifest": {
        "*": {
          "image": "computes/fibonacci-sum-split:latest"
        }
      }
    }
  }
}

The taskDefinition property contains json defining the actual task definition. Imagine you want to share this task definition across thousands of tasks, it would become quite repetitive. Luckily with IPFS and IPLD we can create a pointer to that data instead of repeating it over and over.

Linked Example

Let's look at the same task, but using IPLD links and Polymorphs.

{
  "input": {
    "dataset": 2
  },
  "taskDefinition": {
    "/": "zdpuAwMb2hcPEVVyy8h3MRqKkQfbXAus4d5AHAkHQJL7bvhwh"
  },
}
{
  "runner": {
    "type": "docker-json-runner",
    "manifest": {
      "*": {
        "image": "computes/fibonacci-sum-split:latest"
      }
    }
  }
}

If you look at task.json, it contains an IPLD link (defined as { "/": "zdpuAwMb2hcPEVVyy8h3MRqKkQfbXAus4d5AHAkHQJL7bvhwh" }). When this link is encountered, Computes will download the linked data and substitute it in place of the link when evaluating the task. The task-definition.json contains the data that the IPLD link is pointing to.