Skip to content

Commit d0d6d05

Browse files
authored
Merge pull request #95 from ControlCore-Project/main
Bring dev to the recent
2 parents 78be237 + 1091829 commit d0d6d05

4,468 files changed

Lines changed: 1697380 additions & 29 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

concore.hpp

Lines changed: 336 additions & 11 deletions
Large diffs are not rendered by default.

demo/gencon2.graphml

Lines changed: 964 additions & 0 deletions
Large diffs are not rendered by default.

demo/gencontrol.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import numpy as np
2+
import concore
3+
4+
ysp = 3.0
5+
6+
# controller function
7+
def controller(ym):
8+
if ym[0] < ysp:
9+
return 1.01 * ym
10+
else:
11+
return 0.9 * ym
12+
13+
# main
14+
concore.default_maxtime(150)
15+
concore.delay = 0.02
16+
17+
# initial values -- transforms to string including the simtime as the 0th entry in the list
18+
init_simtime_u = "[0.0, 0.0]"
19+
init_simtime_ym = "[0.0, 0.0]"
20+
21+
u = np.array([concore.initval(init_simtime_u)]).T
22+
while(concore.simtime<10):
23+
while concore.unchanged():
24+
ym = concore.read(concore.iport['SYM'],"ym",init_simtime_ym)
25+
ym = np.array([ym]).T
26+
#####
27+
u = controller(ym)
28+
#####
29+
print("****"+str(concore.simtime) + ". u="+str(u) + "ym="+str(ym))
30+
concore.write(concore.oport['SU'],"u",list(u.T[0]),delta=0)
31+
32+
concore.write(concore.oport['CU'],"u",list(u.T[0]),delta=0)
33+
34+
while(concore.simtime<concore.maxtime):
35+
while concore.unchanged():
36+
ym = concore.read(concore.iport['PYM'],"ym",init_simtime_ym)
37+
ym = np.array([ym]).T
38+
#####
39+
u = controller(ym)
40+
#####
41+
print(str(concore.simtime) + ". u="+str(u) + "ym="+str(ym))
42+
concore.write(concore.oport['CU'],"u",list(u.T[0]),delta=0)
43+
44+
concore.write(concore.oport['SU'],"u",list(u.T[0]),delta=0)
45+
print("retry="+str(concore.retrycount))

demo/generalcontrol.graphml

Lines changed: 699 additions & 0 deletions
Large diffs are not rendered by default.

demo/generalcontroler.graphml

Lines changed: 723 additions & 0 deletions
Large diffs are not rendered by default.

fri/server/main.py

Lines changed: 163 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import Flask, request, jsonify, send_file, send_from_directory
22
from werkzeug.utils import secure_filename
3+
import xml.etree.ElementTree as ET
34
import os
45
import subprocess
56
from subprocess import call,check_output
@@ -18,6 +19,17 @@
1819
cors = CORS(app)
1920
app.config['CORS_HEADERS'] = 'Content-Type'
2021

