load q table from model_file
776186
def loadModel(self, model_file):
        """"""
        with open(model_file) as f:
            self.q_table = json.load(f)
348493
def load(self, model):
        """"""
        self._dawg.load(find_data(model))
        self._loaded_model = True
964697
def import_model(self, source):
        """"""
        if not hasattr(source, 'read'):  # Not a File-like object
            with open(self._resolve_source(source), 'r') as f:
                return self._import(f)
        else:
            return self._import(source)
288919
def load(config_path, run_number=0, device='cuda:0'):
    
    model_config = ModelConfig.from_file(config_path, run_number, device=device)

    return model_config
736166
public final void loadSqlTables() throws Exception {
    for (Class<?> clazz : this.mngSettings.getClasses()) {
      TableSql tableSql = new TableSql();
      makeTableSqlFromXml(tableSql, clazz);
      this.tablesMap.put(clazz.getSimpleName(), tableSql);
    }
    for (Class<?> clazz : this.mngSettings.getClasses()) {
      TableSql tableSql = this.tablesMap.get(clazz.getSimpleName());
      StringBuffer sbIdNamesUc = new StringBuffer("");
      for (int i = 0; i < tableSql.getIdColumnsNames().length; i++) {
        if (i > 0) {
          sbIdNamesUc.append(",");
        }
        sbIdNamesUc.append(tableSql.getIdColumnsNames()[i].toUpperCase());
      }
      Field[] fields = getUtlReflection().retrieveFields(clazz);
      for (Field field : fields) {
        FieldSql fieldSql = tableSql.getFieldsMap().get(field.getName());
        if (fieldSql != null) { //if persistable or composite (foreign CID)
          String fldTypeSmpNm = field.getType().getSimpleName();
          try {
            TableSql tableSqlForeign = this.tablesMap.get(fldTypeSmpNm);
            if (tableSqlForeign != null) {
              //if it's foreign entity according entities list ORDER
              //make sure ORDER of entities!!!
              fieldSql.setForeignEntity(fldTypeSmpNm);
              String isNullableStr = this.mngSettings
                .lazFldSts(clazz, field.getName()).get("isNullable");
              if (fieldSql.getDefinition() != null // FK composite ID
                && !Boolean.valueOf(isNullableStr)
                  && !fieldSql.getDefinition().contains("not null")) {
                fieldSql.setDefinition(fieldSql.getDefinition() + " not null");
              }
              //FK:
              StringBuffer sbForeignIdNamesUc = new StringBuffer("");
              for (int i = 0; i < tableSqlForeign.getIdColumnsNames()
                .length; i++) {
                if (i > 0) {
                  sbForeignIdNamesUc.append(",");
                }
                sbForeignIdNamesUc.append(tableSqlForeign
                  .getIdColumnsNames()[i].toUpperCase());
              }
              String fkNames;
              if (tableSqlForeign.getIdColumnsNames().length > 1) {
                // composite FK:
                fkNames = sbForeignIdNamesUc.toString();
                // check if it is also primary key:
                boolean isAlsoPk = true;
                if (tableSql.getIdColumnsNames().length
                  == tableSqlForeign.getIdColumnsNames().length) {
                  for (int i = 0; i < tableSql.getIdColumnsNames()
                    .length; i++) {
                    if (!tableSqlForeign.getIdColumnsNames()[0]
                      .equals(tableSql.getIdColumnsNames()[0])) {
                      isAlsoPk = false;
                      break;
                    }
                  }
                }
                if (isAlsoPk) {
                  fieldSql.setTypeField(ETypeField.COMPOSITE_FK_PK);
                } else {
                  fieldSql.setTypeField(ETypeField.COMPOSITE_FK);
                }
                for (String cIdNm : tableSqlForeign.getIdColumnsNames()) {
                  FieldSql fldCid = new FieldSql();
                  fldCid.setTypeField(ETypeField.DERIVED_FROM_COMPOSITE);
                  if (!Boolean.valueOf(isNullableStr)
                      && !tableSqlForeign.getFieldsMap()
                        .get(cIdNm).getDefinition().contains("not null")) {
                    fldCid.setDefinition(tableSqlForeign.getFieldsMap()
                      .get(cIdNm).getDefinition() + " not null");
                  } else if (Boolean.valueOf(isNullableStr)
                      && fldCid.getDefinition().contains("not null")) {
                    fldCid.setDefinition(tableSqlForeign.getFieldsMap()
                      .get(cIdNm).getDefinition().replace(" not null", ""));
                  } else {
                    fldCid.setDefinition(tableSqlForeign.getFieldsMap()
                      .get(cIdNm).getDefinition());
                  }
                  fldCid.setForeignEntity(tableSqlForeign.getFieldsMap()
                    .get(cIdNm).getForeignEntity());
                  tableSql.getFieldsMap().put(cIdNm, fldCid);
                }
              } else {
                fkNames = field.getName().toUpperCase();
                if (fieldSql.getDefinition() == null) {
                  throw new ExceptionWithCode(ExceptionWithCode
                    .CONFIGURATION_MISTAKE,
                      "Where is no definition FID class/name: "
                        + clazz.getSimpleName() + "/" + field.getName());
                }
              }
              int hc = fldTypeSmpNm.hashCode();
              String hashCfesn;
              if (hc < 0) {
                hc = -hc;
                hashCfesn = "M" + hc;
              } else {
                hashCfesn = String.valueOf(hc);
              }

              String constraintFk = "constraint fk"
                + clazz.getSimpleName()
                + hashCfesn + field.getName()
                + " foreign key (" + fkNames
                + ") references " + fldTypeSmpNm.toUpperCase()
                + " (" + sbForeignIdNamesUc + ")";
              String constraint = tableSql.getConstraint();
              if (constraint != null) {
                constraint += ",\n" + constraintFk;
              } else {
                constraint = constraintFk;
              }
              tableSql.setConstraint(constraint);
            }
            //if field is PK, make sure NOT NULL:
            if (sbIdNamesUc.toString().contains(field.getName().toUpperCase())
                && !fieldSql.getDefinition().contains("not null")) {
              fieldSql.setDefinition(fieldSql.getDefinition()
                + " not null");
            }
          } catch (Exception e) {
            this.logger.error(null, ASrvOrm.class, "Error on load SQL tables:"
              + " class/field/fieldSql/tableSql - " + clazz.getSimpleName()
                + "/" + field.getName() + "/" + fieldSql + "/" + tableSql);
            throw e;
          }
        }
      }
      try {
        for (String colIdNm : tableSql.getIdColumnsNames()) {
          if (tableSql.getFieldsMap().get(colIdNm) == null) {
          throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
            "Where is no column ID class/name: " + clazz.getSimpleName()
              + "/" + colIdNm);
          }
        }
        //PK if complex (composite or foreign entity):
        if (tableSql.getIdColumnsNames().length > 1 || tableSql.getFieldsMap()
          .get(tableSql.getIdColumnsNames()[0]).getForeignEntity() != null) {
          String constraintPk = "constraint pk"
            + clazz.getSimpleName() + tableSql.getIdColumnsNames()[0]
              + " primary key (" + sbIdNamesUc + ")";
          if (tableSql.getConstraint() == null) {
            tableSql.setConstraint(constraintPk);
          } else {
            tableSql.setConstraint(constraintPk
              + ",\n" + tableSql.getConstraint());
          }
        }
        String constraintAdd = this.mngSettings.lazClsSts(clazz)
          .get("constraintAdd");
        if (constraintAdd != null) {
          if (tableSql.getConstraint() == null) {
            tableSql.setConstraint(constraintAdd);
          } else {
            tableSql.setConstraint(tableSql.getConstraint()
              + ",\n" + constraintAdd);
          }
        }
      } catch (Exception e) {
        this.logger.error(null, ASrvOrm.class, "Error on load SQL tables:"
          + " class/tableSql - " + clazz.getSimpleName() + "/" + tableSql);
        throw e;
      }
    }
  }
607136
def load_params_from_file(self, fname: str):
        
        utils.check_condition(os.path.exists(fname), "No model parameter file found under %s. "
                                                     "This is either not a model directory or the first training "
                                                     "checkpoint has not happened yet." % fname)
        self.params, self.aux_params = utils.load_params(fname)
        utils.check_condition(all(name.startswith(self.prefix) for name in self.params.keys()),
                              "Not all parameter names start with model prefix '%s'" % self.prefix)
        utils.check_condition(all(name.startswith(self.prefix) for name in self.aux_params.keys()),
                              "Not all auxiliary parameter names start with model prefix '%s'" % self.prefix)
        logger.info('Loaded params from "%s"', fname)
831911
def import_items(item_seq, dest_model,  batch_len=500, 
                 clear=False, dry_run=True, 
                 start_batch=0, end_batch=None, 
                 overwrite=True,
                 run_update=False, ignore_related=True,
                 ignore_errors=False, verbosity=1):
    
    if isinstance(dest_model, (djmodels.query.QuerySet, djmodels.Manager)):
        dest_qs = dest_model.all()
        dest_model = get_model(dest_qs)
    else:
        dest_qs = dest_model.objects.all()

    stats = collections.Counter()
    try:
        try:
            src_qs = item_seq.objects.all()
        except AttributeError:
            src_qs = item_seq.all()
        N = src_qs.count()
        item_seq = src_qs.values()
    except AttributeError as e:
        print_exc()
        if not ignore_errors:
            raise e
        N = len(item_seq)

    if not N:
        if verbosity > 0:
            print 'No records found in %r' % src_qs
        return N

    # make sure there's a valid last batch number so the verbose messages will make sense
    end_batch = end_batch or int(N / float(batch_len))

    if clear and not dry_run:
        if N < dest_qs.count():
            if verbosity > 0:
                print "WARNING: There are %d %r records in the destinsation queryset which is more than the %d records in the source data. So no records will be deleted/cleared in the destination!" % (dest_qs.count(), dest_model, N)

        if verbosity > 0:
            print "WARNING: Deleting %d records from %r to make room for %d new records !!!!!!!" % (dest_qs.count(), dest_model, N)
        num_deleted = delete_in_batches(dest_qs)
        if verbosity > 0:
            print "Finished deleting %d records in %r." % (num_deleted, dest_model)

    if verbosity > 0:
        print('Loading %r records from sequence provided...' % N)
        widgets = [pb.Counter(), '/%d rows: ' % N or 1, pb.Percentage(), ' ', pb.RotatingMarker(), ' ', pb.Bar(),' ', pb.ETA()]
        pbar = pb.ProgressBar(widgets=widgets, maxval=N)

    for batch_num, dict_batch in enumerate(util.generate_slices(item_seq, batch_len=batch_len, start_batch=start_batch)):
        if start_batch + batch_num > end_batch:
            if verbosity > 1:
                print('Stopping before batch {0} because it is not between {1} and {2}'.format(start_batch + batch_num, start_batch, end_batch))
            break
        if verbosity > 2:
            print '-------- dict batch ------'
            # print(repr(dict_batch))
            print(repr((start_batch + batch_num, len(dict_batch), batch_len)))
        item_batch = []
        total_len_batches = 0

        # convert an iterable of Django ORM record dictionaries into a list of Django ORM objects
        for d in dict_batch:
            if verbosity > 2:
                print '-------- dict of source obj ------'
                print(repr(d))
            obj = dest_model()
            try:
                # if the model has an import_item method then use it
                obj.import_item(d, verbosity=verbosity)
            except:
                if verbosity > 2:
                    print '------ Creating a new %r instance --------' % dest_model
                obj, row_errors = django_object_from_row(d, dest_model, ignore_related=ignore_related, verbosity=verbosity)
                if verbosity > 2:
                    print 'new obj.__dict__: %r' % obj.__dict__
            if run_update:
                try:
                    if verbosity > 2:
                        print '------ Updating FKs with overwrite=%r --------' % overwrite
                    obj._update(save=False, overwrite=overwrite)
                except:
                    if verbosity > 0:
                        print_exc()
                        print 'ERROR: Unable to update record: %r' % obj
                    pass
            item_batch += [obj]
            stats += row_errors

        del(dict_batch)
        if verbosity and verbosity < 2:
            if batch_num:
                pbar.update(batch_num * batch_len + len(item_batch))
            else:
                # don't start the progress bar until at least one batch has been loaded
                pbar.start()
        elif verbosity > 1:
            print('Writing {0} items (of type {1}) from batch {2}. Will stop at batch {3} which is record {4} ...'.format(
                len(item_batch), dest_model, start_batch + batch_num, end_batch, min(batch_len * (start_batch + end_batch), N),
                ))
        total_len_batches += len(item_batch)

        # use bulk_create to make fast DB insertions. Note: any custom save() or _update() methods will *NOT* be run
        if not dry_run:
            try:
                dest_model.objects.bulk_create(item_batch)
            except UnicodeDecodeError as err:
                from django.db import transaction
                transaction.rollback()
                if verbosity > 0:
                    print '%s' % err
                    print 'Now attempting to save objects one at a time instead of as a batch...'
                for obj in item_batch:
                    try:
                        obj.save()
                        stats += collections.Counter(['batch_UnicodeDecodeError'])
                    except:
                        from django.db import transaction
                        transaction.rollback()
                        stats += collections.Counter(['save_UnicodeDecodeError'])
                        print str(obj)
                        print repr(obj.__dict__)
                if not ignore_errors:
                    print_exc()
                    raise
            except Exception as err:
                from django.db import transaction
                transaction.rollback()
                if verbosity > 0:
                    print '%s' % err
                    print 'Now attempting to save objects one at a time instead of as a batch...'
                for obj in item_batch:
                    try:
                        obj.save()
                        stats += collections.Counter(['batch_Error'])
                    except:
                        from django.db import transaction
                        transaction.rollback()
                        print str(obj)
                        print repr(obj.__dict__)
                        print_exc()
                        stats += collections.Counter(['save_Error'])
                if not ignore_errors:
                    print_exc()
                    raise
        if batch_num < end_batch:
            if len(item_batch) != batch_len:
                stats += collections.Counter(['batch_len={0}'.format(len(item_batch))])
            print('Retrieving {0} {1} items for the next batch, batch number {2}...'.format(
                  batch_len, src_qs.model, batch_num + 1))
        del(item_batch)

    if verbosity > 0:
        pbar.finish()
    return stats
660626
def load_model(f, format=None, load_external_data=True):  # type: (Union[IO[bytes], Text], Optional[Any], bool) -> ModelProto
    '''
    
    '''
    s = _load_bytes(f)
    model = load_model_from_string(s, format=format)

    if load_external_data:
        model_filepath = _get_file_path(f)
        if model_filepath:
            base_dir = os.path.dirname(model_filepath)
            load_external_data_for_model(model, base_dir)

    return model
1215487
def load(self, modelfile, layer=None):
        
        # read modelfile, convert JSON and load/update model
        self.param_file = modelfile
        self._load(layer)
        self._update(layer)
809535
def loadValues(self, values):
        
        table = self.tableType()
        if table:
            schema = table.schema()
        else:
            schema = None
        
        process = []
        for widget in self.findChildren(QWidget):
            prop = widget.property('columnName')
            if not prop:
                continue
            
            order = widget.property('columnOrder')
            if order:
                order = unwrapVariant(order)
            else:
                order = 10000000
            
            process.append((order, widget, prop))
        
        process.sort()
        for order, widget, prop in process:
            columnName = nativestring(unwrapVariant(prop, ''))
            
            if not columnName:
                continue
            
            if isinstance(widget, XEnumBox) and schema:
                column = schema.column(columnName)
                if column.enum() is not None:
                    widget.setEnum(column.enum())
            
            if columnName in values:
                projexui.setWidgetValue(widget, values.get(columnName))
