Search in sources :

Example 41 with EquationSet

use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.

the class ChangeVariable method emitPath.

public static String emitPath(EquationSet home, EquationSet target, String name) {
    // If there is an unambiguous path up to "name", then emit nothing.
    EquationSet e = home;
    while (e != target) {
        if (isVisible(e, name))
            break;
        e = e.container;
    }
    if (e == target)
        return "";
    // If there is an unambiguous path to the container of "name", then use that.
    if (// Only do this if not top-level container, as that container can't be referenced explicitly.
    target.container != null) {
        // Count depth to decide between using this method or $up. For a single level, $up is a nicer choice. For many levels, an explicit part name is more concise.
        int depth = 0;
        e = home;
        while (e != target) {
            depth++;
            if (isVisible(e, target.name))
                break;
            e = e.container;
        }
        if (e == target && depth > 1)
            return target.name + ".";
    }
    // Otherwise, use $up.
    String result = "";
    e = home;
    while (e != target) {
        result += "$up.";
        e = e.container;
    }
    return result;
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet)

Example 42 with EquationSet

use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.

the class ExportJob method fakeConnectionTarget.

/**
 *        Replace any entries of the form A=connect() with A=N2A_fakePart.
 */
public static boolean fakeConnectionTarget(EquationSet s) {
    boolean result = false;
    for (Variable v : s.variables) {
        if (// may be due to unreadable part names in connect()
        v.equations.size() == 0) {
            String value = s.source.get(v.nameString());
            if (!Operator.containsConnect(value))
                continue;
            try {
                v.add(new EquationEntry("N2A_fakePart"));
                result = true;
            } catch (Exception e) {
            }
        } else if (// could be a properly-parsed connect() line
        v.equations.size() == 1) {
            EquationEntry e = v.equations.first();
            // connect() appears like AccessElement during initial parse
            if (!(e.expression instanceof AccessElement))
                continue;
            AccessElement ae = (AccessElement) e.expression;
            AccessVariable av = (AccessVariable) ae.operands[0];
            if (!av.name.equals("connect"))
                continue;
            av.name = "N2A_fakePart";
            e.expression = av;
            result = true;
        }
    }
    for (EquationSet p : s.parts) if (fakeConnectionTarget(p))
        result = true;
    return result;
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) Variable(gov.sandia.n2a.eqset.Variable) UnresolvedVariable(gov.sandia.n2a.eqset.EquationSet.UnresolvedVariable) AccessVariable(gov.sandia.n2a.language.AccessVariable) AccessVariable(gov.sandia.n2a.language.AccessVariable) AccessElement(gov.sandia.n2a.language.AccessElement) EquationEntry(gov.sandia.n2a.eqset.EquationEntry) UnconvertibleException(javax.measure.UnconvertibleException) IncommensurableException(javax.measure.IncommensurableException)

Example 43 with EquationSet

use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.

the class ExportJob method process.

public void process(MPart source) {
    if (source.get("$metadata", "backend", "lems", "part").isEmpty()) {
        for (EquationSet p : equations.parts) topLevelPart((MPart) p.source);
    } else {
        topLevelPart(source);
    }
    // Simulation
    if (simulation != null) {
        simulation.findOutputs();
        if (simulation.score() > 0)
            simulation.append();
    }
    // ComponentTypes
    if (componentTypes.size() > 0) {
        try {
            // Rebuild equations, this time without the aggressive constant folding.
            MPart mpart = (MPart) equations.source;
            equations = new EquationSet(mpart);
            makeExecutable(equations, false);
            for (ComponentType ct : componentTypes) ct.append();
        }// Shouldn't be any exceptions, since we already built this equation set once.
         catch (Exception e) {
        }
    }
    appendUnits(requiresNML);
    // Collate
    Element root;
    if (componentTypes.isEmpty() && !forBackend) {
        suffix = "nml";
        root = doc.createElement("neuroml");
        root.setAttribute("xmlns", "http://www.neuroml.org/schema/neuroml2");
        root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        root.setAttribute("xsi:schemaLocation", "http://www.neuroml.org/schema/neuroml2 ../Schemas/NeuroML2/NeuroML_v2beta4.xsd");
        root.setAttribute("id", modelName);
    } else {
        suffix = "xml";
        root = doc.createElement("Lems");
        if (requiresNML) {
            Element include = addElement("Include", elements);
            include.setAttribute("file", "Cells.xml");
            include = addElement("Include", elements);
            include.setAttribute("file", "Networks.xml");
            if (simulation != null) {
                include = addElement("Include", elements);
                include.setAttribute("file", "Simulation.xml");
                Element target = addElement("Target", elements);
                target.setAttribute("component", simulation.id);
            }
        } else {
        // TODO: set Target for pure LEMS file (one with no NeuroML elements at all).
        }
    }
    sequencer.append(root, elements);
    doc.appendChild(root);
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) MPart(gov.sandia.n2a.eqset.MPart) AccessElement(gov.sandia.n2a.language.AccessElement) Element(org.w3c.dom.Element) UnconvertibleException(javax.measure.UnconvertibleException) IncommensurableException(javax.measure.IncommensurableException)

