Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 0f7b4e4

Browse files
authored
Make documentation available for Python API (#345)
* CircuitConfig, NodeSets, and SimulationConfig didn't have a top level docstring and thus sphinx `automodule` wasn't displaying them * Many of the SimulationConfig were rooted in _libsonata, when they should be in SimulationConfig; this was refactored, however it has implications in the following projects: * BlueCelluLab was update to work around the change BlueBrain/BlueCelluLab#123 * SNAP tests have been updated to handle the different locations of SimulationConfig classes: BlueBrain/snap#254
1 parent 35e905a commit 0f7b4e4

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

docs/source/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20-
import os
2120
from pathlib import Path
2221
import pkg_resources
2322
import re

python/bindings.cpp

+30-27
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ PYBIND11_MODULE(_libsonata, m) {
527527

528528
bindStorageClass<NodeStorage>(m, "NodeStorage", "NodePopulation");
529529

530-
py::class_<NodeSets>(m, "NodeSets", "")
530+
py::class_<NodeSets>(m, "NodeSets", "NodeSets")
531531
.def(py::init<const std::string&>())
532532
.def_static("from_file", [](py::object path) { return NodeSets::fromFile(py::str(path)); })
533533
.def_property_readonly("names", &NodeSets::names, DOC_NODESETS(names))
@@ -589,11 +589,11 @@ PYBIND11_MODULE(_libsonata, m) {
589589
.value("complete", CircuitConfig::ConfigStatus::complete)
590590
.value("partial", CircuitConfig::ConfigStatus::partial);
591591

592-
py::class_<CircuitConfig>(m, "CircuitConfig", "")
592+
py::class_<CircuitConfig>(m, "CircuitConfig", "Circuit Configuration")
593593
.def(py::init<const std::string&, const std::string&>())
594594
.def_static("from_file",
595595
[](py::object path) { return CircuitConfig::fromFile(py::str(path)); })
596-
.def_property_readonly("config_status", &CircuitConfig::getCircuitConfigStatus)
596+
.def_property_readonly("config_status", &CircuitConfig::getCircuitConfigStatus, "ibid")
597597
.def_property_readonly("node_sets_path", &CircuitConfig::getNodeSetsPath)
598598
.def_property_readonly("node_populations", &CircuitConfig::listNodePopulations)
599599
.def("node_population",
@@ -613,7 +613,8 @@ PYBIND11_MODULE(_libsonata, m) {
613613
.def("edge_population_properties", &CircuitConfig::getEdgePopulationProperties, "name"_a)
614614
.def_property_readonly("expanded_json", &CircuitConfig::getExpandedJSON);
615615

616-
py::class_<SimulationConfig::Run> run(m,
616+
py::class_<SimulationConfig> simConf(m, "SimulationConfig", "Simulation Configuration");
617+
py::class_<SimulationConfig::Run> run(simConf,
617618
"Run",
618619
"Stores parameters defining global simulation settings");
619620
run.def_readonly("tstop", &SimulationConfig::Run::tstop, DOC_SIMULATIONCONFIG(Run, tstop))
@@ -648,7 +649,9 @@ PYBIND11_MODULE(_libsonata, m) {
648649
.value("nicholson", SimulationConfig::Run::IntegrationMethod::nicholson)
649650
.value("nicholson_ion", SimulationConfig::Run::IntegrationMethod::nicholson_ion);
650651

651-
py::class_<SimulationConfig::Output> output(m, "Output", "Parameters of simulation output");
652+
py::class_<SimulationConfig::Output> output(simConf,
653+
"Output",
654+
"Parameters of simulation output");
652655
output
653656
.def_readonly("output_dir",
654657
&SimulationConfig::Output::outputDir,
@@ -672,7 +675,7 @@ PYBIND11_MODULE(_libsonata, m) {
672675
.value("by_time", SimulationConfig::Output::SpikesSortOrder::by_time);
673676

674677
py::class_<SimulationConfig::Conditions> conditions(
675-
m, "Conditions", "Parameters defining global experimental conditions");
678+
simConf, "Conditions", "Parameters defining global experimental conditions");
676679
conditions
677680
.def_readonly("celsius",
678681
&SimulationConfig::Conditions::celsius,
@@ -705,7 +708,7 @@ PYBIND11_MODULE(_libsonata, m) {
705708
.value("soma", SimulationConfig::Conditions::SpikeLocation::soma)
706709
.value("AIS", SimulationConfig::Conditions::SpikeLocation::AIS);
707710

708-
py::class_<SimulationConfig::ModificationBase> modificationBase(m, "ModificationBase");
711+
py::class_<SimulationConfig::ModificationBase> modificationBase(simConf, "ModificationBase");
709712
modificationBase
710713
.def_readonly("node_set",
711714
&SimulationConfig::ModificationBase::nodeSet,
@@ -715,10 +718,10 @@ PYBIND11_MODULE(_libsonata, m) {
715718
DOC_SIMULATIONCONFIG(ModificationBase, type));
716719

717720
py::class_<SimulationConfig::ModificationTTX, SimulationConfig::ModificationBase>(
718-
m, "ModificationTTX");
721+
simConf, "ModificationTTX");
719722

720723
py::class_<SimulationConfig::ModificationConfigureAllSections,
721-
SimulationConfig::ModificationBase>(m, "ModificationConfigureAllSections")
724+
SimulationConfig::ModificationBase>(simConf, "ModificationConfigureAllSections")
722725
.def_readonly("section_configure",
723726
&SimulationConfig::ModificationConfigureAllSections::sectionConfigure,
724727
DOC_SIMULATIONCONFIG(ModificationConfigureAllSections, sectionConfigure));
@@ -732,7 +735,7 @@ PYBIND11_MODULE(_libsonata, m) {
732735
SimulationConfig::ModificationBase::ModificationType::ConfigureAllSections,
733736
DOC_SIMULATIONCONFIG(ModificationBase, ModificationType, ConfigureAllSections));
734737

735-
py::class_<SimulationConfig::Report> report(m, "Report", "Parameters of a report");
738+
py::class_<SimulationConfig::Report> report(simConf, "Report", "Parameters of a report");
736739
report
737740
.def_readonly("cells",
738741
&SimulationConfig::Report::cells,
@@ -796,7 +799,7 @@ PYBIND11_MODULE(_libsonata, m) {
796799
.value("center", SimulationConfig::Report::Compartments::center)
797800
.value("all", SimulationConfig::Report::Compartments::all);
798801

799-
py::class_<SimulationConfig::InputBase> inputBase(m, "InputBase");
802+
py::class_<SimulationConfig::InputBase> inputBase(simConf, "InputBase");
800803
inputBase
801804
.def_readonly("module",
802805
&SimulationConfig::InputBase::module,
@@ -814,15 +817,15 @@ PYBIND11_MODULE(_libsonata, m) {
814817
&SimulationConfig::InputBase::nodeSet,
815818
DOC_SIMULATIONCONFIG(InputBase, nodeSet));
816819

817-
py::class_<SimulationConfig::InputLinear, SimulationConfig::InputBase>(m, "Linear")
820+
py::class_<SimulationConfig::InputLinear, SimulationConfig::InputBase>(simConf, "Linear")
818821
.def_readonly("amp_start",
819822
&SimulationConfig::InputLinear::ampStart,
820823
DOC_SIMULATIONCONFIG(InputLinear, ampStart))
821824
.def_readonly("amp_end",
822825
&SimulationConfig::InputLinear::ampEnd,
823826
DOC_SIMULATIONCONFIG(InputLinear, ampEnd));
824827

825-
py::class_<SimulationConfig::InputRelativeLinear, SimulationConfig::InputBase>(m,
828+
py::class_<SimulationConfig::InputRelativeLinear, SimulationConfig::InputBase>(simConf,
826829
"RelativeLinear")
827830
.def_readonly("percent_start",
828831
&SimulationConfig::InputRelativeLinear::percentStart,
@@ -831,7 +834,7 @@ PYBIND11_MODULE(_libsonata, m) {
831834
&SimulationConfig::InputRelativeLinear::percentEnd,
832835
DOC_SIMULATIONCONFIG(InputRelativeLinear, percentEnd));
833836

834-
py::class_<SimulationConfig::InputPulse, SimulationConfig::InputBase>(m, "Pulse")
837+
py::class_<SimulationConfig::InputPulse, SimulationConfig::InputBase>(simConf, "Pulse")
835838
.def_readonly("amp_start",
836839
&SimulationConfig::InputPulse::ampStart,
837840
DOC_SIMULATIONCONFIG(InputPulse, ampStart))
@@ -845,15 +848,16 @@ PYBIND11_MODULE(_libsonata, m) {
845848
&SimulationConfig::InputPulse::frequency,
846849
DOC_SIMULATIONCONFIG(InputPulse, frequency));
847850

848-
py::class_<SimulationConfig::InputSubthreshold, SimulationConfig::InputBase>(m, "Subthreshold")
851+
py::class_<SimulationConfig::InputSubthreshold, SimulationConfig::InputBase>(simConf,
852+
"Subthreshold")
849853
.def_readonly("percent_less",
850854
&SimulationConfig::InputSubthreshold::percentLess,
851855
DOC_SIMULATIONCONFIG(InputSubthreshold, percentLess));
852856

853857
py::class_<SimulationConfig::InputHyperpolarizing, SimulationConfig::InputBase>(
854-
m, "Hyperpolarizing");
858+
simConf, "Hyperpolarizing");
855859

856-
py::class_<SimulationConfig::InputSynapseReplay, SimulationConfig::InputBase>(m,
860+
py::class_<SimulationConfig::InputSynapseReplay, SimulationConfig::InputBase>(simConf,
857861
"SynapseReplay")
858862
.def_readonly("spike_file",
859863
&SimulationConfig::InputSynapseReplay::spikeFile,
@@ -862,15 +866,15 @@ PYBIND11_MODULE(_libsonata, m) {
862866
&SimulationConfig::InputSynapseReplay::source,
863867
DOC_SIMULATIONCONFIG(InputSynapseReplay, source));
864868

865-
py::class_<SimulationConfig::InputSeclamp, SimulationConfig::InputBase>(m, "Seclamp")
869+
py::class_<SimulationConfig::InputSeclamp, SimulationConfig::InputBase>(simConf, "Seclamp")
866870
.def_readonly("voltage",
867871
&SimulationConfig::InputSeclamp::voltage,
868872
DOC_SIMULATIONCONFIG(InputSeclamp, voltage))
869873
.def_readonly("series_resistance",
870874
&SimulationConfig::InputSeclamp::seriesResistance,
871875
DOC_SIMULATIONCONFIG(InputSeclamp, seriesResistance));
872876

873-
py::class_<SimulationConfig::InputNoise, SimulationConfig::InputBase>(m, "Noise")
877+
py::class_<SimulationConfig::InputNoise, SimulationConfig::InputBase>(simConf, "Noise")
874878
.def_readonly("mean",
875879
&SimulationConfig::InputNoise::mean,
876880
DOC_SIMULATIONCONFIG(InputNoise, mean))
@@ -881,7 +885,7 @@ PYBIND11_MODULE(_libsonata, m) {
881885
&SimulationConfig::InputNoise::variance,
882886
DOC_SIMULATIONCONFIG(InputNoise, variance));
883887

884-
py::class_<SimulationConfig::InputShotNoise, SimulationConfig::InputBase>(m, "ShotNoise")
888+
py::class_<SimulationConfig::InputShotNoise, SimulationConfig::InputBase>(simConf, "ShotNoise")
885889
.def_readonly("rise_time",
886890
&SimulationConfig::InputShotNoise::riseTime,
887891
DOC_SIMULATIONCONFIG(InputShotNoise, riseTime))
@@ -908,7 +912,7 @@ PYBIND11_MODULE(_libsonata, m) {
908912
DOC_SIMULATIONCONFIG(InputShotNoise, ampVar));
909913

910914
py::class_<SimulationConfig::InputRelativeShotNoise, SimulationConfig::InputBase>(
911-
m, "RelativeShotNoise")
915+
simConf, "RelativeShotNoise")
912916
.def_readonly("rise_time",
913917
&SimulationConfig::InputRelativeShotNoise::riseTime,
914918
DOC_SIMULATIONCONFIG(InputRelativeShotNoise, riseTime))
@@ -935,7 +939,7 @@ PYBIND11_MODULE(_libsonata, m) {
935939
DOC_SIMULATIONCONFIG(InputRelativeShotNoise, meanPercent));
936940

937941
py::class_<SimulationConfig::InputAbsoluteShotNoise, SimulationConfig::InputBase>(
938-
m, "AbsoluteShotNoise")
942+
simConf, "AbsoluteShotNoise")
939943
.def_readonly("rise_time",
940944
&SimulationConfig::InputAbsoluteShotNoise::riseTime,
941945
DOC_SIMULATIONCONFIG(InputAbsoluteShotNoise, riseTime))
@@ -962,7 +966,7 @@ PYBIND11_MODULE(_libsonata, m) {
962966
DOC_SIMULATIONCONFIG(InputAbsoluteShotNoise, sigma));
963967

964968
py::class_<SimulationConfig::InputOrnsteinUhlenbeck, SimulationConfig::InputBase>(
965-
m, "OrnsteinUhlenbeck")
969+
simConf, "OrnsteinUhlenbeck")
966970
.def_readonly("tau",
967971
&SimulationConfig::InputOrnsteinUhlenbeck::tau,
968972
DOC_SIMULATIONCONFIG(InputOrnsteinUhlenbeck, tau))
@@ -983,7 +987,7 @@ PYBIND11_MODULE(_libsonata, m) {
983987
DOC_SIMULATIONCONFIG(InputOrnsteinUhlenbeck, sigma));
984988

985989
py::class_<SimulationConfig::InputRelativeOrnsteinUhlenbeck, SimulationConfig::InputBase>(
986-
m, "RelativeOrnsteinUhlenbeck")
990+
simConf, "RelativeOrnsteinUhlenbeck")
987991
.def_readonly("tau",
988992
&SimulationConfig::InputRelativeOrnsteinUhlenbeck::tau,
989993
DOC_SIMULATIONCONFIG(InputRelativeOrnsteinUhlenbeck, tau))
@@ -1027,7 +1031,7 @@ PYBIND11_MODULE(_libsonata, m) {
10271031
.value("voltage_clamp", SimulationConfig::InputBase::InputType::voltage_clamp)
10281032
.value("conductance", SimulationConfig::InputBase::InputType::conductance);
10291033

1030-
py::class_<SimulationConfig::ConnectionOverride>(m,
1034+
py::class_<SimulationConfig::ConnectionOverride>(simConf,
10311035
"ConnectionOverride",
10321036
"List of parameters of a connection")
10331037
.def_readonly("name",
@@ -1064,7 +1068,6 @@ PYBIND11_MODULE(_libsonata, m) {
10641068
&SimulationConfig::ConnectionOverride::neuromodulationStrength,
10651069
DOC_SIMULATIONCONFIG(ConnectionOverride, neuromodulationStrength));
10661070

1067-
py::class_<SimulationConfig> simConf(m, "SimulationConfig", "");
10681071
simConf.def(py::init<const std::string&, const std::string&>())
10691072
.def_static(
10701073
"from_file",
@@ -1113,7 +1116,7 @@ PYBIND11_MODULE(_libsonata, m) {
11131116
&SimulationConfig::getBetaFeatures,
11141117
DOC_SIMULATIONCONFIG(getBetaFeatures));
11151118

1116-
py::enum_<SimulationConfig::SimulatorType>(simConf, "SimulatorType")
1119+
py::enum_<SimulationConfig::SimulatorType>(simConf, "SimulatorType", "SimulatorType Enum")
11171120
.value("NEURON", SimulationConfig::SimulatorType::NEURON)
11181121
.value("CORENEURON", SimulationConfig::SimulatorType::CORENEURON);
11191122

python/libsonata/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Hdf5Reader,
2727
)
2828

29+
2930
__all__ = [
3031
"CircuitConfig",
3132
"CircuitConfigStatus",

python/tests/test_config.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
)
77

88

9-
from libsonata._libsonata import Report, Output, Run, Conditions
10-
11-
129
PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
1310
'../../tests/data')
1411

@@ -411,7 +408,8 @@ def test_basic(self):
411408
self.assertEqual(self.config.run.dt, 0.025)
412409
self.assertEqual(self.config.run.random_seed, 201506)
413410
self.assertEqual(self.config.run.spike_threshold, -35.5)
414-
self.assertEqual(self.config.run.integration_method, Run.IntegrationMethod.nicholson_ion)
411+
self.assertEqual(self.config.run.integration_method,
412+
SimulationConfig.Run.IntegrationMethod.nicholson_ion)
415413
self.assertEqual(self.config.run.stimulus_seed, 111)
416414
self.assertEqual(self.config.run.ionchannel_seed, 222)
417415
self.assertEqual(self.config.run.minis_seed, 333)
@@ -423,11 +421,13 @@ def test_basic(self):
423421
os.path.abspath(os.path.join(PATH, 'config/some/path/output')))
424422
self.assertEqual(self.config.output.spikes_file, 'out.h5')
425423
self.assertEqual(self.config.output.log_file, '')
426-
self.assertEqual(self.config.output.spikes_sort_order, Output.SpikesSortOrder.by_id)
424+
self.assertEqual(self.config.output.spikes_sort_order,
425+
SimulationConfig.Output.SpikesSortOrder.by_id)
427426

428427
self.assertEqual(self.config.conditions.celsius, 35.0)
429428
self.assertEqual(self.config.conditions.v_init, -80)
430-
self.assertEqual(self.config.conditions.spike_location, Conditions.SpikeLocation.AIS)
429+
self.assertEqual(self.config.conditions.spike_location,
430+
SimulationConfig.Conditions.SpikeLocation.AIS)
431431
self.assertEqual(self.config.conditions.extracellular_calcium, None)
432432
self.assertEqual(self.config.conditions.randomize_gaba_rise_time, False)
433433
self.assertEqual(self.config.conditions.mechanisms, {'ProbAMPANMDA_EMS': {'property2': -1,
@@ -446,6 +446,7 @@ def test_basic(self):
446446
self.assertEqual(self.config.list_report_names,
447447
{ "axonal_comp_centers", "cell_imembrane", "compartment", "soma", "lfp" })
448448

449+
Report = SimulationConfig.Report
449450
self.assertEqual(self.config.report('soma').cells, 'Column')
450451
self.assertEqual(self.config.report('soma').type, Report.Type.compartment)
451452
self.assertEqual(self.config.report('soma').compartments, Report.Compartments.center)

0 commit comments

Comments
 (0)