Search in sources :

Example 1 with Column

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) {
    }
}
Also used : Path(java.nio.file.Path) MPart(gov.sandia.n2a.eqset.MPart) Table(gov.sandia.n2a.ui.jobs.Table) Remote(gov.sandia.n2a.host.Remote) Host(gov.sandia.n2a.host.Host) IOException(java.io.IOException) MNode(gov.sandia.n2a.db.MNode) Date(java.util.Date) MDoc(gov.sandia.n2a.db.MDoc) BufferedWriter(java.io.BufferedWriter) Backend(gov.sandia.n2a.plugins.extpoints.Backend) Column(gov.sandia.n2a.ui.jobs.OutputParser.Column) NodeJob(gov.sandia.n2a.ui.jobs.NodeJob) OutputParser(gov.sandia.n2a.ui.jobs.OutputParser) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

MDoc (gov.sandia.n2a.db.MDoc)1 MNode (gov.sandia.n2a.db.MNode)1 MPart (gov.sandia.n2a.eqset.MPart)1 Host (gov.sandia.n2a.host.Host)1 Remote (gov.sandia.n2a.host.Remote)1 Backend (gov.sandia.n2a.plugins.extpoints.Backend)1 NodeJob (gov.sandia.n2a.ui.jobs.NodeJob)1 OutputParser (gov.sandia.n2a.ui.jobs.OutputParser)1 Column (gov.sandia.n2a.ui.jobs.OutputParser.Column)1 Table (gov.sandia.n2a.ui.jobs.Table)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1