Returns the ID for the given run, creating the row if needed.

    Args:
      experiment_name: name of experiment containing this run.
      run_name: name of run.
772476
def _maybe_init_run(self, experiment_name, run_name):
    
    experiment_id = self._maybe_init_experiment(experiment_name)
    cursor = self._db.cursor()
    cursor.execute(
        """
        SELECT run_id FROM Runs
        WHERE experiment_id = ? AND run_name = ?
        """,
        (experiment_id, run_name))
    row = cursor.fetchone()
    if row:
      return row[0]
    run_id = self._create_id()
    # TODO: track actual run start times
    started_time = 0
    cursor.execute(
        """
        INSERT INTO Runs (
          experiment_id, run_id, run_name, inserted_time, started_time
        ) VALUES (?, ?, ?, ?, ?)
        """,
        (experiment_id, run_id, run_name, time.time(), started_time))
    return run_id
446415
def update_experiment(self, id, key, value):
        ''''''
        if id not in self.experiments:
            return False
        self.experiments[id][key] = value
        self.write_file()
        return True
1036707
def create_experiment_fn(*args, **kwargs):
  """"""

  def experiment_fn(run_config, hparams):
    return create_experiment(run_config, hparams, *args, **kwargs)

  return experiment_fn
101563
def get_forced_variation(self, experiment_key, user_id):
    

    if user_id not in self.forced_variation_map:
      self.logger.debug('User "%s" is not in the forced variation map.' % user_id)
      return None

    experiment = self.get_experiment_from_key(experiment_key)
    if not experiment:
      # The invalid experiment key will be logged inside this call.
      return None

    experiment_to_variation_map = self.forced_variation_map.get(user_id)

    if not experiment_to_variation_map:
      self.logger.debug('No experiment "%s" mapped to user "%s" in the forced variation map.' % (
        experiment_key,
        user_id
      ))
      return None

    variation_id = experiment_to_variation_map.get(experiment.id)
    if variation_id is None:
      self.logger.debug(
        'No variation mapped to experiment "%s" in the forced variation map.' % experiment_key
      )
      return None

    variation = self.get_variation_from_id(experiment_key, variation_id)

    self.logger.debug('Variation "%s" is mapped to experiment "%s" and user "%s" in the forced variation map' % (
      variation.key,
      experiment_key,
      user_id
    ))
    return variation
1161734
def persist_experiment(experiment):
    
    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = experiment.id
    LOG.debug("Using experiment ID stored in config: %s", cfg_exp)
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = str(CFG["experiment_description"])
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
    else:
        exps.update({'name': name, 'description': desc})
        ret = exps.first()

    try:
        session.commit()
    except IntegrityError:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)
1249179
def print_runs(query):
    

    if query is None:
        return

    for tup in query:
        print(("{0} @ {1} - {2} id: {3} group: {4}".format(
            tup.end, tup.experiment_name, tup.project_name,
            tup.experiment_group, tup.run_group)))
87344
public static void onApptimizeExperimentRun(String experimentName,
												String variantName,
												boolean firstRun) {
		// TODO: update specific experiment only
		dispatchConversationTask(new ConversationDispatchTask() {
			@Override
			protected boolean execute(Conversation conversation) {
				ApptentiveInternal instance = ObjectUtils.as(ApptentiveInternal.getInstance(), ApptentiveInternal.class);
				if (instance != null) {
					instance.tryUpdateApptimizeData();
					return true;
				}

				return false;
			}
		}, "update Apptimize experiment data");
	}
381415
def get_runs(project_name):
    
    conn, c = open_data_base_connection()
    try:
        c.execute("""SELECT run_name FROM {}""".format(project_name + "_run_table"))
        run_names = np.array(c.fetchall()).squeeze(axis=1)
        run_names = convert_list_to_dict(run_names)
        return run_names
    except sqlite3.OperationalError:
        logging.info("{} not found".format(run_name))
    finally:
        conn.close()
302859
def rename_experiment(self, new_name):
        '''
        '''
        logger.info('rename experiment "%s"', self.experiment_name)
        content = {'name': new_name}
        url = self._build_api_url(
            '/experiments/{experiment_id}'.format(
                experiment_id=self._experiment_id
            )
        )
        res = self._session.put(url, json=content)
        res.raise_for_status()
        self.experiment_name = new_name
989086
def get_id(test):
    
    test_id = test.id()
    module_length = len(test.test.__module__)
    return test_id[:module_length] + ":" + test_id[module_length + 1:]
1080993
def status(id):
    
    if id:
        try:
            experiment = ExperimentClient().get(normalize_job_name(id))
        except FloydException:
            experiment = ExperimentClient().get(id)

        print_experiments([experiment])
    else:
        experiments = ExperimentClient().get_all()
        print_experiments(experiments)
915162
def info(job_name_or_id):
    
    try:
        experiment = ExperimentClient().get(normalize_job_name(job_name_or_id))
    except FloydException:
        experiment = ExperimentClient().get(job_name_or_id)

    task_instance_id = get_module_task_instance_id(experiment.task_instances)
    task_instance = TaskInstanceClient().get(task_instance_id) if task_instance_id else None
    normalized_job_name = normalize_job_name(experiment.name)
    table = [["Job name", normalized_job_name],
             ["Created", experiment.created_pretty],
             ["Status", experiment.state], ["Duration(s)", experiment.duration_rounded],
             ["Instance", experiment.instance_type_trimmed],
             ["Description", experiment.description],
             ["Metrics", format_metrics(experiment.latest_metrics)]]
    if task_instance and task_instance.mode in ['jupyter', 'serving']:
        table.append(["Mode", task_instance.mode])
        table.append(["Url", experiment.service_url])
    if experiment.tensorboard_url:
        table.append(["TensorBoard", experiment.tensorboard_url])
    floyd_logger.info(tabulate(table))
618668
def show_experiment_info():
    ''''''
    experiment_config = Experiments()
    experiment_dict = experiment_config.get_all_experiments()
    if not experiment_dict:
        print('There is no experiment running...')
        exit(1)
    update_experiment()
    experiment_id_list = []
    for key in experiment_dict.keys():
        if experiment_dict[key]['status'] != 'STOPPED':
            experiment_id_list.append(key)
    if not experiment_id_list:
        print_warning('There is no experiment running...')
        return
    for key in experiment_id_list:
        print(EXPERIMENT_MONITOR_INFO % (key, experiment_dict[key]['status'], experiment_dict[key]['port'], \
             experiment_dict[key].get('platform'), experiment_dict[key]['startTime'], get_time_interval(experiment_dict[key]['startTime'], experiment_dict[key]['endTime'])))
        print(TRIAL_MONITOR_HEAD)
        running, response = check_rest_server_quick(experiment_dict[key]['port'])
        if running:
            response = rest_get(trial_jobs_url(experiment_dict[key]['port']), REST_TIME_OUT)
            if response and check_response(response):
                content = json.loads(response.text)
                for index, value in enumerate(content):
                    content[index] = convert_time_stamp_to_date(value)
                    print(TRIAL_MONITOR_CONTENT % (content[index].get('id'), content[index].get('startTime'), content[index].get('endTime'), content[index].get('status')))
        print(TRIAL_MONITOR_TAIL)
850072
def get_experiment_image_info(experiment: 'Experiment') -> Tuple[str, str]:
    """"""
    project_name = experiment.project.name
    repo_name = project_name

    image_name = '{}/{}'.format(conf.get('REGISTRY_URI'), repo_name)
    image_tag = experiment.code_reference.commit
    return image_name, image_tag
992033
def select_variant(experiment)
      # starts off at 0
      accum = 0.0
      sample = Kernel.rand

      # go through our experiments and return the variation that matches
      # our random value
      experiment.variations.each_with_index do |variation, i|

        # we want to record the index in the array for this variation
        variation.index = i
        variation.experiment_id = experiment.id

        # add the variation's weight to accum
        accum += variation.weight

        # return the variation if accum is more than our random value
        if sample <= accum
          return variation
        end
      end
      # default to nil
      return nil
    end
659129
def get_cycles(self):
        '''
        '''
        logger.info('get cycles of experiment "%s"', self.experiment_name)
        url = self._build_api_url(
            '/experiments/{experiment_id}/cycles'.format(
                experiment_id=self._experiment_id
            )
        )
        res = self._session.get(url)
        res.raise_for_status()
        return res.json()['data']
1372839
def _compute_experiment_from_runs(self):
    """"""
    hparam_infos = self._compute_hparam_infos()
    if not hparam_infos:
      return None
    metric_infos = self._compute_metric_infos()
    return api_pb2.Experiment(hparam_infos=hparam_infos,
                              metric_infos=metric_infos)