22+
def check_node_labels(graphml_file):
23+
tree = ET.parse(graphml_file)
24+
root = tree.getroot()
25+
namespace = {'y': 'http://www.yworks.com/xml/graphml'}
26+
node_labels = root.findall('.//y:NodeLabel', namespace)
27+
for node_label in node_labels:
28+
label = node_label.text
29+
if label.endswith('.m'):
30+
return True
31+
return False
32+
2133
# To upload multiple file. For example, /upload/test?apikey=xyz
2234
@app.route('/upload/<dir>', methods=['POST'])
2335
def upload(dir):
@@ -65,9 +77,14 @@ def upload(dir):
6577
# to download /build/<dir>?fetch=<graphml>. For example, /build/test?fetch=sample1&apikey=xyz
6678
@app.route('/build/<dir>', methods=['POST'])
6779
def build(dir):
68-
graphml_file = request.args.get('fetch')
80+
graphml_file = request.args.get('fetch')
81+
params = request.args.get('params')
82+
docker = request.args.get('docker')
83+
octave = request.args.get('octave')
84+
maxtime = request.args.get('maxtime')
6985
apikey = request.args.get('apikey')
7086
out_dir = request.args.get('outdir')
87+
output_str = ""
7188
if(apikey == None):
7289
dirname = secure_filename(dir)
7390
else:
@@ -77,35 +94,132 @@ def build(dir):
7794
dir_path = os.path.abspath(os.path.join(concore_path, graphml_file)) #path for ./build
7895
else:
7996
dir_path = os.path.abspath(os.path.join(concore_path, out_dir)) #path for ./build
97+
98+
dotMCheck = check_node_labels(os.path.abspath(os.path.join(concore_path, makestudy_dir)) + '.graphml')
99+
if((dotMCheck == False or octave == 'false') and os.path.isfile(os.path.abspath(os.path.join(concore_path, 'concore.octave')))):
100+
if(platform.uname()[0]!='Windows'):
101+
proc= call(["rm", "concore.octave"], cwd=concore_path)
102+
else:
103+
proc= call(["del", "concore.octave"], shell=True, cwd=concore_path)
104+
105+
if(octave == 'true' and dotMCheck):
106+
if(platform.uname()[0]!='Windows'):
107+
proc= call(["touch", "concore.octave"], cwd=concore_path)
108+
else:
109+
proc= open(os.path.abspath(os.path.join(concore_path, 'concore.octave')), 'x')
110+
111+
80112
if not os.path.exists(dir_path):
81113
if(platform.uname()[0]=='Windows'):
82114
if(out_dir == None or out_dir == ""):
83-
proc= call(["makestudy", makestudy_dir], shell=True, cwd=concore_path)
115+
if(docker == 'true'):
116+
try:
117+
output_bytes = subprocess.check_output(["makedocker", makestudy_dir], cwd=concore_path, shell=True)
118+
output_str = output_bytes.decode("utf-8")
119+
proc = 0
120+
except subprocess.CalledProcessError as e:
121+
output_str = f"Docker study creation failed with return code {e.returncode} (check duplicate directory)"
122+
proc = 1
123+
else:
124+
try:
125+
output_bytes = subprocess.check_output(["makestudy", makestudy_dir], cwd=concore_path, shell=True)
126+
output_str = output_bytes.decode("utf-8")
127+
proc = 0
128+
except subprocess.CalledProcessError as e:
129+
output_str = f"Study creation failed with return code {e.returncode} (check duplicate directory)"
130+
proc = 1
84131
else:
85-
proc= call(["makestudy", makestudy_dir, out_dir], shell=True, cwd=concore_path)
132+
if(docker == 'true'):
133+
try:
134+
output_bytes = subprocess.check_output(["makedocker", makestudy_dir, out_dir], cwd=concore_path, shell=True)
135+
output_str = output_bytes.decode("utf-8")
136+
proc = 0
137+
except subprocess.CalledProcessError as e:
138+
output_str = f"Docker study creation failed with return code {e.returncode} (check duplicate directory)"
139+
proc = 1
140+
else:
141+
try:
142+
output_bytes = subprocess.check_output(["makestudy", makestudy_dir, out_dir], cwd=concore_path, shell=True)
143+
output_str = output_bytes.decode("utf-8")
144+
proc = 0
145+
except subprocess.CalledProcessError as e:
146+
output_str = f"Study creation failed with return code {e.returncode} (check duplicate directory)"
147+
proc = 1
86148
else:
87149
if(out_dir == None or out_dir == ""):
88-
proc= call(["./makestudy", makestudy_dir], cwd=concore_path)
150+
if(docker == 'true'):
151+
try:
152+
output_bytes = subprocess.check_output(["./makedocker", makestudy_dir], cwd=concore_path)
153+
output_str = output_bytes.decode("utf-8")
154+
proc = 0
155+
except subprocess.CalledProcessError as e:
156+
output_str = f"Docker study creation failed with return code {e.returncode} (check duplicate directory)"
157+
proc = 1
158+
else:
159+
try:
160+
output_bytes = subprocess.check_output(["./makestudy", makestudy_dir], cwd=concore_path)
161+
output_str = output_bytes.decode("utf-8")
162+
proc = 0
163+
except subprocess.CalledProcessError as e:
164+
output_str = f"Study creation failed with return code {e.returncode} (check duplicate directory)"
165+
proc = 1
89166
else:
90-
proc= call(["./makestudy", makestudy_dir, out_dir], cwd=concore_path)
167+
if(docker == 'true'):
168+
try:
169+
output_bytes = subprocess.check_output(["./makedocker", makestudy_dir, out_dir], cwd=concore_path)
170+
output_str = output_bytes.decode("utf-8")
171+
proc = 0
172+
except subprocess.CalledProcessError as e:
173+
output_str = f"Docker study creation failed with return code {e.returncode} (check duplicate directory)"
174+
proc = 1
175+
else:
176+
try:
177+
output_bytes = subprocess.check_output(["./makestudy", makestudy_dir, out_dir], cwd=concore_path)
178+
output_str = output_bytes.decode("utf-8")
179+
proc = 0
180+
except subprocess.CalledProcessError as e:
181+
output_str = f"Study creation failed with return code {e.returncode} (check duplicate directory)"
182+
proc = 1
91183
if(proc == 0):
92184
resp = jsonify({'message': 'Directory successfully created'})
93185
resp.status_code = 201
94186
else:
95187
resp = jsonify({'message': 'There is an Error'})
96-
resp.status_code = 500
188+
resp.status_code = 500
97189
if(platform.uname()[0]=='Windows'):
98-
call(["build"], cwd=dir_path, shell=True)
190+
try:
191+
output_bytes = subprocess.check_output("build", cwd=dir_path, shell=True)
192+
output_str = output_str + output_bytes.decode("utf-8")
193+
resp = jsonify({'message': 'Directory successfully created', 'output': output_str})
194+
except subprocess.CalledProcessError as e:
195+
output_str = f"Build failed with return code {e.returncode}"
196+
resp = jsonify({'message': 'Build Failed', 'output': output_str})
197+
resp.status_code = 500
198+
if(maxtime != None and maxtime != ''):
199+
proc=call(["maxtime", maxtime],shell=True, cwd=dir_path)
200+
if(params != None and params != ''):
201+
proc=call(["params", params],shell=True, cwd=dir_path)
99202
else:
100-
call(["./build"], cwd=dir_path)
203+
try:
204+
output_bytes = subprocess.check_output("./build", cwd=dir_path)
205+
output_str = output_str + output_bytes.decode("utf-8")
206+
resp = jsonify({'message': 'Directory successfully created', 'output': output_str})
207+
except subprocess.CalledProcessError as e:
208+
output_str = f"Build failed with return code {e.returncode}"
209+
resp = jsonify({'message': 'Build Failed', 'output': output_str})
210+
resp.status_code = 500
211+
if(maxtime != None and maxtime != ''):
212+
proc=call(["./maxtime", maxtime], cwd=dir_path)
213+
if(params != None and params != ''):
214+
proc=call(["./params", params], cwd=dir_path)
101215
return resp
102216

