From fe6009b6fd6b2b17b06977afa6a651c7a6891374 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Thu, 15 Feb 2024 12:25:45 +0000 Subject: [PATCH 1/4] feat(dlems-keywords): add cvode related keywords --- .../lemsml/export/dlems/DLemsKeywords.java | 124 +++++++++--------- 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/src/main/java/org/lemsml/export/dlems/DLemsKeywords.java b/src/main/java/org/lemsml/export/dlems/DLemsKeywords.java index c92442f3d..2423c2322 100644 --- a/src/main/java/org/lemsml/export/dlems/DLemsKeywords.java +++ b/src/main/java/org/lemsml/export/dlems/DLemsKeywords.java @@ -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(); + } } From 2aa6950a38239dceb0289567306f74b2e155224b Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Thu, 15 Feb 2024 12:27:19 +0000 Subject: [PATCH 2/4] feat(netpyne-template): update to include cvode bits --- src/main/resources/netpyne/run.vm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/resources/netpyne/run.vm b/src/main/resources/netpyne/run.vm index 8ed746ee5..17db9f044 100644 --- a/src/main/resources/netpyne/run.vm +++ b/src/main/resources/netpyne/run.vm @@ -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) @@ -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 @@ -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() From d5b2eb94be914fbbc044301fa8e5e189b4c97bc4 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Thu, 15 Feb 2024 12:36:05 +0000 Subject: [PATCH 3/4] feat(dlems-writer): add bits for handling cvode in NEURON --- .../org/lemsml/export/dlems/DLemsWriter.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/org/lemsml/export/dlems/DLemsWriter.java b/src/main/java/org/lemsml/export/dlems/DLemsWriter.java index ebe295720..944aa7d05 100644 --- a/src/main/java/org/lemsml/export/dlems/DLemsWriter.java +++ b/src/main/java/org/lemsml/export/dlems/DLemsWriter.java @@ -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; @@ -203,6 +205,34 @@ 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 metas = simCpt.metas; + for(Meta m : metas) + { + HashMap 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"); + 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")); From dacf1f3fadf1672d7a1a29c4ecab0f7b2d051052 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Thu, 15 Feb 2024 15:47:36 +0000 Subject: [PATCH 4/4] fix(netpyne): improve logic for cvode in generated script --- src/main/java/org/lemsml/export/dlems/DLemsWriter.java | 10 +++++++--- src/main/resources/netpyne/run.vm | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/lemsml/export/dlems/DLemsWriter.java b/src/main/java/org/lemsml/export/dlems/DLemsWriter.java index 944aa7d05..237c8688a 100644 --- a/src/main/java/org/lemsml/export/dlems/DLemsWriter.java +++ b/src/main/java/org/lemsml/export/dlems/DLemsWriter.java @@ -228,10 +228,14 @@ public String getMainScript() throws LEMSException, IOException if (nrn_cvode == true) { g.writeStringField(DLemsKeywords.CVODE.get(), "true"); - g.writeStringField(DLemsKeywords.ABS_TOL.get(), abs_tol); - g.writeStringField(DLemsKeywords.REL_TOL.get(), rel_tol); - } + 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")) diff --git a/src/main/resources/netpyne/run.vm b/src/main/resources/netpyne/run.vm index 17db9f044..e03992872 100644 --- a/src/main/resources/netpyne/run.vm +++ b/src/main/resources/netpyne/run.vm @@ -50,7 +50,7 @@ class NetPyNESimulation(): # cvode if abs_tol is not None: self.simConfig.cvode_active = True - self.simConfig.cvode_atol = $abs_tol + self.simConfig.cvode_atol = abs_tol else: self.simConfig.cvode_active = False