Skip to content

Commit 396fbed

Browse files
authored
Merge pull request #27 from openworm/test_neuroml_apdp_1
Test neuroml apdp 1
2 parents 2e15467 + 98eb27c commit 396fbed

22 files changed

+430
-196
lines changed

.github/workflows/ci-make.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
7373
- name: Test Python command line script
7474
run: |
75-
python run_main.py -R 1233 -p 6 --doEvol --folderName exampleRun2 # Note: small population of 6 for quick runtime
75+
python run_main.py -R 1233 -p 6 --doEvol --outputFolderName exampleRun2 # Note: small population of 6 for quick runtime
7676
7777
- name: Test using test_all.sh
7878
run: |

.test.example.mep

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ system: Testing activity of some neurons
33
experiments:
44
Test:
55
expected:
6-
spike times: [0.605, 4.955, 10.055, 14.805, 19.605, 24.405, 29.155]
6+
spike times: [0.605, 4.955, 10.055, 14.805, 19.605, 24.405, 29.155]

.test.example.omt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ experiments:
1515
spike detection:
1616
method: threshold
1717
threshold: 2
18-
tolerance: 0
18+
tolerance: 0

.test.nmlNS.omt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ experiments:
1515
spike detection:
1616
method: threshold
1717
threshold: 2
18-
tolerance: 0.008264462809917363
18+
tolerance: 0.04027846842366976

Mainvars.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ extern const int SR_B;
2525

2626
// Size of genotype
2727
extern int VectSize;
28-
extern string output_dir_name;
28+
//extern string output_dir_name;
2929
//extern int nn(int, int);
30-
extern string nervousSystemName;
31-
extern string nervousSystemNameForSim;
32-
extern string nervousSystemNameForEvol;
30+
//extern string nervousSystemName;
31+
//extern string nervousSystemNameForSim;
32+
//extern string nervousSystemNameForEvol;

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ random.o: random.cpp random.h VectorMatrix.h
2727
TSearch.o: TSearch.cpp TSearch.h
2828
g++ -c -O3 -flto TSearch.cpp
2929

30-
jsonUtils.o: jsonUtils.cpp jsonUtils.h Worm.h
30+
jsonUtils.o: jsonUtils.cpp jsonUtils.h
3131
g++ -c -O3 -std=c++11 -I/opt/homebrew/Cellar/nlohmann-json/3.11.3/include -flto $(CXXFLAGS) $(LDFLAGS) jsonUtils.cpp
3232

3333
utils.o: utils.cpp utils.h
@@ -49,7 +49,7 @@ StretchReceptor.o: StretchReceptor.cpp StretchReceptor.h
4949
Muscles.o: Muscles.cpp Muscles.h VectorMatrix.h random.h
5050
g++ -c -O3 -flto Muscles.cpp
5151
main.o: main.cpp Worm.h WormBody.h StretchReceptor.h Muscles.h TSearch.h
52-
g++ -c -O3 -flto $(CXXFLAGS) $(LDFLAGS) main.cpp
52+
g++ -c -O3 -std=c++11 -flto $(CXXFLAGS) $(LDFLAGS) main.cpp
5353
tests.o: tests.cpp NervousSystem.o random.o
5454
g++ -c -O3 -flto tests.cpp
5555
tests: info tests.o

Worm.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@
77
//
88

99
#include "Worm.h"
10-
10+
#include "utils.h"
1111

1212
int nn(int neuronNumber, int unitNumber)
1313
{
1414
return neuronNumber+((unitNumber-1)*N_neuronsperunit);
1515
}
1616

17-
string nervousSystemName = "NervousSystem";
18-
string nervousSystemNameForSim = "nmlNervousSystem";
19-
string nervousSystemNameForEvol = "NervousSystem";
20-
21-
bool checkNervousSystemForJson(){
22-
return (strcmp(nervousSystemName.c_str(),"NervousSystem") == 0);
23-
}
24-
2517
NervousSystemBase* makeNervousSystem()
2618
{
2719
if (checkNervousSystemForJson()) return new NervousSystem();

Worm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Eduardo Izquierdo on 9/25/15.
66
// Copyright © 2015 Eduardo Izquierdo. All rights reserved.
77
//
8-
8+
#pragma once
99
#include "VectorMatrix.h"
1010
#include "random.h"
1111
#include "WormBody.h"

exampleRun/simulation_pars.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"doNML": 0,
3+
"seed": 1233,
4+
"Duration": 24
5+
}

