config.h
1 /*************************************************************************
2  * Copyright (C) 2018-2021 Blue Brain Project
3  * Jonas Karlsson <jonas.karlsson@epfl.ch>
4  * Juan Hernando <juan.hernando@epfl.ch>
5  *
6  * This file is part of 'libsonata', distributed under the terms
7  * of the GNU Lesser General Public License version 3.
8  *
9  * See top-level COPYING.LESSER and COPYING files for details.
10  *************************************************************************/
11 
12 #pragma once
13 
14 #include <set>
15 #include <string>
16 #include <unordered_map>
17 #include <vector>
18 
19 #include <bbp/sonata/edges.h>
20 #include <bbp/sonata/nodes.h>
21 #include <bbp/sonata/optional.hpp>
22 
23 #include "common.h"
24 #include "optional.hpp"
25 #include "variant.hpp"
26 
27 
28 namespace bbp {
29 namespace sonata {
30 
32 
37  std::string type;
38 
44  std::string elementsPath;
45 
51  std::string typesPath;
52 
57 
61  std::string morphologiesDir;
62 
66  std::unordered_map<std::string, std::string> alternateMorphologyFormats;
67 };
68 
77 
82  nonstd::optional<std::string> vasculatureFile{nonstd::nullopt};
83 
88  nonstd::optional<std::string> vasculatureMesh{nonstd::nullopt};
89 
94  nonstd::optional<std::string> microdomainsFile{nonstd::nullopt};
95 };
96 
105 
109  nonstd::optional<std::string> endfeetMeshesFile{nonstd::nullopt};
110 
114  nonstd::optional<std::string> spineMorphologiesDir{nonstd::nullopt};
115 };
116 
120 class SONATA_API CircuitConfig
121 {
122  public:
123  enum class ConfigStatus {
125  invalid,
128  complete,
135  partial
136  };
137 
147  CircuitConfig(const std::string& contents, const std::string& basePath);
148 
160  static CircuitConfig fromFile(const std::string& path);
161 
167 
171  const std::string& getNodeSetsPath() const;
172 
176  const std::string& getCompartmentSetsPath() const;
177 
181  std::set<std::string> listNodePopulations() const;
182 
189  NodePopulation getNodePopulation(const std::string& name, const Hdf5Reader& hdf5_reader) const;
190  NodePopulation getNodePopulation(const std::string& name) const;
194  std::set<std::string> listEdgePopulations() const;
195 
202  EdgePopulation getEdgePopulation(const std::string& name, const Hdf5Reader& hdf5_reader) const;
203  EdgePopulation getEdgePopulation(const std::string& name) const;
204 
213 
222 
227  const std::string& getExpandedJSON() const;
228 
229  private:
230  struct Components {
231  std::string morphologiesDir;
232  std::unordered_map<std::string, std::string> alternateMorphologiesDir;
233  std::string biophysicalNeuronModelsDir;
234 
235  nonstd::optional<std::string> vasculatureFile{nonstd::nullopt};
236  nonstd::optional<std::string> vasculatureMesh{nonstd::nullopt};
237  nonstd::optional<std::string> endfeetMeshesFile{nonstd::nullopt};
238  nonstd::optional<std::string> microdomainsFile{nonstd::nullopt};
239  nonstd::optional<std::string> spineMorphologiesDir{nonstd::nullopt};
240  };
241 
242  class Parser;
243 
244  // Circuit config json string whose paths and variables have been expanded to include
245  // manifest variables
246  std::string _expandedJSON;
247 
248  // How strict we are checking the circuit config
249  ConfigStatus _status = ConfigStatus::complete;
250 
251  // Path to the nodesets file
252  std::string _nodeSetsFile;
253 
254  // Node populations that override default components variables
255  std::unordered_map<std::string, NodePopulationProperties> _nodePopulationProperties;
256 
257  // Edge populations that override default components variables
258  std::unordered_map<std::string, EdgePopulationProperties> _edgePopulationProperties;
259 };
260 
264 class SONATA_API SimulationConfig
265 {
266  public:
270  struct Run {
271  enum class IntegrationMethod { invalid = -1, euler, crank_nicolson, crank_nicolson_ion };
272 
273  static constexpr double DEFAULT_spikeThreshold = -30.0;
274  static constexpr IntegrationMethod DEFAULT_IntegrationMethod = IntegrationMethod::euler;
275  static constexpr int DEFAULT_stimulusSeed = 0;
276  static constexpr int DEFAULT_ionchannelSeed = 0;
277  static constexpr int DEFAULT_minisSeed = 0;
278  static constexpr int DEFAULT_synapseSeed = 0;
279 
281  double tstop{};
283  double dt{};
285  int randomSeed{};
287  double spikeThreshold = DEFAULT_spikeThreshold;
290  IntegrationMethod integrationMethod = DEFAULT_IntegrationMethod;
293  int stimulusSeed = DEFAULT_stimulusSeed;
295  int ionchannelSeed = DEFAULT_ionchannelSeed;
298  int minisSeed = DEFAULT_minisSeed;
300  int synapseSeed = DEFAULT_synapseSeed;
302  std::string electrodesFile;
303  };
307  struct Output {
308  enum class SpikesSortOrder { invalid = -1, none, by_id, by_time };
309 
310  static constexpr char DEFAULT_outputDir[] = "output";
311  static constexpr char DEFAULT_logFile[] = "";
312  static constexpr char DEFAULT_spikesFile[] = "out.h5";
313  static constexpr SpikesSortOrder DEFAULT_sortOrder = SpikesSortOrder::by_time;
314 
316  std::string outputDir = DEFAULT_outputDir;
318  std::string logFile = DEFAULT_logFile;
320  std::string spikesFile = DEFAULT_spikesFile;
322  SpikesSortOrder sortOrder = DEFAULT_sortOrder;
323  };
324 
326  enum class ModificationType { invalid = -1, TTX, ConfigureAllSections };
327 
329  std::string nodeSet;
331  ModificationType type;
333  std::string name;
334  };
335 
337  };
338 
343  std::string sectionConfigure;
344  };
345 
347 
351  struct Conditions {
352  enum class SpikeLocation { invalid = -1, soma, AIS };
353  static constexpr double DEFAULT_celsius = 34.0;
354  static constexpr double DEFAULT_vInit = -80.0;
355  static constexpr SpikeLocation DEFAULT_spikeLocation = SpikeLocation::soma;
356  static constexpr bool DEFAULT_randomizeGabaRiseTime = false;
357 
359  double celsius = DEFAULT_celsius;
361  double vInit = DEFAULT_vInit;
363  SpikeLocation spikeLocation = DEFAULT_spikeLocation;
366  nonstd::optional<double> extracellularCalcium{nonstd::nullopt};
369  bool randomizeGabaRiseTime = DEFAULT_randomizeGabaRiseTime;
373  std::unordered_map<std::string, std::unordered_map<std::string, variantValueType>>
376  std::vector<Modification> modifications;
378  const std::vector<Modification>& getModifications() const noexcept;
379  };
383  struct Report {
384  enum class Sections { invalid = -1, soma, axon, dend, apic, all };
385  enum class Type { invalid = -1, compartment, lfp, summation, synapse };
386  enum class Scaling { invalid = -1, none, area };
387  enum class Compartments { invalid = -1, center, all };
388 
390  std::string cells;
392  Sections sections;
394  Type type;
397  Scaling scaling;
400  Compartments compartments;
404  std::string variableName;
406  std::string unit;
408  double dt{};
410  double startTime{};
412  double endTime{};
414  std::string fileName;
416  bool enabled = true;
417  };
418 
419  using ReportMap = std::unordered_map<std::string, Report>;
420 
421  struct InputBase {
422  enum class Module {
423  invalid = -1,
424  linear,
425  relative_linear,
426  pulse,
427  sinusoidal,
428  subthreshold,
429  hyperpolarizing,
430  synapse_replay,
431  seclamp,
432  noise,
433  shot_noise,
434  relative_shot_noise,
435  absolute_shot_noise,
436  ornstein_uhlenbeck,
437  relative_ornstein_uhlenbeck
438  };
439 
440  enum class InputType {
441  invalid = -1,
442  spikes,
443  extracellular_stimulation,
444  current_clamp,
445  voltage_clamp,
446  conductance
447  };
448 
450  Module module;
452  InputType inputType;
454  double delay{};
456  double duration{};
458  std::string nodeSet;
459  };
460 
461  struct InputLinear: public InputBase {
463  double ampStart{};
465  double ampEnd{};
467  bool representsPhysicalElectrode = false;
468  };
469 
472  double percentStart{};
474  double percentEnd{};
476  bool representsPhysicalElectrode = false;
477  };
478 
479  struct InputPulse: public InputBase {
481  double ampStart{};
483  double width{};
485  double frequency{};
487  bool representsPhysicalElectrode = false;
488  };
489 
490  struct InputSinusoidal: public InputBase {
492  double ampStart{};
494  double frequency{};
496  double dt{};
498  bool representsPhysicalElectrode = false;
499  };
500 
501  struct InputSubthreshold: public InputBase {
503  double percentLess{};
505  bool representsPhysicalElectrode = false;
506  };
507 
510  bool representsPhysicalElectrode = false;
511  };
512 
513  struct InputSynapseReplay: public InputBase {
515  std::string spikeFile;
516  };
517 
518  struct InputSeclamp: public InputBase {
520  double voltage{};
522  double seriesResistance{};
523  };
524 
525  struct InputNoise: public InputBase {
527  nonstd::optional<double> mean{nonstd::nullopt};
529  nonstd::optional<double> meanPercent{nonstd::nullopt};
532  double variance{};
534  bool representsPhysicalElectrode = false;
535  };
536 
537  struct InputShotNoise: public InputBase {
539  double riseTime{};
541  double decayTime{};
543  nonstd::optional<int> randomSeed{nonstd::nullopt};
545  double reversal{};
547  double dt{};
549  int rate{};
551  double ampMean{};
554  double ampVar{};
556  bool representsPhysicalElectrode = false;
557  };
558 
561  double riseTime{};
563  double decayTime{};
565  nonstd::optional<int> randomSeed{nonstd::nullopt};
567  double reversal{};
569  double dt{};
572  double meanPercent{};
575  double sdPercent{};
577  bool representsPhysicalElectrode = false;
581  double relativeSkew{};
582  };
583 
586  double riseTime{};
588  double decayTime{};
590  nonstd::optional<int> randomSeed{nonstd::nullopt};
592  double reversal{};
594  double dt{};
596  double mean{};
598  double sigma{};
600  bool representsPhysicalElectrode = false;
604  double relativeSkew{};
605  };
606 
609  double tau{};
611  double reversal{};
613  double dt{};
615  nonstd::optional<int> randomSeed{nonstd::nullopt};
617  double mean{};
619  double sigma{};
621  bool representsPhysicalElectrode = false;
622  };
623 
626  double tau{};
628  double reversal{};
630  double dt{};
632  nonstd::optional<int> randomSeed{nonstd::nullopt};
635  double meanPercent{};
638  double sdPercent{};
640  bool representsPhysicalElectrode = false;
641  };
642 
645  InputPulse,
650  InputSeclamp,
651  InputNoise,
657 
658  using InputMap = std::unordered_map<std::string, Input>;
659 
666  std::string name;
668  std::string source;
670  std::string target;
672  double weight{1.};
674  nonstd::optional<double> spontMinis{nonstd::nullopt};
677  nonstd::optional<std::string> synapseConfigure{nonstd::nullopt};
680  nonstd::optional<std::string> modoverride{nonstd::nullopt};
683  nonstd::optional<double> synapseDelayOverride{nonstd::nullopt};
686  double delay{0.};
689  nonstd::optional<double> neuromodulationDtc{nonstd::nullopt};
692  nonstd::optional<double> neuromodulationStrength{nonstd::nullopt};
693  };
694 
695  enum class SimulatorType { invalid = -1, NEURON, CORENEURON };
696 
704  SimulationConfig(const std::string& content, const std::string& basePath);
705 
715  static SimulationConfig fromFile(const std::string& path);
716 
720  const std::string& getBasePath() const noexcept;
721 
725  const std::string& getJSON() const noexcept;
726 
730  const std::string& getNetwork() const noexcept;
731 
735  const Run& getRun() const noexcept;
736 
740  const Output& getOutput() const noexcept;
741 
745  const Conditions& getConditions() const noexcept;
746 
750  std::set<std::string> listReportNames() const;
751 
758  const Report& getReport(const std::string& name) const;
759 
763  std::set<std::string> listInputNames() const;
764 
770  const Input& getInput(const std::string& name) const;
771 
776  const std::vector<ConnectionOverride>& getConnectionOverrides() const noexcept;
777 
782  const SimulationConfig::SimulatorType& getTargetSimulator() const;
783 
788  const std::string& getNodeSetsFile() const noexcept;
789 
793  const std::string& getCompartmentSetsFile() const noexcept;
794 
798  const nonstd::optional<std::string>& getNodeSet() const noexcept;
799 
803  const std::unordered_map<std::string, variantValueType>& getMetaData() const noexcept;
804 
805 
809  const std::unordered_map<std::string, variantValueType>& getBetaFeatures() const noexcept;
810 
815  const std::string& getExpandedJSON() const;
816 
817  private:
818  // JSON string
819  std::string _expandedJSON;
820  // Base path of the simulation config file
821  std::string _basePath;
822 
823  // Run section
824  Run _run;
825  // Output section
826  Output _output;
827  // List of reports
828  ReportMap _reports;
829  // Conditions section
830  Conditions _conditions;
831  // Path of circuit config file for the simulation
832  std::string _network;
833  // List of inputs
834  InputMap _inputs;
835  // List of connections
836  std::vector<ConnectionOverride> _connection_overrides;
837  // Name of simulator
838  SimulatorType _targetSimulator;
839  // Path of node sets file
840  std::string _nodeSetsFile;
841  // Path of compartment sets file
842  std::string _compartmentSetsFile;
843  // Name of node set
844  nonstd::optional<std::string> _nodeSet{nonstd::nullopt};
845  // Remarks on the simulation
846  std::unordered_map<std::string, variantValueType> _metaData;
847  // Variables for a new feature in development, to be moved to other sections once in production
848  std::unordered_map<std::string, variantValueType> _betaFeatures;
849 
850  class Parser;
851 };
852 
853 } // namespace sonata
854 } // namespace bbp
Definition: config.h:121
CircuitConfig(const std::string &contents, const std::string &basePath)
ConfigStatus getCircuitConfigStatus() const
EdgePopulation getEdgePopulation(const std::string &name, const Hdf5Reader &hdf5_reader) const
ConfigStatus
Definition: config.h:123
NodePopulation getNodePopulation(const std::string &name, const Hdf5Reader &hdf5_reader) const
const std::string & getCompartmentSetsPath() const
EdgePopulationProperties getEdgePopulationProperties(const std::string &name) const
std::set< std::string > listEdgePopulations() const
const std::string & getExpandedJSON() const
static CircuitConfig fromFile(const std::string &path)
const std::string & getNodeSetsPath() const
NodePopulationProperties getNodePopulationProperties(const std::string &name) const
std::set< std::string > listNodePopulations() const
Definition: edges.h:27
Definition: hdf5_reader.h:122
Definition: nodes.h:25
Definition: config.h:265
static SimulationConfig fromFile(const std::string &path)
const std::string & getBasePath() const noexcept
SimulationConfig(const std::string &content, const std::string &basePath)
class optional
Definition: optional.hpp:847
Definition: variant.hpp:1679
std::string morphologiesDir
Definition: config.h:61
std::string type
Definition: config.h:37
std::string elementsPath
Definition: config.h:44
std::string typesPath
Definition: config.h:51
std::unordered_map< std::string, std::string > alternateMorphologyFormats
Definition: config.h:66
std::string biophysicalNeuronModelsDir
Definition: config.h:56
std::string spatialSynapseIndexDir
Definition: config.h:104
std::string spatialSegmentIndexDir
Definition: config.h:76
const std::vector< Modification > & getModifications() const noexcept
Method to return the full list of modifications in the Conditions section.
std::vector< Modification > modifications
List of modifications that mimics experimental manipulations to the circuit.
Definition: config.h:376
std::unordered_map< std::string, std::unordered_map< std::string, variantValueType > > mechanisms
Definition: config.h:374
std::string target
node_set specifying postsynaptic nodes
Definition: config.h:670
std::string name
the name of the connection override
Definition: config.h:666
std::string source
node_set specifying presynaptic nodes
Definition: config.h:668
std::string nodeSet
Node set which is affected by input.
Definition: config.h:458
InputType inputType
Type of input.
Definition: config.h:452
Module module
Type of stimulus.
Definition: config.h:450
std::string spikeFile
The location of the file with the spike info for injection, file extension must be ....
Definition: config.h:515
std::string nodeSet
Node set which receives the manipulation.
Definition: config.h:329
std::string name
Name of the modification setting.
Definition: config.h:333
ModificationType type
Name of the manipulation. Supported values are “TTX” and “ConfigureAllSections”.
Definition: config.h:331
Sections sections
Sections on which to report. Default value: "soma".
Definition: config.h:392
std::string variableName
Definition: config.h:404
std::string unit
Descriptive text of the unit recorded. Not validated for correctness.
Definition: config.h:406
Scaling scaling
Definition: config.h:397
Type type
Report type.
Definition: config.h:394
std::string cells
Node sets on which to report.
Definition: config.h:390
Compartments compartments
Definition: config.h:400
std::string fileName
Report filename. Default is "<report name>.h5".
Definition: config.h:414
Definition: config.h:270
std::string electrodesFile
Filename that contains the weights for the LFP calculation.
Definition: config.h:302