Skip to content

Algorithm Interface

Scott Sievert edited this page Feb 17, 2017 · 1 revision

Steps to add an algorithm to an application

  1. Define the inputs and outputs for the algorithm
  2. Write the YAML file (myAlg.yaml) that describes the inputs and outputs.
  3. Call the algorithm with a dictionary of arguments.

YAML interface

Here's an example YAML interface file for initExp. This example gives various initialization arguments and says that the return statement must be True (which is enforced by the verifier):

getQuery:
  args:
    n:
      description: Number of targets
      type: num
    d:
      description: Dimension of embedding
      type: num
  rets:
    description: The ID of the center target
    type: tuple
    values:
      0:
        type: num
        description: index of 1st target
      1:
        type: num
        description: index of 2nd target

Here's how you would call this algorithm:

myApp interface

A similar interface exists for myApp's functions.

class myApp:
    # ...
    def getQuery(self, butler, alg, args):
        # get the index of the target to ask about
        target_indicies = alg({'n': n, 'd': d})

        # pull the target with that index out
        targets = [self.TargetManager.get_target_item(butler.exp_uid, i) for i in target_indicies]

        # return that target
        return {'targets': targets}

On the HTML page in getQuery_widget.html, the myApp:getQuery return statement is then available through query. In this case, myAlg:getQuery would return 0 which would be parsed

For example, you might have the following HTML to show a particular index:

<img class="image" src={{ query.targets[0].primary_description }}> </img>
Clone this wiki locally