Skip to content

Commit

Permalink
Merge pull request #112 from NeuroML/feat/netpyne-cvode
Browse files Browse the repository at this point in the history
netpyne: expose cvode bits from LEMS
  • Loading branch information
pgleeson authored Feb 22, 2024
2 parents 728c83f + dacf1f3 commit aa62f9b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 62 deletions.
124 changes: 64 additions & 60 deletions src/main/java/org/lemsml/export/dlems/DLemsKeywords.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,83 @@

/**
* @author matteocantarelli
*
*
*/
public enum DLemsKeywords
{
DT,
SEED,
REPORT_FILE,
DYNAMICS,
EVENTS,
CONDITION,
DIRECTION,
EFFECT,
NAME,
TYPE,
TITLE,
PARAMETERS,
STATE,
STATE_FUNCTIONS,
T_END,
T_START,
COMMENT,
DUMP_TO_FILE,
OUTPUT_FILE,
SPIKE_FILE,
SPIKE_FILE_FORMAT,
EVENT_SELECTIONS,
EVENT_SELECTION_ID,
SELECT,
EVENT_PORT,
FILE_NAME,
OUTPUT_COLUMNS,
VARIABLE,
QUANTITY,
DISPLAY,
ABSCISSA_AXIS,
MIN, MAX,
ORDINATE_AXIS,
CURVES,
ABSCISSA,
ORDINATE,
POPULATION,
POPULATION_INDEX,
SEGMENT_ID,
SEGMENT_NAME,
FRACTION_ALONG,
COLOUR,
POPULATIONS,
SIZE,
DT,
SEED,
REPORT_FILE,
DYNAMICS,
EVENTS,
CONDITION,
DIRECTION,
EFFECT,
NAME,
TYPE,
TITLE,
PARAMETERS,
STATE,
STATE_FUNCTIONS,
T_END,
T_START,
COMMENT,
DUMP_TO_FILE,
OUTPUT_FILE,
SPIKE_FILE,
SPIKE_FILE_FORMAT,
EVENT_SELECTIONS,
EVENT_SELECTION_ID,
SELECT,
EVENT_PORT,
FILE_NAME,
OUTPUT_COLUMNS,
VARIABLE,
QUANTITY,
DISPLAY,
ABSCISSA_AXIS,
MIN, MAX,
ORDINATE_AXIS,
CURVES,
ABSCISSA,
ORDINATE,
POPULATION,
POPULATION_INDEX,
SEGMENT_ID,
SEGMENT_NAME,
FRACTION_ALONG,
COLOUR,
POPULATIONS,
SIZE,
SYNAPSES,
SYNAPSE,
COMPONENT,
PROJECTIONS,
PRE_POPULATION,
POST_POPULATION,
PROJECTIONS,
PRE_POPULATION,
POST_POPULATION,
CONNECTIONS,
PRE_CELL_ID,
POST_CELL_ID,
WEIGHT,
DELAY,
PRE_CELL_ID,
POST_CELL_ID,
WEIGHT,
DELAY,
INPUTS,


TEMPERATURE,
NEURON_VARIABLE_NAME,
NEURON_MECHANISM_NAME,
NEURON_SECTION_NAME,
NEURON_FRACT_ALONG,
NEURON_VARIABLE_SCALE,

EXPORT_LIBRARY_VERSION;

public String get()
{
return this.toString().toLowerCase();
}
EXPORT_LIBRARY_VERSION,

CVODE,
ABS_TOL,
REL_TOL;

public String get()
{
return this.toString().toLowerCase();
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/lemsml/export/dlems/DLemsWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import org.lemsml.jlems.core.type.Dimension;
import org.lemsml.jlems.core.type.FinalParam;
import org.lemsml.jlems.core.type.Lems;
import org.lemsml.jlems.core.type.LemsCollection;
import org.lemsml.jlems.core.type.ParamValue;
import org.lemsml.jlems.core.type.Meta;
import org.lemsml.jlems.core.type.Target;
import org.lemsml.jlems.core.type.dynamics.DerivedVariable;
import org.lemsml.jlems.core.type.dynamics.IVisitable;
Expand Down Expand Up @@ -203,6 +205,38 @@ public String getMainScript() throws LEMSException, IOException

g.writeStringField(DLemsKeywords.DT.get(), convertTime(simCpt.getParamValue("step")));

boolean nrn_cvode = false;
/* defaults from NEURON */
String abs_tol = "None";
String rel_tol = "None";
LemsCollection<Meta> metas = simCpt.metas;
for(Meta m : metas)
{
HashMap<String, String> attributes = m.getAttributes();
if (attributes.getOrDefault("for", "").equals("neuron"))
{
if (attributes.getOrDefault("method", "").equals("cvode"))
{
nrn_cvode = true;
abs_tol = attributes.getOrDefault("abs_tolerance", abs_tol);
rel_tol = attributes.getOrDefault("rel_tolerance", rel_tol);
E.info("CVode with abs_tol="+abs_tol+" , rel_tol="+rel_tol+" selected for NEURON simulation");
}
}

}
if (nrn_cvode == true)
{
g.writeStringField(DLemsKeywords.CVODE.get(), "true");
}
else
{
g.writeStringField(DLemsKeywords.CVODE.get(), "false");
}
/* set them to something even if not provided by user */
g.writeStringField(DLemsKeywords.ABS_TOL.get(), abs_tol);
g.writeStringField(DLemsKeywords.REL_TOL.get(), rel_tol);

int seed = DEFAULT_SEED;
if (simCpt.hasStringValue("seed"))
seed = Integer.parseInt(simCpt.getStringValue("seed"));
Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/netpyne/run.vm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import datetime

class NetPyNESimulation():

def __init__(self, tstop=$t_end, dt=$dt, seed=123456789, save_json=False):
def __init__(self, tstop=$t_end, dt=$dt, seed=123456789, save_json=False, abs_tol=None):

self.setup_start = time.time()
#if ($report_file)
Expand Down Expand Up @@ -47,6 +47,13 @@ class NetPyNESimulation():
self.simConfig.duration = self.simConfig.tstop = tstop # Duration of the simulation, in ms
self.simConfig.dt = dt # Internal integration timestep to use

# cvode
if abs_tol is not None:
self.simConfig.cvode_active = True
self.simConfig.cvode_atol = abs_tol
else:
self.simConfig.cvode_active = False

# Seeds for randomizers (connectivity, input stimulation and cell locations)
# Note: locations and connections should be fully specified by the structure of the NeuroML,
# so seeds for conn & loc shouldn't affect networks structure/behaviour
Expand Down Expand Up @@ -231,7 +238,7 @@ if __name__ == '__main__':
save_json = '-json' in sys.argv
no_run = '-norun' in sys.argv

ns = NetPyNESimulation(tstop=$t_end, dt=$dt, seed=$seed, save_json=save_json)
ns = NetPyNESimulation(tstop=$t_end, dt=$dt, seed=$seed, save_json=save_json, abs_tol=$abs_tol)

if not no_run:
ns.run()
Expand Down

0 comments on commit aa62f9b

Please sign in to comment.