Skip to content

Commit 8ac7fb0

Browse files
authored
Merge pull request #28 from ControlCore-Project/main
merge back to dev
2 parents bf8a556 + 01a426e commit 8ac7fb0

119 files changed

Lines changed: 30350 additions & 17 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.

.github/workflows/draft-pdf.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on: [push]
2+
3+
jobs:
4+
paper:
5+
runs-on: ubuntu-latest
6+
name: Paper Draft
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v2
10+
- name: Build draft PDF
11+
uses: openjournals/openjournals-draft-action@master
12+
with:
13+
journal: joss
14+
# This should be the path to the paper within your repo.
15+
paper-path: paper.md
16+
- name: Upload
17+
uses: actions/upload-artifact@v1
18+
with:
19+
name: paper
20+
# This is the output path where Pandoc will write the compiled
21+
# PDF. Note, this should be the same directory as the input
22+
# paper.md
23+
path: paper.pdf

0mq/cpymax.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import concore
2+
import time
3+
concore.delay = 0.01
4+
#Nsim = 100
5+
init_simtime_u = "[0.0, 0.0, 0.0]"
6+
init_simtime_ym = "[0.0, 0.0, 0.0]"
7+
minElasped = 10000000
8+
maxElasped = 0
9+
sumElasped = 0
10+
u = concore.initval(init_simtime_u)
11+
wallclock1 = time.perf_counter()
12+
while(concore.simtime<concore.maxtime):
13+
while concore.unchanged():
14+
ym = concore.read(1,"ym",init_simtime_ym)
15+
u[0] = ym[0]+1
16+
print("ym="+str(ym[0])+" u="+str(u[0]));
17+
concore.write(1,"u",u);
18+
wallclock2 = time.perf_counter()
19+
elasped = wallclock2-wallclock1
20+
sumElasped += elasped
21+
wallclock1 = wallclock2
22+
minElasped = min(minElasped, elasped)
23+
maxElasped = max(maxElasped, elasped)
24+
25+
#concore.write(1,"u",init_simtime_u)
26+
print("retry="+str(concore.retrycount))
27+
print("min="+str(minElasped))
28+
print("avg="+str(sumElasped/concore.maxtime))
29+
print("max="+str(maxElasped))

0mq/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+

0mq/funbody.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import concore
2+
import concore2
3+
import time
4+
from osparc_control import CommandManifest
5+
from osparc_control import CommandParameter
6+
from osparc_control import CommandType
7+
from osparc_control import PairedTransmitter
8+
# declare some commands to which a reply can be provided
9+
CONCORE_MANIFEST = CommandManifest(
10+
action="fun",
11+
description="function call",
12+
params=[
13+
CommandParameter(name="u", description="control move"),
14+
],
15+
command_type=CommandType.WITH_IMMEDIATE_REPLY,
16+
)
17+
18+
19+
print("funbody 0mq")
20+
# initialization of 0mq/osparc-control "paired_transmitter"
21+
paired_transmitter = PairedTransmitter(
22+
remote_host="localhost",
23+
exposed_commands=[CONCORE_MANIFEST],
24+
remote_port=2346,
25+
listen_port=2345,)
26+
27+
paired_transmitter.start_background_sync()
28+
29+
concore.delay = 0.07
30+
concore2.delay = 0.07
31+
concore2.inpath = concore.inpath
32+
concore2.outpath = concore.outpath
33+
concore2.simtime = 0
34+
concore.default_maxtime(100)
35+
init_simtime_u = "[0.0, 0.0, 0.0]"
36+
init_simtime_ym = "[0.0, 0.0, 0.0]"
37+
38+
u = concore.initval(init_simtime_u)
39+
ym = concore2.initval(init_simtime_ym)
40+
while(concore2.simtime<concore.maxtime):
41+
#while concore.unchanged():
42+
# u = concore.read(concore.iport['U1'],"u",init_simtime_u)
43+
command_list = paired_transmitter.get_incoming_requests()
44+
while len(command_list)==0:
45+
time.sleep(.01)
46+
command_list = paired_transmitter.get_incoming_requests()
47+
if len(command_list)>1:
48+
print("too many commands at once!")
49+
command = command_list[0]
50+
if command.action == CONCORE_MANIFEST.action:
51+
u = command.params["u"]
52+
concore.simtime = u[0]
53+
u = u[1:]
54+
concore.write(concore.oport['U2'],"u",u)
55+
print(u)
56+
old2 = concore2.simtime
57+
while concore2.unchanged() or concore2.simtime <= old2:
58+
ym = concore2.read(concore.iport['Y2'],"ym",init_simtime_ym)
59+
ym = [concore2.simtime]+ym
60+
print(f"Replying to {command.action} with {ym}")
61+
paired_transmitter.reply_to_command(
62+
request_id=command.request_id, payload=ym)
63+
else:
64+
print("undefined action"+str(command.action))
65+
quit()
66+
#concore2.write(concore.oport['Y1'],"ym",ym)
67+
print("funbody u="+str(u)+" ym="+str(ym)+" time="+str(concore2.simtime))
68+
paired_transmitter.stop_background_sync()
69+
print("retry="+str(concore.retrycount))

0mq/funbody2.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+

0 commit comments

Comments
 (0)