The flexibility that can be seen below can be exploited on these contexts:

  • Running some experiments from config files in yaml/json
  • Automatize them and use the json representation to send them as messages
  • Attach metadata to the experiment (use data stores)

In [2]:
from fito import as_operation, SpecField, PrimitiveField, Operation
from time import sleep

class DatabaseConnection(Operation):
    host = PrimitiveField(pos=0)
    
    def __repr__(self): return "connection(db://{})".format(self.host)

@as_operation(database=SpecField, experiment_config=SpecField)
def run_experiment(database, experiment_config):
    sleep(0.25)

@as_operation()
def experiment_1(alpha=0.5, beta=10):
    return alpha + beta / 2

It's __repr__ is descent


In [4]:
run = run_experiment(DatabaseConnection('localhost'), experiment_1(alpha=10))
print run


run_experiment(database=connecti..., experiment_config...)

Json serializable:


In [5]:
print run.json.dumps()


{
  "experiment_config": {
    "alpha": 10, 
    "beta": 10, 
    "type": "experiment_1"
  }, 
  "type": "run_experiment", 
  "database": {
    "host": "localhost", 
    "type": "DatabaseConnection"
  }
}

My beloved yaml-serializable


In [6]:
print run.yaml.dumps()


database:
  host: localhost
  type: DatabaseConnection
experiment_config:
  alpha: 10
  beta: 10
  type: experiment_1
type: run_experiment

And of course, parseable :)


In [7]:
print Operation.from_yaml(run.yaml.dumps()).yaml.dumps()


database:
  host: localhost
  type: DatabaseConnection
experiment_config:
  alpha: 10
  beta: 10
  type: experiment_1
type: run_experiment