Example 44 with EquationSet

use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.

the class JobSTACS method run.

public void run() {
    localJobDir = Host.getJobDir(Host.getLocalResourceDir(), job);
    Path errPath = localJobDir.resolve("err");
    try {
        Backend.err.set(new PrintStream(new FileOutputStream(errPath.toFile(), true), false, "UTF-8"));
    } catch (Exception e) {
    }
    try {
        Files.createFile(localJobDir.resolve("started"));
        MNode model = NodeJob.getModel(job);
        env = Host.get(job);
        // remote or local
        Path resourceDir = env.getResourceDir();
        // Unlike localJobDir (which is created by MDir), this may not exist until we explicitly create it.
        jobDir = Host.getJobDir(resourceDir, job);
        // digestModel() might write to a remote file (params), so we need to ensure the dir exists first.
        Files.createDirectories(jobDir);
        digestedModel = new EquationSet(model);
        InternalBackend.digestModel(digestedModel);
        String duration = digestedModel.metadata.get("duration");
        if (!duration.isEmpty())
            job.set(duration, "duration");
        seed = model.getOrDefault(System.currentTimeMillis(), "$metadata", "seed");
        job.set(seed, "seed");
        int cores = 1;
        if (!(env instanceof Remote))
            cores = env.getProcessorTotal();
        cores = job.getOrDefault(cores, "host", "cores");
        int nodes = job.getOrDefault(1, "host", "nodes");
        processes = cores * nodes;
        generateConfigs();
        // The simulator could append to the same error file, so we need to close the file before submitting.
        PrintStream ps = Backend.err.get();
        if (ps != System.err) {
            ps.close();
            Backend.err.remove();
            job.set(Host.size(errPath), "errSize");
        }
        List<List<String>> commands = new ArrayList<List<String>>();
        List<String> charmrun = new ArrayList<String>();
        charmrun.add("charmrun");
        charmrun.add("+p" + processes);
        List<String> command = new ArrayList<String>(charmrun);
        command.add(env.config.getOrDefault("genet", "backend", "stacs", "genet"));
        command.add("config.yml");
        commands.add(command);
        command = new ArrayList<String>(charmrun);
        command.add(env.config.getOrDefault("stacs", "backend", "stacs", "stacs"));
        command.add("config.yml");
        commands.add(command);
        env.submitJob(job, true, commands);
    } catch (Exception e) {
        if (!(e instanceof AbortRun))
            e.printStackTrace(Backend.err.get());
        try {
            Files.copy(new ByteArrayInputStream("failure".getBytes("UTF-8")), localJobDir.resolve("finished"));
        } catch (Exception f) {
        }
    }
    // If an exception occurred, the error file will still be open.
    PrintStream ps = Backend.err.get();
    if (ps != System.err)
        ps.close();
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) EquationSet(gov.sandia.n2a.eqset.EquationSet) ArrayList(java.util.ArrayList) Remote(gov.sandia.n2a.host.Remote) MNode(gov.sandia.n2a.db.MNode) IOException(java.io.IOException) AbortRun(gov.sandia.n2a.plugins.extpoints.Backend.AbortRun) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with EquationSet

use of gov.sandia.n2a.eqset.EquationSet in project n2a by frothga.

the class XyceBackend method analyze.

public void analyze(EquationSet s) {
    for (EquationSet p : s.parts) analyze(p);
    XyceBackendData bed = new XyceBackendData();
    bed.internal = (InternalBackendData) s.backendData;
    s.backendData = bed;
    bed.analyze(s);
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet)

Aggregations

EquationSet (gov.sandia.n2a.eqset.EquationSet)63 Variable (gov.sandia.n2a.eqset.Variable)25 AccessVariable (gov.sandia.n2a.language.AccessVariable)24 ConnectionBinding (gov.sandia.n2a.eqset.EquationSet.ConnectionBinding)16 ArrayList (java.util.ArrayList)16 EquationEntry (gov.sandia.n2a.eqset.EquationEntry)12 Operator (gov.sandia.n2a.language.Operator)12 MNode (gov.sandia.n2a.db.MNode)11 MPart (gov.sandia.n2a.eqset.MPart)10 Constant (gov.sandia.n2a.language.Constant)10 Scalar (gov.sandia.n2a.language.type.Scalar)10 IncommensurableException (javax.measure.IncommensurableException)9 UnconvertibleException (javax.measure.UnconvertibleException)9 AbortRun (gov.sandia.n2a.plugins.extpoints.Backend.AbortRun)8 VariableReference (gov.sandia.n2a.eqset.VariableReference)7 Type (gov.sandia.n2a.language.Type)7 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)7 EventTarget (gov.sandia.n2a.backend.internal.InternalBackendData.EventTarget)6 Visitor (gov.sandia.n2a.language.Visitor)6 EventSource (gov.sandia.n2a.backend.internal.InternalBackendData.EventSource)5