Last active
December 18, 2015 23:18
-
-
Save bwaldvogel/5860187 to your computer and use it in GitHub Desktop.
Script to update hyperopt jobs database for adding a new hyperparameter. See https://github.com/jaberg/hyperopt/issues/136
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: set fileencoding=utf-8 : | |
from __future__ import division, absolute_import, print_function | |
import sys | |
from pymongo import MongoClient | |
if __name__ == "__main__": | |
if len(sys.argv) < 6: | |
print("usage: %s <host[:port]> <db> <experiment> <parameter> <value>" % sys.argv[0], file=sys.stderr) | |
sys.exit(1) | |
client = MongoClient(sys.argv[1]) | |
dbname = sys.argv[2] | |
exp_key = sys.argv[3] | |
parameter_name = sys.argv[4] | |
parameter_value = float(sys.argv[5]) | |
if not dbname in client.database_names(): | |
raise Exception("unknown database: '%s'" % dbname) | |
jobs = client[dbname]["jobs"] | |
for job in jobs.find({'exp_key': exp_key}): | |
tid = int(job["tid"]) | |
query = {'_id': job["_id"]} | |
jobs.update(query, {"$set": {"misc.vals.%s" % parameter_name: [parameter_value]}}) | |
jobs.update(query, {"$set": {"misc.idxs.%s" % parameter_name: [tid]}}) | |
print("upgraded job", job["_id"], tid) | |
else: | |
print("found no job in database '%s' with experiment '%s'" % (dbname, exp_key), file=sys.stderr) | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment