Skip to content

Commit 08ce4fe

Browse files
committed
mayuresh, funbody, funcall
1 parent 200ca39 commit 08ce4fe

15 files changed

Lines changed: 2742 additions & 0 deletions

concore.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
print("bad params: "+sparams)
4646
except:
4747
params = dict()
48+
#9/30/22
49+
def tryparam(n,i):
50+
try:
51+
return params[n]
52+
except:
53+
return i
54+
4855

4956
#9/12/21
5057
def default_maxtime(default):

concoredocker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
print("bad params: "+sparams)
3636
except:
3737
params = dict()
38+
#9/30/22
39+
def tryparam(n,i):
40+
try:
41+
return params[n]
42+
except:
43+
return i
3844

3945
#9/12/21
4046
def default_maxtime(default):

testsou/funbody.dir/concore2.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import time
2+
import os
3+
from ast import literal_eval
4+
import sys
5+
import re
6+
7+
#if windows, create script to kill this process
8+
# because batch files don't provide easy way to know pid of last command
9+
# ignored for posix!=windows, because "concorepid" is handled by script
10+
# ignored for docker (linux!=windows), because handled by docker stop
11+
if hasattr(sys, 'getwindowsversion'):
12+
with open("concorekill.bat","w") as fpid:
13+
fpid.write("taskkill /F /PID "+str(os.getpid())+"\n")
14+
15+
try:
16+
iport = literal_eval(open("concore.iport").read())
17+
except:
18+
iport = dict()
19+
try:
20+
oport = literal_eval(open("concore.oport").read())
21+
except:
22+
oport = dict()
23+
24+
25+
s = ''
26+
olds = ''
27+
delay = 1
28+
retrycount = 0
29+
inpath = "./in" #must be rel path for local
30+
outpath = "./out"
31+
32+
#9/21/22
33+
try:
34+
sparams = open(inpath+"1/concore.params").read()
35+
if sparams[0] == '"': #windows keeps "" need to remove
36+
sparams = sparams[1:]
37+
sparams = sparams[0:sparams.find('"')]
38+
if sparams != '{':
39+
print("converting sparams: "+sparams)
40+
sparams = "{'"+re.sub(';',",'",re.sub('=',"':",re.sub(' ','',sparams)))+"}"
41+
print("converted sparams: " + sparams)
42+
try:
43+
params = literal_eval(sparams)
44+
except:
45+
print("bad params: "+sparams)
46+
except:
47+
params = dict()
48+
#9/30/22
49+
def tryparam(n,i):
50+
try:
51+
return params[n]
52+
except:
53+
return i
54+
55+
56+
#9/12/21
57+
def default_maxtime(default):
58+
global maxtime
59+
try:
60+
maxtime = literal_eval(open(inpath+"1/concore.maxtime").read())
61+
except:
62+
maxtime = default
63+
default_maxtime(100)
64+
65+
def unchanged():
66+
global olds,s
67+
if olds==s:
68+
s = ''
69+
return True
70+
else:
71+
olds = s
72+
return False
73+
74+
def read(port, name, initstr):
75+
global s,simtime,retrycount
76+
time.sleep(delay)
77+
try:
78+
infile = open(inpath+str(port)+"/"+name);
79+
ins = infile.read()
80+
except:
81+
ins = initstr
82+
while len(ins)==0:
83+
time.sleep(delay)
84+
ins = infile.read()
85+
retrycount += 1
86+
s += ins
87+
inval = literal_eval(ins)
88+
simtime = max(simtime,inval[0])
89+
return inval[1:]
90+
91+
def write(port, name, val, delta=0):
92+
global outpath,simtime
93+
if isinstance(val,str):
94+
time.sleep(2*delay)
95+
elif isinstance(val,list)==False:
96+
print("mywrite must have list or str")
97+
quit()
98+
try:
99+
with open(outpath+str(port)+"/"+name,"w") as outfile:
100+
if isinstance(val,list):
101+
outfile.write(str([simtime+delta]+val))
102+
simtime += delta
103+
else:
104+
outfile.write(val)
105+
except:
106+
print("skipping"+outpath+str(port)+"/"+name);
107+
108+
def initval(simtime_val):
109+
global simtime
110+
val = literal_eval(simtime_val)
111+
simtime = val[0]
112+
return val[1:]
113+

testsou/funbody.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import concore
2+
import concore2
3+
print("funbody")
4+
5+
concore.delay = 0.07
6+
concore2.delay = 0.07
7+
concore2.inpath = concore.inpath
8+
concore2.outpath = concore.outpath
9+
concore2.simtime = 0
10+
concore.default_maxtime(100)
11+
init_simtime_u = "[0.0, 0.0, 0.0]"
12+
init_simtime_ym = "[0.0, 0.0, 0.0]"
13+
14+
u = concore.initval(init_simtime_u)
15+
ym = concore.initval(init_simtime_ym)
16+
while(concore.simtime<concore.maxtime):
17+
while concore.unchanged():
18+
u = concore.read(concore.iport['U1'],"u",init_simtime_u)
19+
concore2.write(concore.oport['U2'],"u",u)
20+
old2 = concore2.simtime
21+
while concore2.simtime <= old2:
22+
ym = concore2.read(concore.iport['Y2'],"ym",init_simtime_ym)
23+
concore.write(concore.oport['Y1'],"ym",ym)
24+
print("funbody u="+str(u)+" ym="+str(ym)+" time="+str(concore2.simtime))
25+
print("retry="+str(concore.retrycount))