exampleRun/worm_data.json

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@
6161
"value": 0.41666666666666663
6262
}
6363
},
64+
"Evolutionary Optimization Parameters": {
65+
"Duration": {
66+
"message": "optimization simulation duration",
67+
"value": 24
68+
},
69+
"pop_size": {
70+
"message": "population size",
71+
"value": 96
72+
},
73+
"randomseed": {
74+
"message": "seed",
75+
"value": 1233
76+
}
77+
},
6478
"Fitness traj": {
6579
"AvgSpeed": {
6680
"message": "Average speed of the worm in meters per second",

jsonUtils.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <functional>
66
#include <vector>
77
#include <nlohmann/json.hpp>
8-
//#include "utils.h"
8+
#include "utils.h"
99
#include "jsonUtils.h"
1010
#include "Mainvars.h"
1111

@@ -682,10 +682,10 @@ n.InternalSetElectricalSynapseWeight(elec_weights[i].w.from, elec_weights[i].to,
682682
}
683683

684684

685-
void writeParsToJson(wormForJson & w, string file_name)
685+
686+
void writeParsToJson(json & j, wormForJson & w, string file_name)
686687
{
687688

688-
json j;
689689
{Params<double> par = getBodyParams(w.b);
690690
appendToJson<double>(j["Body"],par);}
691691

@@ -760,6 +760,27 @@ void writeParsToJson(wormForJson & w)
760760
writeParsToJson(w, "worm_data.json");
761761
}
762762

763+
764+
void writeParsToJson(wormForJson & w, string file_name)
765+
{
766+
json j;
767+
writeParsToJson(j,w,file_name);
768+
}
769+
770+
void writeParsToJson(wormForJson & w, string file_name, vector<doubIntParamsHead> & parvec)
771+
{
772+
json j;
773+
774+
for (size_t i=0;i<parvec.size(); i++) {
775+
if (strcmp(parvec[i].parDoub.head.c_str(),"NULL")!=0)
776+
appendToJson<double>(j[parvec[i].parDoub.head],parvec[i].parDoub);
777+
if (strcmp(parvec[i].parInt.head.c_str(),"NULL")!=0)
778+
appendToJson<long>(j[parvec[i].parInt.head],parvec[i].parInt);
779+
}
780+
writeParsToJson(j,w,file_name);
781+
}
782+
783+
763784
void readJson(json j, ifstream & ifs)
764785
{
765786
ifs >> j;

jsonUtils.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#pragma once
12
#include "Worm.h"
23
#include <vector>
34
#include <string>
45
#include "utils.h"
6+
//#include <nlohmann/json.hpp>
57

6-
//#pragma once
7-
8+
//using json = nlohmann::json;
89
using namespace std;
910
using wormForJson = Worm;
1011

@@ -20,10 +21,16 @@ vector<string> messages;
2021
template <class T>
2122
struct ParamsHead : Params<T> {
2223
ParamsHead(string head_val, Params<T> par_val):Params<T>(par_val){head=head_val;}
23-
ParamsHead():Params<T>(){}
24+
ParamsHead():Params<T>(){head = "NULL";}
2425
string head;
2526
};
2627

28+
struct doubIntParamsHead
29+
{
30+
ParamsHead<double> parDoub;
31+
ParamsHead<long> parInt;
32+
};
33+
2734

2835
//ifstream & setParamsFromDump(ifstream &ifs, Worm<NervousSystem> &);
2936
ifstream & setParamsFromDump(ifstream &ifs, wormForJson &);
@@ -40,7 +47,8 @@ void setNSFromJsonFile(ifstream & ifs, NervousSystem & n);
4047

4148

4249
void writeWormParams(wormForJson & w);
43-
50+
void writeParsToJson(wormForJson & w, string file_name, vector<doubIntParamsHead> & parvec);
51+
//void writeParsToJson(json & j, wormForJson & w, string file_name);
4452
void writeParsToJson(wormForJson &, string);
4553
void writeParsToJson(wormForJson &);
4654
void testNervousSystemJson(string, NervousSystem &);

0 commit comments

Comments
 (0)