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 targetstype: numd:
description: Dimension of embeddingtype: numrets:
description: The ID of the center targettype: tuplevalues:
0:
type: numdescription: index of 1st target1:
type: numdescription: index of 2nd target

Here's how you would call this algorithm:

myApp interface

A similar interface exists for myApp's functions.

classmyApp:
# ...defgetQuery(self, butler, alg, args):
# get the index of the target to ask abouttarget_indicies=alg({'n': n, 'd': d})
# pull the target with that index outtargets= [self.TargetManager.get_target_item(butler.exp_uid, i) foriintarget_indicies]
# return that targetreturn {'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:

<imgclass="image" src={{query.targets[0].primary_description}}></img>

Clone this wiki locally