use of gov.sandia.n2a.ui.jobs.OutputParser.Column in project n2a by frothga.
the class Main method runHeadless.
/**
* Assumes this app was started solely for the purpose of running one specific job.
* This job operates outside the normal job management. The user is responsible
* for everything, including load balancing, directory and file management.
* Jobs can run remotely, but there is no support for retrieving results.
*/
public static void runHeadless(MNode record) {
// See PanelEquations.launchJob()
// Use current working directory, on assumption that's what the caller wants.
Path jobDir = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
// This allows a remote job to run in the regular jobs directory there.
String jobKey = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.ROOT).format(new Date());
// Make this appear as if it is from the jobs collection.
MDoc job = new MDoc(jobDir.resolve("job"), jobKey);
String key = record.key();
MNode doc = AppData.models.childOrEmpty(key);
record.mergeUnder(doc);
// TODO: the only reason to collate here is to ensure that host and backend are correctly identified if they are inherited. Need a more efficient method, such as lazy collation in MPart.
MPart collated = new MPart(record);
NodeJob.collectJobParameters(collated, key, job);
NodeJob.saveSnapshot(record, job);
// Handle remote host
// If a remote host is used, it must be specified exactly, rather than a list of possibilities.
Host host = Host.get(job);
if (// Need to note the key so user can easily find the remote job directory.
host instanceof Remote) {
job.set(jobKey, "remoteKey");
job.save();
}
// Start the job.
Backend backend = Backend.getBackend(job.get("backend"));
backend.start(job);
// Wait for completion
NodeJob node = new NodeJobHeadless(job);
while (node.complete < 1) node.monitorProgress();
// Convert to CSV, if requested.
if (record.getFlag("$metadata", "csv")) {
Table table = new Table(jobDir.resolve("out"), false);
try {
table.dumpCSV(jobDir.resolve("out.csv"));
} catch (IOException e) {
}
}
// Extract results requested in ASV
MNode ASV = record.child("$metadata", "dakota", "ASV");
// nothing more to do
if (ASV == null)
return;
OutputParser output = new OutputParser();
output.parse(jobDir.resolve("out"));
try (BufferedWriter writer = Files.newBufferedWriter(jobDir.resolve("results"))) {
for (MNode o : ASV) {
String name = o.get();
Column c = output.getColumn(name);
float value = 0;
if (c != null && !c.values.isEmpty())
value = c.values.get(c.values.size() - 1);
writer.write(value + " " + name);
}
} catch (IOException e) {
}
}
Aggregations