/** @param f */ void loadParameters(File f) { try { parameters = new ParameterDatabase(f, clArgs); } catch (FileNotFoundException ex) { Output.initialError( "A File Not Found Exception was generated upon " + "reading the parameter file \"" + f.getPath() + "\".\nHere it is:\n" + ex); } catch (IOException ex) { Output.initialError( "An IO Exception was generated upon reading the " + "parameter file \"" + f.getPath() + "\".\nHere it is:\n" + ex); } if (parameters == null) { Output.initialError("No parameter file was loaded"); } else { paramPanel.loadParameters(); conPanel.loadParameters(); } }
void restoreFromCheckpoint(File checkpoint) { try { state = Checkpoint.restoreFromCheckpoint(checkpoint.getCanonicalPath()); parameters = state.parameters; paramPanel.loadParameters(); conPanel.loadParameters(); paused = true; setStep(false); spawnPlayThread(true); stopButton.setEnabled(true); } catch (OptionalDataException e) { Output.initialError( "A ClassNotFoundException was generated upon" + "starting up from a checkpoint." + "\nHere it is:\n" + e); } catch (ClassNotFoundException e) { Output.initialError( "A ClassNotFoundException was generated upon" + "starting up from a checkpoint." + "\nHere it is:\n" + e); } catch (IOException e) { Output.initialError( "An IO Exception was generated upon" + "starting up, probably in setting up a log" + "\nHere it is:\n" + e); } }
/** * @return * @throws BadParameterException */ Output initializeOutput() throws BadParameterException { // 1. create the output // boolean store = parameters.getBoolean(new Parameter(Evolve.P_STORE),null,false); int verbosity = parameters.getInt(new Parameter(Evolve.P_VERBOSITY), null, 0); if (verbosity < 0) Output.initialError( "Verbosity should be an integer >= 0.\n", new Parameter(Evolve.P_VERBOSITY)); Output output = new Output(true, verbosity); // output.setFlush( // parameters.getBoolean(new Parameter(Evolve.P_FLUSH),null,false)); // stdout is always log #0. stderr is always log #1. // stderr accepts announcements, and both are fully verbose // by default. output.addLog(ec.util.Log.D_STDOUT, Output.V_VERBOSE, false); output.addLog(ec.util.Log.D_STDERR, Output.V_VERBOSE, true); output.systemMessage(Version.message()); return output; }
public static void main(ParameterDatabase parameters) { EvolutionState state; // ParameterDatabase parameters; ParameterDatabase original = (ParameterDatabase) deepClone(parameters); int currentJob = 0; // the next job number (0 by default) // parameters = loadParameterDatabase(args); if (currentJob == 0) // no current job number yet currentJob = parameters.getIntWithDefault(new Parameter("current-job"), null, 0); if (currentJob < 0) Output.initialError( "The 'current-job' parameter must be >= 0 (or not exist, which defaults to 0)"); int numJobs = parameters.getIntWithDefault(new Parameter("jobs"), null, 1); if (numJobs < 1) Output.initialError("The 'jobs' parameter must be >= 1 (or not exist, which defaults to 1)"); // Now we know how many jobs remain. Let's loop for that many jobs. Each time we'll // load the parameter database scratch (except the first time where we reuse the one we // just loaded a second ago). The reason we reload from scratch each time is that the // experimenter is free to scribble all over the parameter database and it'd be nice to // have everything fresh and clean. It doesn't take long to load the database anyway, // it's usually small. for (int job = currentJob; job < numJobs; job++) { // We used to have a try/catch here to catch errors thrown by this job and continue to the // next. // But the most common error is an OutOfMemoryException, and printing its stack trace would // just create another OutOfMemoryException! Which dies anyway and has a worthless stack // trace as a result. // try { // load the parameter database (reusing the very first if it exists) if (parameters == null) parameters = (ParameterDatabase) deepClone(original); // parameters = loadParameterDatabase(args); // Initialize the EvolutionState, then set its job variables state = initialize(parameters, job); // pass in job# as the seed increment state.output.systemMessage("Job: " + job); state.job = new Object[1]; // make the job argument storage state.job[0] = Integer.valueOf(job); // stick the current job in our job storage // state.runtimeArguments = args; // stick the runtime // arguments in our storage if (numJobs > 1) // only if iterating (so we can be backwards-compatible), { String jobFilePrefix = "job." + job + "."; state.output.setFilePrefix(jobFilePrefix); // add a prefix for checkpoint/output files state.checkpointPrefix = jobFilePrefix + state.checkpointPrefix; // also set up checkpoint prefix } // Here you can set up the EvolutionState's parameters further before it's setup(...). // This includes replacing the random number generators, changing values in // state.parameters, // changing instance variables (except for job and runtimeArguments, please), etc. // now we let it go state.run(EvolutionState.C_STARTED_FRESH); cleanup(state); // flush and close various streams, print out parameters if necessary parameters = null; // so we load a fresh database next time around } } System.exit(0); }