Skip to content

Commit

Permalink
created nintab
Browse files Browse the repository at this point in the history
  • Loading branch information
markgarnold committed Mar 24, 2023
1 parent 4cfcf40 commit 9631b01
Show file tree
Hide file tree
Showing 12 changed files with 839 additions and 0 deletions.
29 changes: 29 additions & 0 deletions nintan/cpymax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import concore
import time
concore.delay = 0.01
#Nsim = 100
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"
minElasped = 10000000
maxElasped = 0
sumElasped = 0
u = concore.initval(init_simtime_u)
wallclock1 = time.perf_counter()
while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
u[0] = ym[0]+1
print("ym="+str(ym[0])+" u="+str(u[0]));
concore.write(1,"u",u);
wallclock2 = time.perf_counter()
elasped = wallclock2-wallclock1
sumElasped += elasped
wallclock1 = wallclock2
minElasped = min(minElasped, elasped)
maxElasped = max(maxElasped, elasped)

#concore.write(1,"u",init_simtime_u)
print("retry="+str(concore.retrycount))
print("min="+str(minElasped))
print("avg="+str(sumElasped/concore.maxtime))
print("max="+str(maxElasped))
32 changes: 32 additions & 0 deletions nintan/cstim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import concore
from ast import literal_eval
import time
concore.delay = 0.001
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"
minElasped = 10000000
maxElasped = 0
sumElasped = 0
u = concore.initval(init_simtime_u)
wallclock1 = time.perf_counter()
while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
try:
u[0] = float(literal_eval(input()))
except:
print("bad input, using .5 instead")
u[0] = 0.5
print("ym="+str(ym[0])+" u="+str(u[0]));
concore.write(1,"u",u);
wallclock2 = time.perf_counter()
elasped = wallclock2-wallclock1
sumElasped += elasped
wallclock1 = wallclock2
minElasped = min(minElasped, elasped)
maxElasped = max(maxElasped, elasped)

print("retry="+str(concore.retrycount))
print("min="+str(minElasped))
print("avg="+str(sumElasped/concore.maxtime))
print("max="+str(maxElasped))
32 changes: 32 additions & 0 deletions nintan/cstim0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import concore
from ast import literal_eval
import time
concore.delay = 0.001
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"
minElasped = 10000000
maxElasped = 0
sumElasped = 0
u = concore.initval(init_simtime_u)
wallclock1 = time.perf_counter()
while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
try:
u[0] = float(literal_eval(input()))
except:
print("bad input, using .5 instead")
u[0] = 0.5
print("ym="+str(ym[0])+" u="+str(u[0]));
concore.write(1,"u",u);
wallclock2 = time.perf_counter()
elasped = wallclock2-wallclock1
sumElasped += elasped
wallclock1 = wallclock2
minElasped = min(minElasped, elasped)
maxElasped = max(maxElasped, elasped)

print("retry="+str(concore.retrycount))
print("min="+str(minElasped))
print("avg="+str(sumElasped/concore.maxtime))
print("max="+str(maxElasped))
17 changes: 17 additions & 0 deletions nintan/pmpymax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import concore

concore.delay = 0.01
#Nsim = 100
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"

ym = concore.initval(init_simtime_ym)
while(concore.simtime<concore.maxtime):
while concore.unchanged():
u = concore.read(1,"u",init_simtime_u)
ym[0] = u[0]+10000
print("ym="+str(ym[0])+" u="+str(u[0]));
concore.write(1,"ym",ym,delta=1)
input()
#concore.write(1,"ym",init_simtime_ym)
print("retry="+str(concore.retrycount))
106 changes: 106 additions & 0 deletions nintan/powermetermax.dir/concore2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import time
import os
from ast import literal_eval
import sys
import re

#if windows, create script to kill this process
# because batch files don't provide easy way to know pid of last command
# ignored for posix!=windows, because "concorepid" is handled by script
# ignored for docker (linux!=windows), because handled by docker stop
if hasattr(sys, 'getwindowsversion'):
with open("concorekill.bat","w") as fpid:
fpid.write("taskkill /F /PID "+str(os.getpid())+"\n")

try:
iport = literal_eval(open("concore.iport").read())
except:
iport = dict()
try:
oport = literal_eval(open("concore.oport").read())
except:
oport = dict()


s = ''
olds = ''
delay = 1
retrycount = 0
inpath = "./in" #must be rel path for local
outpath = "./out"

