MCPcopy
hub / github.com/hyperopt/hyperopt / MongoTrials

Class MongoTrials

hyperopt/mongoexp.py:661–995  ·  view source on GitHub ↗

Trials maps on to an entire mongo collection. It's basically a wrapper around MongoJobs for now. As a concession to performance, this object permits trial filtering based on the exp_key, but I feel that's a hack. The case of `cmd` is similar-- the exp_key and cmd are semantically co

Source from the content-addressed store, hash-verified

659
660
661class MongoTrials(Trials):
662 """Trials maps on to an entire mongo collection. It's basically a wrapper
663 around MongoJobs for now.
664
665 As a concession to performance, this object permits trial filtering based
666 on the exp_key, but I feel that's a hack. The case of `cmd` is similar--
667 the exp_key and cmd are semantically coupled.
668
669 WRITING TO THE DATABASE
670 -----------------------
671 The trials object is meant for *reading* a trials database. Writing
672 to a database is different enough from writing to an in-memory
673 collection that no attempt has been made to abstract away that
674 difference. If you want to update the documents within
675 a MongoTrials collection, then retrieve the `.handle` attribute (a
676 MongoJobs instance) and use lower-level methods, or pymongo's
677 interface directly. When you are done writing, call refresh() or
678 refresh_tids() to bring the MongoTrials up to date.
679 """
680
681 asynchronous = True
682
683 def __init__(self, arg, exp_key=None, cmd=None, workdir=None, refresh=True):
684 if not _has_mongo:
685 raise Exception(
686 "MongoTrials cannot import pymongo classes. Make sure that pymongo "
687 "is available in your environment. E.g., try running 'import pymongo'"
688 )
689
690 if isinstance(arg, MongoJobs):
691 self.handle = arg
692 else:
693 connection_string = arg
694 self.handle = MongoJobs.new_from_connection_str(connection_string)
695 self.handle.create_indexes()
696 self._exp_key = exp_key
697 self.cmd = cmd
698 self.workdir = workdir
699 if refresh:
700 self.refresh()
701
702 def view(self, exp_key=None, cmd=None, workdir=None, refresh=True):
703 rval = self.__class__(
704 self.handle,
705 exp_key=self._exp_key if exp_key is None else exp_key,
706 cmd=self.cmd if cmd is None else cmd,
707 workdir=self.workdir if workdir is None else workdir,
708 refresh=refresh,
709 )
710 return rval
711
712 def refresh_tids(self, tids):
713 """Sync documents with `['tid']` in the list of `tids` from the
714 database (not *to* the database).
715
716 Local trial documents whose tid is not in `tids` are not
717 affected by this call. Local trial documents whose tid is in `tids` may
718 be:

Callers 5

setUpMethod · 0.90
wrapperFunction · 0.90
test_seeds_AABMethod · 0.90
test_trial_attachmentsFunction · 0.90
run_oneMethod · 0.85

Calls

no outgoing calls

Tested by 4

setUpMethod · 0.72
wrapperFunction · 0.72
test_seeds_AABMethod · 0.72
test_trial_attachmentsFunction · 0.72