testsou/funbu.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import concore
2+
print("funbu")
3+
4+
concore.delay = 0.07
5+
concore.default_maxtime(100)
6+
init_simtime_u = "[0.0, 0.0, 0.003]"
7+
init_simtime_ym = "[0.0, 0.0, 0.004]"
8+
9+
u = concore.initval(init_simtime_u)
10+
while(concore.simtime<concore.maxtime):
11+
while concore.unchanged():
12+
u = concore.read(concore.iport['U1'],"u",init_simtime_u)
13+
concore.write(concore.oport['U2'],"u",u)
14+
print("funbu u="+str(u))
15+
print("retry="+str(concore.retrycount))

testsou/funby.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import concore
2+
print("funby")
3+
4+
concore.delay = 0.07
5+
concore.default_maxtime(100)
6+
init_simtime_ym = "[0.0, 0.0, 0.004]"
7+
8+
ym = concore.initval(init_simtime_ym)
9+
while(concore.simtime<concore.maxtime):
10+
while concore.unchanged():
11+
ym = concore.read(concore.iport['Y2'],"ym",init_simtime_ym)
12+
concore.write(concore.oport['Y1'],"ym",ym)
13+
print("funby ym="+str(ym))
14+
print("retry="+str(concore.retrycount))

testsou/funcall.dir/concore2.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import time
2+
import os
3+
from ast import literal_eval
4+
import sys
5+
import re
6+
7+
#if windows, create script to kill this process
8+
# because batch files don't provide easy way to know pid of last command
9+
# ignored for posix!=windows, because "concorepid" is handled by script
10+
# ignored for docker (linux!=windows), because handled by docker stop
11+
if hasattr(sys, 'getwindowsversion'):
12+
with open("concorekill.bat","w") as fpid:
13+
fpid.write("taskkill /F /PID "+str(os.getpid())+"\n")
14+
15+
try:
16+
iport = literal_eval(open("concore.iport").read())
17+
except:
18+
iport = dict()
19+
try:
20+
oport = literal_eval(open("concore.oport").read())
21+
except:
22+
oport = dict()
23+
24+
25+
s = ''
26+
olds = ''
27+
delay = 1
28+
retrycount = 0
29+
inpath = "./in" #must be rel path for local
30+
outpath = "./out"
31+
32+
#9/21/22
33+
try:
34+
sparams = open(inpath+"1/concore.params").read()
35+
if sparams[0] == '"': #windows keeps "" need to remove
36+
sparams = sparams[1:]
37+
sparams = sparams[0:sparams.find('"')]
38+
if sparams != '{':
39+
print("converting sparams: "+sparams)
40+
sparams = "{'"+re.sub(';',",'",re.sub('=',"':",re.sub(' ','',sparams)))+"}"
41+
print("converted sparams: " + sparams)
42+
try:
43+
params = literal_eval(sparams)
44+
except:
45+
print("bad params: "+sparams)
46+
except:
47+
params = dict()
48+
#9/30/22
49+
def tryparam(n,i):
50+
try:
51+
return params[n]
52+
except:
53+
return i
54+
55+
56+
#9/12/21
57+
def default_maxtime(default):
58+
global maxtime
59+
try:
60+
maxtime = literal_eval(open(inpath+"1/concore.maxtime").read())
61+
except:
62+
maxtime = default
63+
default_maxtime(100)
64+
65+
def unchanged():
66+
global olds,s
67+
if olds==s:
68+
s = ''
69+
return True
70+
else:
71+
olds = s
72+
return False
73+
74+
def read(port, name, initstr):
75+
global s,simtime,retrycount
76+
time.sleep(delay)
77+
try:
78+
infile = open(inpath+str(port)+"/"+name);
79+
ins = infile.read()
80+
except:
81+
ins = initstr
82+
while len(ins)==0:
83+
time.sleep(delay)
84+
ins = infile.read()
85+
retrycount += 1
86+
s += ins
87+
inval = literal_eval(ins)
88+
simtime = max(simtime,inval[0])
89+
return inval[1:]
90+
91+
def write(port, name, val, delta=0):
92+
global outpath,simtime
93+
if isinstance(val,str):
94+
time.sleep(2*delay)
95+
elif isinstance(val,list)==False:
96+
print("mywrite must have list or str")
97+
quit()
98+
try:
99+
with open(outpath+str(port)+"/"+name,"w") as outfile:
100+
if isinstance(val,list):
101+
outfile.write(str([simtime+delta]+val))
102+
simtime += delta
103+
else:
104+
outfile.write(val)
105+
except:
106+
print("skipping"+outpath+str(port)+"/"+name);
107+
108+
def initval(simtime_val):
109+
global simtime
110+
val = literal_eval(simtime_val)
111+
simtime = val[0]
112+
return val[1:]
113+

testsou/funcall.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import concore
2+
import concore2
3+
print("funcall")
4+
5+
concore.delay = 0.07
6+
concore2.delay = 0.07
7+
concore2.inpath = concore.inpath
8+
concore2.outpath = concore.outpath
9+
concore2.simtime = 0
10+
concore.default_maxtime(100)
11+
init_simtime_u = "[0.0, 0.0, 0.0]"
12+
init_simtime_ym = "[0.0, 0.0, 0.0]"
13+
14+
ym = concore.initval(init_simtime_ym)
15+
while(concore.simtime<concore.maxtime):
16+
while concore.unchanged():
17+
u = concore.read(concore.iport['U'],"u",init_simtime_u)
18+
concore2.write(concore.oport['U1'],"u",u)
19+
old2 = concore2.simtime
20+
while concore2.simtime<=old2:
21+
ym = concore2.read(concore.iport['Y1'],"ym",init_simtime_ym)
22+
concore.write(concore.oport['Y'],"ym",ym)
23+
print("funcall u="+str(u)+" ym="+str(ym)+" time="+str(concore2.simtime))
24+
print("retry="+str(concore.retrycount))

0 commit comments

Comments
 (0)