#9/21/22
try:
sparams = open(inpath+"1/concore.params").read()
if sparams[0] == '"': #windows keeps "" need to remove
sparams = sparams[1:]
sparams = sparams[0:sparams.find('"')]
if sparams != '{':
print("converting sparams: "+sparams)
sparams = "{'"+re.sub(',',",'",re.sub('=',"':",re.sub(' ','',sparams)))+"}"
print("converted sparams: " + sparams)
try:
params = literal_eval(sparams)
except:
print("bad params: "+sparams)
except:
params = dict()

#9/12/21
def default_maxtime(default):
global maxtime
try:
maxtime = literal_eval(open(inpath+"1/concore.maxtime").read())
except:
maxtime = default
default_maxtime(100)

def unchanged():
global olds,s
if olds==s:
s = ''
return True
else:
olds = s
return False

def read(port, name, initstr):
global s,simtime,retrycount
time.sleep(delay)
try:
infile = open(inpath+str(port)+"/"+name);
ins = infile.read()
except:
ins = initstr
while len(ins)==0:
time.sleep(delay)
ins = infile.read()
retrycount += 1
s += ins
inval = literal_eval(ins)
simtime = max(simtime,inval[0])
return inval[1:]

def write(port, name, val, delta=0):
global outpath,simtime
if isinstance(val,str):
time.sleep(2*delay)
elif isinstance(val,list)==False:
print("mywrite must have list or str")
quit()
try:
with open(outpath+str(port)+"/"+name,"w") as outfile:
if isinstance(val,list):
outfile.write(str([simtime+delta]+val))
simtime += delta
else:
outfile.write(val)
except:
print("skipping"+outpath+str(port)+"/"+name);

def initval(simtime_val):
global simtime
val = literal_eval(simtime_val)
simtime = val[0]
return val[1:]

27 changes: 27 additions & 0 deletions nintan/powermetermax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#CW
import concore
import concore2
import time
print("powermeter")

concore.delay = 0.07
concore2.delay = 0.07
concore2.inpath = concore.inpath
concore2.outpath = concore.outpath
concore2.simtime = 0
#Nsim = 100
concore.default_maxtime(100)
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"
energy = 0

ym = concore.initval(init_simtime_ym)
while(concore.simtime<concore.maxtime):
while concore.unchanged():
u = concore.read(concore.iport['VC'],"u",init_simtime_u)
concore2.write(concore.oport['VXP'],"u",u)
while concore2.unchanged():
ym = concore2.read(concore.iport['VP'],"ym",init_simtime_ym)
concore.write(concore.oport['VXC'],"ym",ym)
print("powermeter u="+str(u)+" ym="+str(ym))
print("retry="+str(concore.retrycount))
39 changes: 39 additions & 0 deletions nintan/pstim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import concore
#from hardware.util_functions import accurate_delay
import time
import threading

global uglobal
uglobal = 0.5
PULSE_WIDTH = 10

def pwm():
while(True):
ulocal = uglobal
if ulocal < 0.0:
ulocal = 0.0
if ulocal > 1.0:
ulocal = 1.0
print("+")
time.sleep(PULSE_WIDTH*ulocal)
print("-")
time.sleep(PULSE_WIDTH*(1.0-ulocal))

pwm_thread = threading.Thread(target=pwm, daemon=True)

concore.delay = 0.001
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"

ym = concore.initval(init_simtime_ym)

pwm_thread.start()
while(concore.simtime<concore.maxtime):
while concore.unchanged():
u = concore.read(1,"u",init_simtime_u)
uglobal = float(u[0])
ym[0] = u[0]*100
print("")
print("ym="+str(ym[0])+" u="+str(u[0]));
concore.write(1,"ym",ym,delta=1)
print("retry="+str(concore.retrycount))
39 changes: 39 additions & 0 deletions nintan/pstim0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import concore
#from hardware.util_functions import accurate_delay
import time
import threading

global uglobal
uglobal = 0.5
PULSE_WIDTH = 10

def pwm():
while(True):
ulocal = uglobal
if ulocal < 0.0:
ulocal = 0.0
if ulocal > 1.0:
ulocal = 1.0
print("+")
time.sleep(PULSE_WIDTH*ulocal)
print("-")
time.sleep(PULSE_WIDTH*(1.0-ulocal))

pwm_thread = threading.Thread(target=pwm, daemon=True)

concore.delay = 0.001
init_simtime_u = "[0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"

ym = concore.initval(init_simtime_ym)

pwm_thread.start()
while(concore.simtime<concore.maxtime):
while concore.unchanged():
u = concore.read(1,"u",init_simtime_u)
uglobal = float(u[0])
ym[0] = u[0]*100
print("")
print("ym="+str(ym[0])+" u="+str(u[0]));
concore.write(1,"ym",ym,delta=1)
print("retry="+str(concore.retrycount))
Loading

0 comments on commit 9631b01

Please sign in to comment.