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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations