@Override
  public List<String> getCallString(String path) {
    List<String> args = new ArrayList<String>();
    args.add(Util.getJavaExecutable());
    args.add("-Xmx256m");
    args.add("-cp");
    args.add(Util.getAbsoluteClasspath());
    args.add("autoweka.randomsearch.RandomSearchWorker");
    args.add(mExperiment.name + ".experiment");
    args.add("{SEED}");

    return args;
  }
  public void prepareExperiment(String path) {
    try {
      // Print out the param file
      printParamFile(new PrintStream(new java.io.File(path + "autoweka.params")));

      autoweka.Util.makePath(path + "out");
    } catch (Exception e) {
      throw new RuntimeException("Failed to prepare the experiment", e);
    }
  }
 public void actionPerformed(ActionEvent e) {
   mFileChooser.setDialogTitle("Predictions CSV");
   mFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
   mFileChooser.setSelectedFile(new File("predictions.csv"));
   mFileChooser.setFileFilter(null);
   if (UIUtil.runFileChooser(mFileChooser, mParent, null, "lastPredictionLocation")
       == JFileChooser.APPROVE_OPTION) {
     // Time to copy the predictions
     autoweka.Util.copyFile(mOutputFile, mFileChooser.getSelectedFile());
   }
 };
示例#4
0
  /**
   * Calls the SubProcessWrapper as a SubProcess, and returns the result back up to the caller.
   *
   * <p>This method is super useful to ensure that leaking doesn't happen/memory limits are
   * enforced, since all the work is done in a subprocess - if anything bad happens, it dies down
   * there, letting your process carry on willy nilly
   *
   * @param runDir The run directory.
   * @param memory The memory limit.
   * @param props The properties.
   * @param trainTimeout The timeout for training.
   * @param instance The instance.
   * @param args The arguments.
   * @param autowekaSeed The seed.
   * @return The error and time.
   */
  public static ErrorAndTime getErrorAndTime(
      File runDir,
      String memory,
      Properties props,
      float trainTimeout,
      String instance,
      String args,
      String autowekaSeed) {
    try {
      List<String> wrapperCmd = new ArrayList<String>();
      wrapperCmd.add(autoweka.Util.getJavaExecutable());
      wrapperCmd.add("-Xmx" + memory);
      wrapperCmd.add("-cp");
      wrapperCmd.add(autoweka.Util.getAbsoluteClasspath());
      wrapperCmd.add("autoweka.SubProcessWrapper");
      wrapperCmd.add("-prop");
      wrapperCmd.add(Util.propertiesToString(props));
      wrapperCmd.add("-timeout");
      wrapperCmd.add(Float.toString(trainTimeout));
      wrapperCmd.add("-wrapper");
      wrapperCmd.add(instance);
      wrapperCmd.addAll(Arrays.asList(args.split(" ")));

      for (String c : wrapperCmd) log.debug("{}", c);

      ProcessBuilder pb = new ProcessBuilder(wrapperCmd);
      pb.environment().put("AUTOWEKA_EXPERIMENT_SEED", autowekaSeed);
      if (runDir != null) pb.directory(runDir);
      pb.redirectErrorStream(true);
      Process proc = pb.start();

      // Register a shutdown hook
      Thread killerHook = new Util.ProcessKillerShutdownHook(proc);
      Runtime.getRuntime().addShutdownHook(killerHook);

      String prevLine = null;
      String line;
      BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));

      float error = 0;
      float time = 0;
      boolean foundMatch = false;

      while ((line = reader.readLine()) != null) {
        // fix nested logging...
        if (line.matches(".*DEBUG.*")) {
          log.debug(line);
        } else if (line.matches(".*WARN.*")) {
          log.warn(line);
        } else if (line.matches(".*ERROR.*")) {
          log.error(line);
        } else {
          log.info(line);
        }
        Matcher matcher = mResultPattern.matcher(line);
        if (matcher.matches()) {
          time = Float.parseFloat(matcher.group(1));
          error = Float.parseFloat(matcher.group(2));
          foundMatch = true;
        }
      }
      proc.waitFor();
      if (!foundMatch)
        throw new RuntimeException("Failed to find output line from subprocess wrapper");

      Runtime.getRuntime().removeShutdownHook(killerHook);

      return new ErrorAndTime(error, time);
    } catch (Exception e) {
      throw new RuntimeException("Failed to invoke child process", e);
    }
  }