103217
@app.route('/debug/<dir>', methods=['POST'])
104218
def debug(dir):
105219
dir_name = secure_filename(dir)
106220
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
107221
if(platform.uname()[0]=='Windows'):
108-
proc=call(["debug"],shell=True, cwd=dir_path)
222+
proc = call(["debug"],shell=True, cwd=dir_path)
109223
else:
110224
proc = call(["./debug"], cwd=dir_path)
111225
if(proc == 0):
@@ -122,7 +236,7 @@ def run(dir):
122236
dir_name = secure_filename(dir)
123237
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
124238
if(platform.uname()[0]=='Windows'):
125-
proc=call(["run"],shell=True, cwd=dir_path)
239+
proc = call(["run"],shell=True, cwd=dir_path)
126240
else:
127241
proc = call(["./run"], cwd=dir_path)
128242
if(proc == 0):
@@ -139,7 +253,7 @@ def stop(dir):
139253
dir_name = secure_filename(dir)
140254
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
141255
if(platform.uname()[0]=='Windows'):
142-
proc=call(["stop"],shell=True, cwd=dir_path)
256+
proc = call(["stop"],shell=True, cwd=dir_path)
143257
else:
144258
proc = call(["./stop"], cwd=dir_path)
145259
if(proc == 0):
@@ -154,12 +268,23 @@ def stop(dir):
154268

