Search in sources :

Example 6 with JobV3

use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.

the class GridSearchHandler method handle.

// Invoke the handler with parameters.  Can throw any exception the called handler can throw.
// TODO: why does this do its own params filling?
// TODO: why does this do its own sub-dispatch?
@Override
S handle(int version, water.api.Route route, Properties parms, String postBody) throws Exception {
    // Only here for train or validate-parms
    if (!route._handler_method.getName().equals("train"))
        throw water.H2O.unimpl();
    // Peek out the desired algo from the URL
    String[] ss = route._url.split("/");
    // {}/{99}/{Grid}/{gbm}/
    String algoURLName = ss[3];
    // gbm -> GBM; deeplearning -> DeepLearning
    String algoName = ModelBuilder.algoName(algoURLName);
    String schemaDir = ModelBuilder.schemaDirectory(algoURLName);
    // Get the latest version of this algo: /99/Grid/gbm  ==> GBMV3
    // String algoSchemaName = SchemaServer.schemaClass(version, algoName).getSimpleName(); // GBMV3
    // int algoVersion = Integer.valueOf(algoSchemaName.substring(algoSchemaName.lastIndexOf("V")+1)); // '3'
    // Ok, i'm replacing one hack with another hack here, because SchemaServer.schema*() calls are getting eliminated.
    // There probably shouldn't be any reference to algoVersion here at all... TODO: unhack all of this
    int algoVersion = 3;
    if (algoName.equals("SVD") || algoName.equals("Aggregator") || algoName.equals("StackedEnsemble"))
        algoVersion = 99;
    // TODO: this is a horrible hack which is going to cause maintenance problems:
    String paramSchemaName = schemaDir + algoName + "V" + algoVersion + "$" + ModelBuilder.paramName(algoURLName) + "V" + algoVersion;
    // Build the Grid Search schema, and fill it from the parameters
    S gss = (S) new GridSearchSchema();
    gss.init_meta();
    gss.parameters = (P) TypeMap.newFreezable(paramSchemaName);
    gss.parameters.init_meta();
    gss.hyper_parameters = new IcedHashMap<>();
    // Get default parameters, then overlay the passed-in values
    // Default parameter settings
    ModelBuilder builder = ModelBuilder.make(algoURLName, null, null);
    // Defaults for this builder into schema
    gss.parameters.fillFromImpl(builder._parms);
    // Override defaults from user parms
    gss.fillFromParms(parms);
    // Verify list of hyper parameters
    // Right now only names, no types
    // note: still use _validation_frame and and _training_frame at this point.
    // Do not change those names yet.
    validateHyperParams((P) gss.parameters, gss.hyper_parameters);
    // Get actual parameters
    MP params = (MP) gss.parameters.createAndFillImpl();
    Map<String, Object[]> sortedMap = new TreeMap<>(gss.hyper_parameters);
    // training_fame are no longer valid names.
    if (sortedMap.containsKey("validation_frame")) {
        sortedMap.put("valid", sortedMap.get("validation_frame"));
        sortedMap.remove("validation_frame");
    }
    // Get/create a grid for given frame
    // FIXME: Grid ID is not pass to grid search builder!
    Key<Grid> destKey = gss.grid_id != null ? gss.grid_id.key() : null;
    // Create target grid search object (keep it private for now)
    // Start grid search and return the schema back with job key
    Job<Grid> gsJob = GridSearch.startGridSearch(destKey, params, sortedMap, new DefaultModelParametersBuilderFactory<MP, P>(), (HyperSpaceSearchCriteria) gss.search_criteria.createAndFillImpl());
    // Fill schema with job parameters
    // FIXME: right now we have to remove grid parameters which we sent back
    gss.hyper_parameters = null;
    // TODO: looks like it's currently always 0
    gss.total_models = gsJob._result.get().getModelCount();
    gss.job = new JobV3(gsJob);
    return gss;
}
Also used : Grid(hex.grid.Grid) ModelBuilder(hex.ModelBuilder) JobV3(water.api.schemas3.JobV3)

Example 7 with JobV3

use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.

the class JobsHandler method fetch.

// called through reflection by RequestServer
@SuppressWarnings("unused")
public JobsV3 fetch(int version, JobsV3 s) {
    Key key = s.job_id.key();
    Value val = DKV.get(key);
    if (null == val)
        throw new IllegalArgumentException("Job is missing");
    Iced ice = val.get();
    if (!(ice instanceof Job))
        throw new IllegalArgumentException("Must be a Job not a " + ice.getClass());
    Job j = (Job) ice;
    s.jobs = new JobV3[1];
    // s.fillFromImpl(jobs);
    try {
        s.jobs[0] = (JobV3) SchemaServer.schema(version, j).fillFromImpl(j);
    }// no special schema for this job subclass, so fall back to JobV3
     catch (H2ONotFoundArgumentException e) {
        s.jobs[0] = new JobV3().fillFromImpl(j);
    }
    return s;
}
Also used : JobV3(water.api.schemas3.JobV3) H2ONotFoundArgumentException(water.exceptions.H2ONotFoundArgumentException)

Example 8 with JobV3

use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.

the class ParseHandler method parse.

// Entry point for parsing.
// called through reflection by RequestServer
@SuppressWarnings("unused")
public ParseV3 parse(int version, ParseV3 parse) {
    ParserInfo parserInfo = ParserService.INSTANCE.getByName(parse.parse_type).info();
    ParseSetup setup = new ParseSetup(parserInfo, parse.separator, parse.single_quotes, parse.check_header, parse.number_columns, delNulls(parse.column_names), ParseSetup.strToColumnTypes(parse.column_types), parse.domains, parse.na_strings, null, new ParseWriter.ParseErr[0], parse.chunk_size);
    if (parse.source_frames == null)
        throw new H2OIllegalArgumentException("Data for Frame '" + parse.destination_frame.name + "' is not available. Please check that the path is valid (for all H2O nodes).'");
    Key[] srcs = new Key[parse.source_frames.length];
    for (int i = 0; i < parse.source_frames.length; i++) srcs[i] = parse.source_frames[i].key();
    parse.job = new JobV3(ParseDataset.parse(parse.destination_frame.key(), srcs, parse.delete_on_done, setup, parse.blocking)._job);
    if (parse.blocking) {
        Frame fr = DKV.getGet(parse.destination_frame.key());
        parse.rows = fr.numRows();
    }
    return parse;
}
Also used : Frame(water.fvec.Frame) ParseSetup(water.parser.ParseSetup) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) ParseWriter(water.parser.ParseWriter) ParserInfo(water.parser.ParserInfo) JobV3(water.api.schemas3.JobV3) Key(water.Key)

Example 9 with JobV3

use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.

the class CreateFrameHandler method run.

public JobV3 run(int version, CreateFrameV3 cf) {
    if (cf.dest == null) {
        cf.dest = new KeyV3.FrameKeyV3();
        cf.dest.name = Key.rand();
    }
    CreateFrame cfr = new CreateFrame(cf.dest.key());
    cf.fillImpl(cfr);
    return new JobV3(cfr.execImpl());
}
Also used : KeyV3(water.api.schemas3.KeyV3) JobV3(water.api.schemas3.JobV3) CreateFrame(hex.CreateFrame)

Aggregations

JobV3 (water.api.schemas3.JobV3)8 Frame (water.fvec.Frame)3 Key (water.Key)2 KeyV3 (water.api.schemas3.KeyV3)2 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)2 H2ONotFoundArgumentException (water.exceptions.H2ONotFoundArgumentException)2 ParseSetup (water.parser.ParseSetup)2 CreateFrame (hex.CreateFrame)1 Interaction (hex.Interaction)1 ModelBuilder (hex.ModelBuilder)1 Grid (hex.grid.Grid)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 FrameV3 (water.api.schemas3.FrameV3)1 JobKeyV3 (water.api.schemas3.KeyV3.JobKeyV3)1 H2OKeyNotFoundArgumentException (water.exceptions.H2OKeyNotFoundArgumentException)1 ParseWriter (water.parser.ParseWriter)1 ParserInfo (water.parser.ParserInfo)1