638856
def load(self, filename, fv_extern=None):
        
        self.modelparams["mdl_stored_file"] = filename
        if fv_extern is not None:
            self.modelparams["fv_extern"] = fv_extern

        # segparams['modelparams'] = {
        #     'mdl_stored_file': mdl_stored_file,
        #     # 'fv_extern': fv_function
        # }
        self.mdl = Model(modelparams=self.modelparams)
511512
def populate_table(self, scenario_directory):
        
        parsed_files = []
        unparsed_files = []
        self.table.clearContents()

        # Block signal to allow update checking only when the table is ready
        self.table.blockSignals(True)
        # NOTE(gigih): need this line to remove existing rows
        self.table.setRowCount(0)

        if not os.path.exists(scenario_directory):
            # LOGGER.info('Scenario directory does not exist: %s' % path)
            return

        # only support .py and .txt files
        for current_path in os.listdir(scenario_directory):
            extension = os.path.splitext(current_path)[1]
            absolute_path = os.path.join(scenario_directory, current_path)

            if extension == '.py':
                append_row(self.table, current_path, absolute_path)
            elif extension == '.txt':
                # insert scenarios from file into table widget
                try:
                    scenarios = read_scenarios(absolute_path)
                    validate_scenario(scenarios, scenario_directory)
                    for key, value in list(scenarios.items()):
                        append_row(self.table, key, value)
                    parsed_files.append(current_path)
                except Error:
                    unparsed_files.append(current_path)

        # unblock signal
        self.table.blockSignals(False)