155269
@app.route('/clear/<dir>', methods=['POST'])
156270
def clear(dir):
271+
unlock = request.args.get('unlock')
272+
params = request.args.get('params')
273+
maxtime = request.args.get('maxtime')
157274
dir_name = secure_filename(dir)
158275
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
159276
if(platform.uname()[0]=='Windows'):
160-
proc=call(["clear"],shell=True, cwd=dir_path)
277+
proc = call(["clear"],shell=True, cwd=dir_path)
278+
if(maxtime != None and maxtime != ''):
279+
proc = call(["maxtime", maxtime],shell=True, cwd=dir_path)
280+
if(params != None and params != ''):
281+
proc = call(["params", params],shell=True, cwd=dir_path)
161282
else:
162283
proc = call(["./clear"], cwd=dir_path)
284+
if(maxtime != None and maxtime != ''):
285+
proc = call(["./maxtime", maxtime], cwd=dir_path)
286+
if(params != None and params != ''):
287+
proc = call(["./params", params], cwd=dir_path)
163288
if(proc == 0):
164289
resp = jsonify({'message': 'result deleted'})
165290
resp.status_code = 201
@@ -222,7 +347,7 @@ def download(dir):
222347
def destroy(dir):
223348
dir = secure_filename(dir)
224349
if(platform.uname()[0]=='Windows'):
225-
proc=call(["destroy", dir],shell=True, cwd=concore_path)
350+
proc = call(["destroy", dir],shell=True, cwd=concore_path)
226351
else:
227352
proc = call(["./destroy", dir], cwd=concore_path)
228353
if(proc == 0):
@@ -232,7 +357,31 @@ def destroy(dir):
232357
else:
233358
resp = jsonify({'message': 'There is an Error'})
234359
resp.status_code = 500
235-
return resp
360+
return resp
361+
362+
@app.route('/library/<dir>', methods=['POST'])
363+
def library(dir):
364+
dir_name = secure_filename(dir)
365+
dir_path = os.path.abspath(os.path.join(concore_path, dir_name))
366+
filename = request.args.get('filename')
367+
library_path = request.args.get('path')
368+
proc = 0
369+
if (library_path == None or library_path == ''):
370+
library_path = "../tools"
371+
if(platform.uname()[0]=='Windows'):
372+
proc = subprocess.check_output(["..\library", library_path, filename],shell=True, cwd=dir_path)
373+
else:
374+
proc = subprocess.check_output(["../library", library_path, filename], cwd=dir_path)
375+
if(proc != 0):
376+
resp = jsonify({'message': proc.decode("utf-8")})
377+
resp.status_code = 201
378+
return resp
379+
else:
380+
resp = jsonify({'message': 'There is an Error'})
381+
resp.status_code = 500
382+
return resp
383+
384+
236385

237386
@app.route('/getFilesList/<dir>', methods=['POST'])
238387
def getFilesList(dir):

humanc/dummy/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Human cardiac (humanc) models

library

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
if [ $# = 0 ]
3+
then
4+
echo "library -- create a link that references "library" program or dir"
5+
else
6+
tooldir="../tools"
7+
if [ $# = 1 ]
8+
then
9+
filename=$1
10+
elif [ $# = 2 ]
11+
then
12+
tooldir=$1
13+
filename=$2
14+
else
15+
echo "too many args"
16+
exit
17+
fi
18+
if [ -e $filename ]
19+
then
20+
echo "cannot create library link over existing file"
21+
exit
22+
fi
23+
if [ -d $tooldir ]
24+
then
25+
if [ -e $tooldir/$filename ]
26+
then
27+
ln -s $tooldir/$filename $filename
28+
echo "library link created"
29+
else
30+
echo "$filename does not exist in $tooldir"
31+
fi
32+
else
33+
echo "$tooldir does not exist"
34+
fi
35+
fi
36+

library.bat

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@echo off
2+
if "%2" == "" (
3+
if exist "..\tools\%1" (
4+
if exist "%1" (
5+
echo "cannot create library link over existing file"
6+
) else (
7+
echo "mklink %1 ..\tools\%1"
8+
mklink "%1" "..\tools\%1"
9+
)
10+
) else (
11+
echo "..\tools\%1 does not exist"
12+
)
13+
) else (
14+
if exist "%1\%2" (
15+
if exist "%2" (
16+
echo "cannot create library link over existing file"
17+
) else (
18+
echo "mklink %2 %1\%2"
19+
mklink "%2" "%1\%2"
20+
)
21+
) else (
22+
echo "%1\%2 does not exist"
23+
)
24+
)
25+

0 commit comments

Comments
 (0)