def basic_setup(self): global log, M if self.args[0]: # Probably being called from the command line - load the config file self.config = conf = appconfig("config:%s" % self.args[0], relative_to=os.getcwd()) # ... logging does not understand section#subsection syntax logging_config = self.args[0].split("#")[0] logging.config.fileConfig(logging_config, disable_existing_loggers=False) log = logging.getLogger("allura.command") log.info("Initialize command with config %r", self.args[0]) load_environment(conf.global_conf, conf.local_conf) self.setup_globals() from allura import model M = model ming.configure(**conf) activitystream.configure(**conf) pylons.tmpl_context.user = M.User.anonymous() else: # Probably being called from another script (websetup, perhaps?) log = logging.getLogger("allura.command") conf = pylons.config self.tools = pylons.app_globals.entry_points["tool"].values() for ep in iter_entry_points("allura.command_init"): log.info("Running command_init for %s", ep.name) ep.load()(conf) log.info("Loaded tools")
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", required=True, help="provide name for experiment, to be used as prefix for database collections") parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--dryrun", help="Do the calculations but do not change the database (handiest with --debug 1 to see the results", action="store_true") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if int(args.debug) == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("CALCULATING GRAPH SYMMETRY STATS - Experiment: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def setUp(self): data.set_database_port("27017") data.set_database_hostname("localhost") data.set_experiment_name("testupdate") config = data.getMingConfiguration() ming.configure(**config) # clean out the collection data.PerGenerationStatsPostclassification.m.remove() self.data = dict( simulation_time=1000, classification_id=ObjectId("52056c3b3f07d50754eec1a3"), classification_type="EVEN", classification_dim=2, classification_coarseness=4, replication=0, sample_size=50, population_size=2000, mutation_rate=0.01, simulation_run_id="urn:uuid:07f75571-6f6b-4113-84c5-46cb8114cb72", mode_richness=[5,3], class_richness=2, mode_evenness_iqv=[0.5,0.3], class_evenness_iqv=0.25, design_space_occupation=None, class_innovation_interval_times=None )
def basic_setup(self): global log, M if self.args[0]: # Probably being called from the command line - load the config file self.config = conf = appconfig('config:%s' % self.args[0], relative_to=os.getcwd()) # Configure logging try: # ... logging does not understand section#subsection syntax logging_config = self.args[0].split('#')[0] logging.config.fileConfig(logging_config, disable_existing_loggers=False) except Exception: # pragma no cover print >> sys.stderr, ( 'Could not configure logging with config file %s' % self.args[0]) log = logging.getLogger('allura.command') log.info('Initialize command with config %r', self.args[0]) load_environment(conf.global_conf, conf.local_conf) self.setup_globals() from allura import model M = model ming.configure(**conf) pylons.c.user = M.User.anonymous() else: # Probably being called from another script (websetup, perhaps?) log = logging.getLogger('allura.command') conf = pylons.config self.tools = pylons.g.entry_points['tool'].values() for ep in iter_entry_points('allura.command_init'): log.info('Running command_init for %s', ep.name) ep.load()(conf) log.info('Loaded tools')
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--filename", help="path to file for export", required=True) args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) #### main program #### data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", required=True, help="provide name for experiment, to be used as prefix for database collections") parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--finalized", help="Only export runs which finalized after convergence", action="store_true") parser.add_argument("--action", choices=["sample", "single", "bulk"]) parser.add_argument("--ssize", help="Sample size of graphs to export", default="100") parser.add_argument("--id", help="Export trait graphs with this object id") parser.add_argument("--idfile", help="Export trait graphs for ids in file") parser.add_argument("--directory", help="Directory to which DOT files are written") args = parser.parse_args() if int(args.debug) == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("EXPORT TRAIT GRAPHS AS DOT - Experiment: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def basic_setup(self): global log, M if self.args[0]: # Probably being called from the command line - load the config # file self.config = conf = appconfig('config:%s' % self.args[0], relative_to=os.getcwd()) # ... logging does not understand section#subsection syntax logging_config = self.args[0].split('#')[0] logging.config.fileConfig( logging_config, disable_existing_loggers=False) log = logging.getLogger('allura.command') log.info('Initialize command with config %r', self.args[0]) load_environment(conf.global_conf, conf.local_conf) self.setup_globals() from allura import model M = model ming.configure(**conf) if asbool(conf.get('activitystream.recording.enabled', False)): activitystream.configure(**h.convert_bools(conf, prefix='activitystream.')) pylons.tmpl_context.user = M.User.anonymous() else: # Probably being called from another script (websetup, perhaps?) log = logging.getLogger('allura.command') conf = pylons.config self.tools = pylons.app_globals.entry_points['tool'].values() for ep in h.iter_entry_points('allura.command_init'): log.info('Running command_init for %s', ep.name) ep.load()(conf) log.info('Loaded tools')
def setup(parser): config = parser.parse_args() sim_id = uuid.uuid1().urn script = __file__ if config.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') data.set_experiment_name(config.experiment) data.set_database_hostname(config.dbhost) data.set_database_port(config.dbport) dbconfig = data.getMingConfiguration(data.modules) ming.configure(**dbconfig) # set up parallelism. At the moment, this doesn't do anything on OSX # but should provide parallelism on Linux across the replicates at least if config.cores is not None: cores = config.cores else: cores = utils.get_parallel_cores(config.devel) log.info("Setting up %s cores for parallel simulation", cores) import simuOpt if(config.debug == 1): simuOpt.setOptions(alleleType='long',optimized=True,quiet=False,numThreads = cores) else: simuOpt.setOptions(alleleType='long',optimized=True,quiet=False,numThreads = cores) return (config,sim_id,script, cores)
def setup(): global args, simconfig permitted_stage_tags = data.get_experiment_stage_tags() parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--collections", choices=['postclassification', 'traits', 'both'], help="Collections to retrofit ", required=True) args = parser.parse_args() simconfig = utils.CTPyConfiguration(args.configuration) if args.debug: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration() ming.configure(**config)
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment, to be used as prefix for database collections") parser.add_argument("--simid", help="simulation ID to export from database") parser.add_argument("--debug", type=int, help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--outputdirectory", help="path to directory for exported data files", required=True) args = parser.parse_args() if args.debug == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("EXPORT DATA TO CSV - Experiment: %s SimulationID: %s", args.experiment, args.simid) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--parallelism", help="Number of concurrent processes to run", default="4") parser.add_argument("--diagram", help="Draw a diagram when complete", default=False) args = parser.parse_args() simconfig = utils.AxelrodExtensibleConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def configure(args=None): '''Load the options and configure the system''' if args is None: args = sys.argv options, args = get_options(args) if options.verbose: log.info('Settings:') for k,v in sorted(options.__dict__.items()): log.info(' %s: %r', k, v) ming_config = { 'ming.zarkov.master':options.mongo_uri, 'ming.zarkov.database':options.mongo_database, 'ming.zarkov.use_gevent':True} for dbinfo in options.extra_dbs: dbinfo = dict(dbinfo) prefix = 'ming.%s.' % dbinfo.pop('name') for k,v in dbinfo.items(): ming_config[prefix + k] = v if options.mongo_username: ming_config['ming.zarkov.authenticate.name'] = options.mongo_username if options.mongo_username: ming_config['ming.zarkov.authenticate.password'] = options.mongo_password ming.configure(**ming_config) if options.pdb: sys.excepthook = postmortem_hook return options, args
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--popsize", help="Population size", required=True) parser.add_argument("--numloci", help="Number of loci per individual", required=True) parser.add_argument("--maxinittraits", help="Max initial number of traits per locus for initialization", required=True) parser.add_argument("--conformismstrength", help="Strength of conformist bias [0.0 - 1.0]", required=True) parser.add_argument("--anticonformismstrength", help="Strength of conformist bias [0.0 - 1.0]", required=True) parser.add_argument("--innovationrate", help="Theta value rate at which innovations occur in population", required=True) parser.add_argument("--periodic", help="Periodic boundary condition", choices=['1','0'], required=True) parser.add_argument("--kandlerinterval", help="Interval for Kandler remaining traits sample, taken before maxtime, in generations (will be scaled to timesteps)", default="1000") parser.add_argument("--simulationendtime", help="Time at which simulation and sampling end, defaults to 2M steps", default="2000000") args = parser.parse_args() simconfig = utils.MixtureConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config) simconfig.num_features = int(args.numloci) simconfig.num_traits = int(args.maxinittraits) simconfig.popsize = int(args.popsize) mut = pg.moran_mutation_rate_from_theta(float(args.popsize), float(args.innovationrate)) simconfig.innovation_rate = float(args.numloci) * mut simconfig.configured_innovation_rate = float(args.innovationrate) log.debug("configured theta = %s, using numloci %s * per-locus mutation rate %s = all-loci innovation rate: %s", args.innovationrate, args.numloci, mut, simconfig.innovation_rate) simconfig.maxtime = int(args.simulationendtime) simconfig.script = __file__ simconfig.conformism_strength = float(args.conformismstrength) simconfig.anticonformism_strength = float(args.anticonformismstrength) simconfig.maxtime = int(args.simulationendtime) simconfig.model_class_label = simconfig.MODEL_CLASS_LABEL log.debug("Equifinality model class: %s", simconfig.model_class_label) simconfig.sim_id = uuid.uuid4().urn if args.periodic == '1': simconfig.periodic = 1 else: simconfig.periodic = 0
def setUp(self): setup_unit_test() config = { 'ming.main.uri': 'mim://host/allura_test', } ming.configure(**config) for i in range(10): M.User.upsert('sample-user-%d' % i)
def setUp(self): ming.configure(**{ 'ming.zarkov.master':'mim:///', 'ming.zarkov.database':'zarkov'}) self.options = mock.Mock() self.options.journal_file_size = 1024 self.options.journal_min_files = 4 self.journal_dir = tempfile.mkdtemp('.journal', 'zarkov-test') self.j = JournalWriter(self.options, self.journal_dir, start_greenlets=False)
def test_configure_optional_params(self, Connection): ming.configure(**{ 'ming.main.uri':'mongodb://localhost:27017/test_db', 'ming.main.replicaSet': 'foobar', 'ming.main.w': 2, 'ming.main.ssl': True, }) session = Session.by_name('main') assert session.bind.conn is not None assert session.bind.db is not None
def connection_configure(): from ming import configure from ming.odm import ThreadLocalODMSession configure(**{'ming.mysession.uri': 'mongodb://localhost:27017/tutorial'}) session = ThreadLocalODMSession.by_name('mysession') session.db ThreadLocalODMSession.by_name('mysession') is session
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument( "--experiment", help= "provide name for experiment, to be used as prefix for database collections" ) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Path to configuration file") parser.add_argument("--model", choices=['axelrod', 'extensible', 'treestructured'], required=True) parser.add_argument( "--finalized", help="Only export runs which finalized after convergence", action="store_true") parser.add_argument("--filename", help="path to file for export", required=True) args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if args.model == 'axelrod': simconfig = utils.AxelrodConfiguration(args.configuration) elif args.model == 'extensible': simconfig = utils.AxelrodExtensibleConfiguration(args.configuration) elif args.model == 'treestructured': simconfig = utils.TreeStructuredConfiguration(args.configuration) else: log.error("This shouldn't happen - args.model = %s", args.model) if args.debug == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("EXPORT DATA TO CSV - Experiment: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def test_configure(self, Connection): ming.configure(**{ 'ming.main.uri':'mongodb://localhost:27017/test_db', 'ming.main.connect_retry': 1, 'ming.main.tz_aware': False, }) session = Session.by_name('main') assert session.bind.conn is not None assert session.bind.db is not None args, kwargs = Connection.call_args assert 'database' not in kwargs
def test_configure(self): ming.configure(**{ 'ming.main.master':'mongodb://localhost:27017/', 'ming.main.database':'test_db', 'ming.main.network_timeout':'0.1', 'ming.main.connect_retry': 1, 'ming.main.tz_aware': False, }) session = Session.by_name('main') assert session.bind.conn is not None assert session.bind.db is not None
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ import ming update_settings_from_environ(settings) ming.configure(**settings) config = Configurator(settings=settings) add_routes(config) config.scan() return config.make_wsgi_app()
def setUp(self): class TestDoc(Document): class __mongometa__: name='test_doc' session = Session.by_name('main') _id=Field(S.ObjectId, if_missing=None) a=Field(S.Int, if_missing=None) b=Field(S.Object, dict(a=S.Int(if_missing=None))) config = { 'ming.main.master':'mongo://localhost:27017/test_db' } ming.configure(**config) self.session = TestDoc.__mongometa__.session
def setup_schema(command, conf, vars): """Place any commands to setup allura here""" import ming import allura REGISTRY.prepare() REGISTRY.register(pylons.c, EmptyClass()) REGISTRY.register(pylons.g, config['pylons.app_globals']) REGISTRY.register(allura.credentials, allura.lib.security.Credentials()) ming.configure(**conf) # Nothing to do log.info('setup_schema called')
def setup_schema(command, conf, vars): """Place any commands to setup allura here""" import ming import allura REGISTRY.prepare() REGISTRY.register(pylons.c, EmptyClass()) REGISTRY.register(pylons.g, config["pylons.app_globals"]) REGISTRY.register(allura.credentials, allura.lib.security.Credentials()) ming.configure(**conf) # Nothing to do log.info("setup_schema called")
def test_configure(self, Connection): ming.configure(**{ 'ming.main.uri':'mongodb://localhost:27017/test_db', 'ming.main.connect_retry': 1, 'ming.main.tz_aware': False, }) session = Session.by_name('main') assert session.bind.conn is not None assert session.bind.db is not None assert session.bind.bind._auto_ensure_indexes args, kwargs = Connection.call_args assert 'database' not in kwargs
def setup_schema(command, conf, vars): """Place any commands to setup allura here""" import ming import allura REGISTRY.prepare() REGISTRY.register(pylons.tmpl_context, EmptyClass()) REGISTRY.register(pylons.app_globals, config['pylons.app_globals']) REGISTRY.register(allura.credentials, allura.lib.security.Credentials()) ming.configure(**conf) if asbool(conf.get('activitystream.recording.enabled', False)): activitystream.configure(**h.convert_bools(conf, prefix='activitystream.')) # Nothing to do log.info('setup_schema called')
def setup_schema(command, conf, vars): """Place any commands to setup allura here""" import ming import allura REGISTRY.prepare() REGISTRY.register(pylons.tmpl_context, EmptyClass()) REGISTRY.register(pylons.app_globals, config['pylons.app_globals']) REGISTRY.register(allura.credentials, allura.lib.security.Credentials()) ming.configure(**conf) if asbool(conf.get('activitystream.recording.enabled', False)): activitystream.configure(**conf) # Nothing to do log.info('setup_schema called')
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) # MongoDB connection configuration url_str = settings.get('mongo_uri', 'mongodb://localhost:27017/default') ming_config = {'ming.default.uri': url_str} ming.configure(**ming_config) config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.scan() return config.make_wsgi_app()
def setUp(self): config = { 'ming.main.uri': 'mim://allura', 'ming.project.uri': 'mim://project-data', } ming.configure(**config) setup_unit_test() self.session = session(File) self.conn = M.session.main_doc_session.db._connection self.db = M.session.main_doc_session.db self.db.fs.remove() self.db.fs.files.remove() self.db.fs.chunks.remove()
def test_configure_with_database(self): ming.configure( **{ "ming.main.uri": "mongodb://localhost:27017/test_db", "ming.main.database": "another_test_db", "ming.main.connect_retry": 1, "ming.main.tz_aware": False, }) session = Session.by_name("main") assert session.bind.conn is not None assert session.bind.db is not None assert session.bind.bind._auto_ensure_indexes args, kwargs = self.MockConn.call_args assert "database" in kwargs
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--popsize", help="Population size", required=True) parser.add_argument("--maxinittraits", help="Max initial number of traits per indiv", required=True) parser.add_argument("--additionrate", help="Rate at which traits are added during interactions", required=True) parser.add_argument("--maxtraitvalue", help="Maximum integer token for traits in the trait space", required=True) parser.add_argument("--periodic", help="Periodic boundary condition", choices=['1','0'], required=True) parser.add_argument("--diagram", help="Draw a diagram of the converged model", action="store_true") parser.add_argument("--drift_rate", help="Rate of drift") args = parser.parse_args() simconfig = utils.AxelrodExtensibleConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config) if args.drift_rate: simconfig.drift_rate = float(args.drift_rate) simconfig.popsize = int(args.popsize) simconfig.maxtraits = int(args.maxinittraits) simconfig.add_rate = float(args.additionrate) simconfig.max_trait_value = int(args.maxtraitvalue) simconfig.sim_id = uuid.uuid4().urn if args.periodic == '1': simconfig.periodic = 1 elif args.periodic == '0': simconfig.periodic = 0
def ming_config(**conf): """Temporarily swap in a new ming configuration, restoring the previous one when the contextmanager exits. :param \*\*conf: keyword arguments defining the new ming configuration """ import ming from ming.session import Session datastores = Session._datastores try: ming.configure(**conf) yield finally: Session._datastores = datastores for name, session in Session._registry.iteritems(): session.bind = datastores.get(name, None) session._name = name
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument( "--experiment", required=True, help= "provide name for experiment, to be used as prefix for database collections" ) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument( "--dryrun", help= "Do the calculations but do not change the database (handiest with --debug 1 to see the results", action="store_true") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if int(args.debug) == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("CALCULATING GRAPH SYMMETRY STATS - Experiment: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def setup_schema(command, conf, vars): """Place any commands to setup allura here""" import ming import allura # turbogears has its own special magic wired up for its globals, can't use a regular Registry tgl = RequestLocals() tgl.tmpl_context = EmptyClass() tgl.app_globals = config['tg.app_globals'] tg.request_local.context._push_object(tgl) REGISTRY.prepare() REGISTRY.register(allura.credentials, allura.lib.security.Credentials()) ming.configure(**conf) if asbool(conf.get('activitystream.recording.enabled', False)): activitystream.configure(**h.convert_bools(conf, prefix='activitystream.')) # Nothing to do log.info('setup_schema called')
def http_main(global_config, **local_settings): """ This function returns a (minimal) Pyramid WSGI application. """ settings = dict(global_config) settings.update(local_settings) config = Configurator(settings=settings) config.add_renderer(None, 'pyramid.renderers.json_renderer_factory') config.add_route('chapman.1_0.queue', '/1.0/q/{qname}/') config.add_route('chapman.1_0.message', '/1.0/m/{message_id}/') config.add_subscriber( RequireHeader('Authorization', 'chapman %s' % settings['chapman.secret']), NewRequest) config.scan('chapman.views') if not ming.Session._datastores: ming.configure(**settings) app = config.make_wsgi_app() db = ming.Session.by_name('chapman').db app = MongoMiddleware(app, db.connection) return app
def setup(): global sargs, config, simconfig sargs = utils.ScriptArgs() if sargs.debug: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') simconfig = utils.CTPyConfiguration(sargs.configuration) log.debug("experiment name: %s", sargs.experiment_name) data.set_experiment_name(sargs.experiment_name) data.set_database_hostname(sargs.database_hostname) data.set_database_port(sargs.database_port) #### main program #### log.info("INITIALIZE_EXPERIMENT - Starting program") config = data.getMingConfiguration() ming.configure(**config)
def setup(): global sargs, config, simconfig sargs = utils.ScriptArgs() if sargs.debug == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') simconfig = utils.CTPyConfiguration(sargs.configuration) log.debug("experiment name: %s", sargs.experiment_name) data.set_experiment_name(sargs.experiment_name) data.set_database_hostname(sargs.database_hostname) data.set_database_port(sargs.database_port) log.info("CALCULATE_PERSIMRUN_STATISTICS - Starting program") config = data.getMingConfiguration() ming.configure(**config)
def setup(): global sargs, config, simconfig sargs = utils.ScriptArgs() if sargs.debug: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') simconfig = utils.CTPyConfiguration(sargs.configuration) log.debug("experiment name: %s", sargs.experiment_name) data.set_experiment_name(sargs.experiment_name) data.set_database_hostname(sargs.database_hostname) data.set_database_port(sargs.database_port) #### main program #### log.info("SUBSAMPLE_INDIVIDUAL_SAMPLES - Starting program") log.info("Performing subsampling for experiment named: %s", data.experiment_name) config = data.getMingConfiguration() ming.configure(**config)
def setup(parser): config = parser.parse_args() sim_id = uuid.uuid1().urn script = __file__ if config.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') data.set_experiment_name(config.experiment) data.set_database_hostname(config.dbhost) data.set_database_port(config.dbport) dbconfig = data.getMingConfiguration(data.modules) ming.configure(**dbconfig) # set up parallelism. At the moment, this doesn't do anything on OSX # but should provide parallelism on Linux across the replicates at least if config.cores is not None: cores = config.cores else: cores = utils.get_parallel_cores(config.devel) log.info("Setting up %s cores for parallel simulation", cores) import simuOpt if (config.debug == 1): simuOpt.setOptions(alleleType='long', optimized=True, quiet=False, numThreads=cores) else: simuOpt.setOptions(alleleType='long', optimized=True, quiet=False, numThreads=cores) return (config, sim_id, script, cores)
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment, to be used as prefix for database collections") parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Path to configuration file") parser.add_argument("--model", choices=['axelrod', 'extensible', 'treestructured'], required=True) parser.add_argument("--finalized", help="Only export runs which finalized after convergence", action="store_true") parser.add_argument("--filename", help="path to file for export", required=True) args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if args.model == 'axelrod': simconfig = utils.AxelrodConfiguration(args.configuration) elif args.model == 'extensible': simconfig = utils.AxelrodExtensibleConfiguration(args.configuration) elif args.model == 'treestructured': simconfig = utils.TreeStructuredConfiguration(args.configuration) else: log.error("This shouldn't happen - args.model = %s", args.model) if args.debug == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("EXPORT DATA TO CSV - Experiment: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument( "--experiment", help= "provide name for experiment, to be used as prefix for database collections" ) parser.add_argument("--simid", help="simulation ID to export from database") parser.add_argument("--debug", type=int, help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--outputdirectory", help="path to directory for exported data files", required=True) args = parser.parse_args() if args.debug == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("EXPORT DATA TO CSV - Experiment: %s SimulationID: %s", args.experiment, args.simid) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
def setup(): global args, config, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment, to be used as prefix for database collections") parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Path to configuration file") parser.add_argument("--filename", help="path and base filename for exports (DO NOT include *.csv extension)", required=True) args = parser.parse_args() if int(args.debug) == 1: log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') #### main program #### log.info("EXPORT DATA TO CSV - Experiment: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config)
# Define your item pipelines here # # Don't forget to add your pipeline to the ITEM_PIPELINES setting # See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html from scrapy import log from pymongo.errors import DuplicateKeyError import config from information_value.models import Document from information_value.models import odm_session import ming ming_config = {'ming.document_store.uri': config.DATABASE_URL} ming.configure(**ming_config) class LeninPipeline(object): def process_item(self, item, spider): Document( name=item['name'], url=item['url'], text=item['text'], month=item['month'], year=int(item['year']), ) try: odm_session.flush() except DuplicateKeyError: log.msg('Duplicate found', level=log.WARNING) return log.msg('Document saved', level=log.INFO)
def _make_core_app(root, global_conf, full_stack=True, **app_conf): """ Set allura up with the settings found in the PasteDeploy configuration file used. :param root: The controller module containing the TG root :param global_conf: The global settings for allura (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The allura application with all the relevant middleware loaded. This is the PasteDeploy factory for the allura application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ # Run all the initialization code here mimetypes.init( [pkg_resources.resource_filename('allura', 'etc/mime.types')] + mimetypes.knownfiles) patches.apply() try: import newrelic except ImportError: pass else: patches.newrelic() # Configure MongoDB ming.configure(**app_conf) # Configure ActivityStream if asbool(app_conf.get('activitystream.recording.enabled', False)): activitystream.configure(**app_conf) # Configure EW variable provider ew.render.TemplateEngine.register_variable_provider(get_tg_vars) # Set FormEncode language to english, as we don't support any other locales formencode.api.set_stdtranslation(domain='FormEncode', languages=['en']) # Create base app base_config = ForgeConfig(root) load_environment = base_config.make_load_environment() # Code adapted from tg.configuration, replacing the following lines: # make_base_app = base_config.setup_tg_wsgi_app(load_environment) # app = make_base_app(global_conf, full_stack=True, **app_conf) # Configure the Pylons environment load_environment(global_conf, app_conf) if config.get('zarkov.host'): try: import zmq except ImportError: raise ImportError, "Unable to import the zmq library. Please"\ " check that zeromq is installed or comment out"\ " the zarkov.host setting in your ini file." app = tg.TGApp() if asbool(config.get('auth.method', 'local')=='sfx'): import sfx.middleware d = h.config_with_prefix(config, 'auth.') d.update(h.config_with_prefix(config, 'sfx.')) app = sfx.middleware.SfxMiddleware(app, d) # Required for pylons app = RoutesMiddleware(app, config['routes.map']) # Required for sessions app = SessionMiddleware(app, config) # Redirect 401 to the login page app = LoginRedirectMiddleware(app) # Add instrumentation app = AlluraTimerMiddleware(app, app_conf) # Clear cookies when the CSRF field isn't posted if not app_conf.get('disable_csrf_protection'): app = CSRFMiddleware(app, '_session_id') # Setup the allura SOPs app = allura_globals_middleware(app) # Ensure https for logged in users, http for anonymous ones if asbool(app_conf.get('auth.method', 'local')=='sfx'): app = SSLMiddleware(app, app_conf.get('no_redirect.pattern')) # Setup resource manager, widget context SOP app = ew.WidgetMiddleware( app, compress=not asbool(global_conf['debug']), # compress=True, script_name=app_conf.get('ew.script_name', '/_ew_resources/'), url_base=app_conf.get('ew.url_base', '/_ew_resources/'), extra_headers=eval(app_conf.get('ew.extra_headers', 'None'))) # Handle static files (by tool) app = StaticFilesMiddleware(app, app_conf.get('static.script_name')) # Handle setup and flushing of Ming ORM sessions app = MingMiddleware(app) # Set up the registry for stacked object proxies (SOPs). # streaming=true ensures they won't be cleaned up till # the WSGI application's iterator is exhausted app = RegistryManager(app, streaming=True) # Converts exceptions to HTTP errors, shows traceback in debug mode tg.error.footer_html = '<!-- %s %s -->' # don't use TG footer with extra CSS & images that take time to load app = tg.error.ErrorHandler(app, global_conf, **config['pylons.errorware']) # Make sure that the wsgi.scheme is set appropriately when we # have the funky HTTP_X_SFINC_SSL environ var if asbool(app_conf.get('auth.method', 'local')=='sfx'): app = set_scheme_middleware(app) # Redirect some status codes to /error/document if config.get('override_root') != 'task': # "task" wsgi would get a 2nd request to /error/document if we used this middleware if asbool(config['debug']): app = StatusCodeRedirect(app, base_config.handle_status_codes) else: app = StatusCodeRedirect(app, base_config.handle_status_codes + [500]) return app
def setUp(self): config = { 'ming.main.uri': 'mim://allura_test', } ming.configure(**config)
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--popsize", help="Population size", required=True) parser.add_argument("--maxinittraits", help="Max initial number of traits per indiv", required=True) parser.add_argument( "--additionrate", help="Rate at which traits are added during interactions", required=True) parser.add_argument( "--maxtraitvalue", help="Maximum integer token for traits in the trait space", required=True) parser.add_argument("--periodic", help="Periodic boundary condition", choices=['1', '0'], required=True) parser.add_argument("--diagram", help="Draw a diagram of the converged model", action="store_true") parser.add_argument("--drift_rate", help="Rate of drift") args = parser.parse_args() simconfig = utils.AxelrodExtensibleConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config) if args.drift_rate: simconfig.drift_rate = float(args.drift_rate) simconfig.popsize = int(args.popsize) simconfig.maxtraits = int(args.maxinittraits) simconfig.add_rate = float(args.additionrate) simconfig.max_trait_value = int(args.maxtraitvalue) simconfig.sim_id = uuid.uuid4().urn if args.periodic == '1': simconfig.periodic = 1 elif args.periodic == '0': simconfig.periodic = 0
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--popsize", help="Population size", required=True) parser.add_argument("--maxinittraits", help="Max initial number of traits per indiv", required=True) parser.add_argument("--learningrate", help="Rate at which traits are learned during interactions", required=True) parser.add_argument("--lossrate", help="Rate at which traits are lost randomly by individuals (0.0 turns this off)", required=True) parser.add_argument("--innovrate", help="Rate at which innovations occur in population", required=True) parser.add_argument("--periodic", help="Periodic boundary condition", choices=['1','0'], required=True) parser.add_argument("--diagram", help="Draw a diagram of the converged model", action="store_true") parser.add_argument("--swrewiring", help="Rewiring probability for Watts-Strogatz population graph", required=False) parser.add_argument("--numtraittrees", help="Number of trait trees in the design space", required=True) parser.add_argument("--branchingfactor", help="Value or mean for tree branching factor", required=True) parser.add_argument("--depthfactor", help="Value or mean for tree depth factor", required=True) parser.add_argument("--savetraitgraphs", help="Saves a snapshot of trait tree graphs", action="store_true") parser.add_argument("--samplinginterval", help="Interval between samples, once sampling begins, defaults to 1M steps", default="1000000") parser.add_argument("--samplingstarttime", help="Time at which sampling begins, defaults to 1M steps", default="6000000") parser.add_argument("--simulationendtime", help="Time at which simulation and sampling end, defaults to 10000000 steps", default="10000000") args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config) if args.swrewiring: simconfig.ws_rewiring = float(args.swrewiring) simconfig.popsize = int(args.popsize) simconfig.maxtraits = int(args.maxinittraits) simconfig.learning_rate = float(args.learningrate) simconfig.num_trees = int(args.numtraittrees) simconfig.branching_factor = float(args.branchingfactor) simconfig.depth_factor = float(args.depthfactor) simconfig.loss_rate = float(args.lossrate) simconfig.innov_rate = float(args.innovrate) simconfig.maxtime = int(args.simulationendtime) simconfig.script = __file__ simconfig.save_graphs = args.savetraitgraphs simconfig.sim_id = uuid.uuid4().urn if args.periodic == '1': simconfig.periodic = 1 else: simconfig.periodic = 0
def _make_core_app(root, global_conf, full_stack=True, **app_conf): """ Set allura up with the settings found in the PasteDeploy configuration file used. :param root: The controller module containing the TG root :param global_conf: The global settings for allura (those defined under the ``[DEFAULT]`` section). :type global_conf: dict :param full_stack: Should the whole TG2 stack be set up? :type full_stack: str or bool :return: The allura application with all the relevant middleware loaded. This is the PasteDeploy factory for the allura application. ``app_conf`` contains all the application-specific settings (those defined under ``[app:main]``. """ # Run all the initialization code here mimetypes.init([pkg_resources.resource_filename('allura', 'etc/mime.types')] + mimetypes.knownfiles) # Configure MongoDB ming.configure(**app_conf) # Configure ActivityStream if asbool(app_conf.get('activitystream.recording.enabled', False)): activitystream.configure(**h.convert_bools(app_conf, prefix='activitystream.')) # Configure EW variable provider ew.render.TemplateEngine.register_variable_provider(get_tg_vars) # Set FormEncode language to english, as we don't support any other locales formencode.api.set_stdtranslation(domain='FormEncode', languages=['en']) # Create base app base_config = ForgeConfig(root) load_environment = base_config.make_load_environment() # Code adapted from tg.configuration, replacing the following lines: # make_base_app = base_config.setup_tg_wsgi_app(load_environment) # app = make_base_app(global_conf, full_stack=True, **app_conf) # Configure the TG environment load_environment(global_conf, app_conf) app = tg.TGApp() for mw_ep in h.iter_entry_points('allura.middleware'): Middleware = mw_ep.load() if getattr(Middleware, 'when', 'inner') == 'inner': app = Middleware(app, config) # Required for sessions app = SessionMiddleware(app, config, data_serializer=BeakerPickleSerializerWithLatin1()) # Handle "Remember me" functionality app = RememberLoginMiddleware(app, config) # Redirect 401 to the login page app = LoginRedirectMiddleware(app) # Add instrumentation app = AlluraTimerMiddleware(app, app_conf) # Clear cookies when the CSRF field isn't posted if not app_conf.get('disable_csrf_protection'): app = CSRFMiddleware(app, '_session_id') if asbool(config.get('cors.enabled', False)): # Handle CORS requests allowed_methods = aslist(config.get('cors.methods')) allowed_headers = aslist(config.get('cors.headers')) cache_duration = asint(config.get('cors.cache_duration', 0)) app = CORSMiddleware(app, allowed_methods, allowed_headers, cache_duration) # Setup the allura SOPs app = allura_globals_middleware(app) # Ensure http and https used per config if config.get('override_root') != 'task': app = SSLMiddleware(app, app_conf.get('no_redirect.pattern'), app_conf.get('force_ssl.pattern'), app_conf.get('force_ssl.logged_in')) # Setup resource manager, widget context SOP app = ew.WidgetMiddleware( app, compress=True, use_cache=not asbool(global_conf['debug']), script_name=app_conf.get('ew.script_name', '/_ew_resources/'), url_base=app_conf.get('ew.url_base', '/_ew_resources/'), extra_headers=ast.literal_eval(app_conf.get('ew.extra_headers', '[]')), cache_max_age=asint(app_conf.get('ew.cache_header_seconds', 60*60*24*365)), # settings to pass through to jinja Environment for EW core widgets # these are for the easywidgets' own [easy_widgets.engines] entry point # (the Allura [easy_widgets.engines] entry point is named "jinja" (not jinja2) but it doesn't need # any settings since it is a class that uses the same jinja env as the rest of allura) **{ 'jinja2.auto_reload': asbool(config['auto_reload_templates']), 'jinja2.bytecode_cache': AlluraJinjaRenderer._setup_bytecode_cache(), 'jinja2.cache_size': asint(config.get('jinja_cache_size', -1)), } ) # Handle static files (by tool) app = StaticFilesMiddleware(app, app_conf.get('static.script_name')) # Handle setup and flushing of Ming ORM sessions app = MingMiddleware(app) # Set up the registry for stacked object proxies (SOPs). # streaming=true ensures they won't be cleaned up till # the WSGI application's iterator is exhausted app = RegistryManager(app, streaming=True) # "task" wsgi would get a 2nd request to /error/document if we used this middleware if config.get('override_root') not in ('task', 'basetest_project_root'): if asbool(config['debug']): # Converts exceptions to HTTP errors, shows traceback in debug mode # don't use TG footer with extra CSS & images that take time to load tg.error.footer_html = '<!-- %s %s -->' app = tg.error.ErrorHandler(app, global_conf, **config['tg.errorware']) else: app = ErrorMiddleware(app, config, **config['tg.errorware']) app = SetRequestHostFromConfig(app, config) # Redirect some status codes to /error/document if asbool(config['debug']): app = StatusCodeRedirect(app, base_config.handle_status_codes) else: app = StatusCodeRedirect( app, base_config.handle_status_codes + [500]) for mw_ep in h.iter_entry_points('allura.middleware'): Middleware = mw_ep.load() if getattr(Middleware, 'when', 'inner') == 'outer': app = Middleware(app, config) return app
config_file = None simconfig = utils.CTPyConfiguration(config_file) log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment_name) log.debug( "NOTE: This interactive simulation always sends data to MongoDB instance on localhost" ) data.set_experiment_name(args.experiment_name) data.set_database_hostname("localhost") data.set_database_port("27017") config = data.getMingConfiguration() ming.configure(**config) sim_id = uuid.uuid4().urn log.info("Beginning simulation run: %s", sim_id) beginCollectingData = cpm.expectedIAQuasiStationarityTimeHaploid( args.popsize, args.mutationrate) log.info("Starting data collection at generation: %s", beginCollectingData) totalSimulationLength = beginCollectingData + args.length log.info("Simulation will sample %s generations after stationarity", args.length) data.storeSimulationData(args.popsize, args.mutationrate, sim_id, args.samplesize, args.replications, args.numloci,
def setup(): global args, simconfig parser = argparse.ArgumentParser() parser.add_argument("--experiment", help="provide name for experiment", required=True) parser.add_argument("--debug", help="turn on debugging output") parser.add_argument("--dbhost", help="database hostname, defaults to localhost", default="localhost") parser.add_argument("--dbport", help="database port, defaults to 27017", default="27017") parser.add_argument("--configuration", help="Configuration file for experiment", required=True) parser.add_argument("--popsize", help="Population size", required=True) parser.add_argument("--maxinittraits", help="Max initial number of traits per indiv", required=True) parser.add_argument( "--learningrate", help="Rate at which traits are learned during interactions", required=True) parser.add_argument( "--lossrate", help= "Rate at which traits are lost randomly by individuals (0.0 turns this off)", required=True) parser.add_argument("--innovrate", help="Rate at which innovations occur in population", required=True) parser.add_argument("--periodic", help="Periodic boundary condition", choices=['1', '0'], required=True) parser.add_argument("--diagram", help="Draw a diagram of the converged model", action="store_true") parser.add_argument( "--swrewiring", help="Rewiring probability for Watts-Strogatz population graph", required=False) parser.add_argument("--numtraittrees", help="Number of trait trees in the design space", required=True) parser.add_argument("--branchingfactor", help="Value or mean for tree branching factor", required=True) parser.add_argument("--depthfactor", help="Value or mean for tree depth factor", required=True) parser.add_argument("--savetraitgraphs", help="Saves a snapshot of trait tree graphs", action="store_true") parser.add_argument( "--samplinginterval", help= "Interval between samples, once sampling begins, defaults to 250K steps", default="250000") parser.add_argument( "--samplingstarttime", help="Time at which sampling begins, defaults to 1000000 steps", default="1000000") args = parser.parse_args() simconfig = utils.TreeStructuredConfiguration(args.configuration) if args.debug == '1': log.basicConfig(level=log.DEBUG, format='%(asctime)s %(levelname)s: %(message)s') else: log.basicConfig(level=log.INFO, format='%(asctime)s %(levelname)s: %(message)s') log.debug("experiment name: %s", args.experiment) data.set_experiment_name(args.experiment) data.set_database_hostname(args.dbhost) data.set_database_port(args.dbport) config = data.getMingConfiguration(data.modules) ming.configure(**config) if args.swrewiring: simconfig.ws_rewiring = float(args.swrewiring) simconfig.popsize = int(args.popsize) simconfig.maxtraits = int(args.maxinittraits) simconfig.learning_rate = float(args.learningrate) simconfig.num_trees = int(args.numtraittrees) simconfig.branching_factor = float(args.branchingfactor) simconfig.depth_factor = float(args.depthfactor) simconfig.loss_rate = float(args.lossrate) simconfig.innov_rate = float(args.innovrate) simconfig.maxtime = simconfig.SIMULATION_CUTOFF_TIME simconfig.script = __file__ simconfig.save_graphs = args.savetraitgraphs simconfig.sim_id = uuid.uuid4().urn if args.periodic == '1': simconfig.periodic = 1 else: simconfig.periodic = 0