432496
def load_object(self, kwargs):
        """"""
        self.object = None
        self.config = None
        self.model = self.get_model_class()
        kwargs.pop('app', None)
        kwargs.pop('model', None)

        if self.model and kwargs.get('pk', False):
            try:
                self.object = self.model.objects.get(pk=kwargs.pop('pk'))
            except Exception:
                raise Exception("Could not load {}".format(self.model.__name__.lower()))
            setattr(self, self.model.__name__.lower(), self.object)

        return kwargs
905995
def load_model(model_file):
    
    # Extract tar
    with tarfile.open(model_file) as tar:
        tarfolder = tempfile.mkdtemp()
        tar.extractall(path=tarfolder)

    from . import features
    from . import preprocessing

    # Get the preprocessing
    with open(os.path.join(tarfolder, "preprocessing.yml"), 'r') as ymlfile:
        preprocessing_description = yaml.load(ymlfile)
    preprocessing_queue = preprocessing.get_preprocessing_queue(
        preprocessing_description['queue'])

    # Get the features
    with open(os.path.join(tarfolder, "features.yml"), 'r') as ymlfile:
        feature_description = yaml.load(ymlfile)
    feature_str_list = feature_description['features']
    feature_list = features.get_features(feature_str_list)

    # Get the model
    import nntoolkit.utils
    model = nntoolkit.utils.get_model(model_file)

    output_semantics_file = os.path.join(tarfolder, 'output_semantics.csv')
    output_semantics = nntoolkit.utils.get_outputs(output_semantics_file)

    # Cleanup
    shutil.rmtree(tarfolder)

    return (preprocessing_queue, feature_list, model, output_semantics)
1122858
def load_table(self, table, rows, colnames=None, limit=None):
        

        conn = self.engine.raw_connection()
        cur = conn.cursor()

        colnames = colnames or next(rows)

        cmd = 'INSERT INTO {table} ({colnames}) VALUES ({placeholders})'.format(
            table=self.tables[table],
            colnames=', '.join(colnames),
            placeholders=', '.join([self.placeholder] * len(colnames)))

        cur.executemany(cmd, itertools.islice(rows, limit))
        conn.commit()
569129
def _export_model(models):
    
    logger_jsons.info("enter export_model")
    _models = []
    try:
        for name, model in models.items():

            if "summaryTable" in model:
                model["summaryTable"] = _idx_table_by_num(model["summaryTable"])

            # Process ensemble table (special two columns)
            if "ensembleTable" in model:
                model["ensembleTable"] = _idx_table_by_num(model["ensembleTable"])

            if "distributionTable" in model:
                model["distributionTable"] = _idx_table_by_num(model["distributionTable"])

            _models.append(model)

    except Exception as e:
        logger_jsons.error("export_model: {}".format(e))
        print("Error: export_model: {}".format(e))
    logger_jsons.info("exit export_model")
    return _models
839139
def load_model(self, fname):
        
        if isinstance(fname, STRING_TYPES):  # assume file name
            if os.path.exists(fname):
                _LIB.XGBoosterLoadModel(self.handle, c_str(fname))
            else:
                raise ValueError("No such file: {0}".format(fname))
        else:
            buf = fname
            length = ctypes.c_ulong(len(buf))
            ptr = (ctypes.c_char * len(buf)).from_buffer(buf)
            _check_call(_LIB.XGBoosterLoadModelFromBuffer(self.handle, ptr, length))