Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions demo/controller_RT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import numpy as np
from ast import literal_eval
import concore

try:
ysp = literal_eval(open("ysp.txt").read())
except:
ysp = 3.0

def controller(ym):
if ym[0] < ysp:
return 1.01 * ym
else:
return 0.9 * ym

#//main//
concore.default_maxtime(150) ##maps to-- for i in range(0,150):
concore.delay = 0.02

#//initial values-- transforms to string including the simtime as the 0th entry in the list//
# u = np.array([[0.0]])
# ym = np.array([[0.0]])
init_simtime_u = "[0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0]"

u = np.array([concore.initval(init_simtime_u)]).T
while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
ym = np.array([ym]).T
#####
u = controller(ym)
#####
print(str(concore.simtime) + ". u="+str(u) + "ym="+str(ym));
concore.write(1,"u",list(u.T[0]),delta=0)

print("retry="+str(concore.retrycount))
73 changes: 73 additions & 0 deletions demo/plotym_RT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import concore
import logging
import numpy as np
import matplotlib.pyplot as plt
import time
logging.info("plot ym")

concore.delay = 0.02
concore.default_maxtime(150)
init_simtime_u = "[0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0]"
ymt = []
ym = concore.initval(init_simtime_ym)

# 1. Fetch 'realtime' parameter passed from terminal (defaults to False)
realtime = concore.tryparam('realtime', False)

# DEBUG: Check if the parameter was successfully caught
logging.info(f"--- Realtime mode is set to: {realtime} ---")

# 2. Set up interactive plot before the loop if realtime is True
if realtime:
plt.ion() # Turn on interactive mode
fig, ax1 = plt.subplots(1, 1)
line1, = ax1.plot([], [])

ax1.set_ylabel('ym')
ax1.legend(['ym'], loc=0)
ax1.set_xlabel('Cycles')
plt.show(block=False) # Ensure it does not block the script

while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
concore.write(1,"ym",ym)
logging.debug(f" ym={ym}")
ymt.append(np.array(ym).T)

# 3. Update the plot iteratively during the simulation
if realtime:
ym1 = [x[0].item() for x in ymt]
x_data = range(len(ym1))

line1.set_data(x_data, ym1)

ax1.relim()
ax1.autoscale_view()

# Force the GUI to draw the new data and flush UI events
fig.canvas.draw()
fig.canvas.flush_events()

logging.info(f"retry={concore.retrycount}")

#################

# 4. Finalize plotting
if realtime:
plt.ioff() # Turn off interactive mode so the plot stays open at the end
plt.savefig("ym.pdf")
plt.show()
else:
ym1 = [x[0].item() for x in ymt]

Nsim = len(ym1)
plt.figure()
plt.subplot(111)
plt.plot(range(Nsim), ym1)
plt.ylabel('ym')
plt.legend(['ym'], loc=0)
plt.xlabel('Cycles')
plt.savefig("ym.pdf")
plt.show()
45 changes: 45 additions & 0 deletions demo/pm_RT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import concore
import numpy as np
import tensorflow as tf

#//pm function//
def pm(u,oldstate):
newresult = u + 0.01
newstate = 0.5*oldstate + 0.5*newresult
return newstate,newresult

pmstate = tf.convert_to_tensor(np.array([[4.0]]))
u = tf.convert_to_tensor(np.array([[0.0]]))

#//main//

concore.default_maxtime(150) ##maps to-- for i in range(0,150):
concore.delay = 0.02

#//initial values-- transforms to string including the simtime as the 0th entry in the list//
# u = np.array([[0.0]])
# ym = np.array([[0.0]])
init_simtime_u = "[0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0]"

ym = np.array([concore.initval(init_simtime_ym)]).T
while(concore.simtime<concore.maxtime):
while concore.unchanged():
u = concore.read(1,"u",init_simtime_u)

### Added lines
u = tf.convert_to_tensor(np.array(u))
pmstate,ym = pm(pmstate,u)
ym = np.array(np.array(ym))
####

print(str(concore.simtime) + ". u="+str(u) + "ym="+str(ym));
concore.write(1,"ym",list(ym.T[0]),delta=1)

print("retry="+str(concore.retrycount))


#// main-- to begin with//
#for i in range(0,150):
# ym = pm(u)
# print('u='+repr(u)+' ym='+repr(ym))
208 changes: 208 additions & 0 deletions demo/sample_RT.graphml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd" xmlns:y="http://www.yworks.com/xml/graphml">
<key for="node" id="d6" yfiles.type="nodegraphics"/>
<key for="edge" id="d10" yfiles.type="edgegraphics"/>
<graph edgedefault="directed" id="1771794630414" projectName="sample_RT" authorName="GREENRAT-K405">
<node id="97c694ee-3503-4ed7-9fae-18d7b80709ff">
<data key="d6">
<y:ShapeNode>
<y:Geometry height="60" width="118" x="110" y="110"/>
<y:Fill color="#ffcc00" opacity="1"/>
<y:BorderStyle color="#000" width="1"/>
<y:NodeLabel>pm:pm_RT.py</y:NodeLabel>
<y:Shape type="rectangle"/>
</y:ShapeNode>
</data>
</node>
<node id="1be002db-0fc2-4c3b-8ca1-54e4bbb3fbcb">
<data key="d6">
<y:ShapeNode>
<y:Geometry height="60" width="206" x="670" y="90"/>
<y:Fill color="#ffcc00" opacity="1"/>
<y:BorderStyle color="#000" width="1"/>
<y:NodeLabel>controller:controller_RT.py</y:NodeLabel>
<y:Shape type="rectangle"/>
</y:ShapeNode>
</data>
</node>
<node id="27c5d524-bdc9-48cd-9aa6-4cb1894cb5d7">
<data key="d6">
<y:ShapeNode>
<y:Geometry height="60" width="196" x="370" y="430"/>
<y:Fill color="#ffcc00" opacity="1"/>
<y:BorderStyle color="#000" width="1"/>
<y:NodeLabel>plotym:plotym_RT.py</y:NodeLabel>
<y:Shape type="rectangle"/>
</y:ShapeNode>
</data>
</node>
<edge id="0" source="1be002db-0fc2-4c3b-8ca1-54e4bbb3fbcb" target="97c694ee-3503-4ed7-9fae-18d7b80709ff">
<data key="d10">
<y:GenericEdge configuration="com.yworks.bpmn.Connection">
<y:LineStyle color="#555" width="2" type="solid"/>
<y:Arrows source="none" target="delta"/>
<y:EdgeLabel>edge1</y:EdgeLabel>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
<y:Point x="337.5" y="99.87270471228895"/>
</y:Path>
</y:GenericEdge>
</data>
</edge>
<edge id="1" source="97c694ee-3503-4ed7-9fae-18d7b80709ff" target="27c5d524-bdc9-48cd-9aa6-4cb1894cb5d7">
<data key="d10">
<y:GenericEdge configuration="com.yworks.bpmn.Connection">
<y:LineStyle color="#555" width="2" type="solid"/>
<y:Arrows source="none" target="delta"/>
<y:EdgeLabel>edge2</y:EdgeLabel>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
<y:Point x="252.0133866516665" y="285"/>
</y:Path>
</y:GenericEdge>
</data>
</edge>
<edge id="2" source="27c5d524-bdc9-48cd-9aa6-4cb1894cb5d7" target="1be002db-0fc2-4c3b-8ca1-54e4bbb3fbcb">
<data key="d10">
<y:GenericEdge configuration="com.yworks.bpmn.Connection">
<y:LineStyle color="#555" width="2" type="solid"/>
<y:Arrows source="none" target="delta"/>
<y:EdgeLabel>edge3</y:EdgeLabel>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
<y:Point x="532.9595561001786" y="244.99999999999997"/>
</y:Path>
</y:GenericEdge>
</data>
</edge>
<actionHistory>
<tid>1771794664219</tid>
<inverse>
<actionName>DEL_NODE</actionName>
<parameters>WyI5N2M2OTRlZS0zNTAzLTRlZDctOWZhZS0xOGQ3YjgwNzA5ZmYiXQ==</parameters>
</inverse>
<equivalent>
<actionName>ADD_NODE</actionName>
<parameters>WyJwbTpwbV9SVC5weSIseyJ3aWR0aCI6MTE4LCJoZWlnaHQiOjYwLCJzaGFwZSI6InJlY3RhbmdsZSIsIm9wYWNpdHkiOjEsImJhY2tncm91bmRDb2xvciI6IiNmZmNjMDAiLCJib3JkZXJDb2xvciI6IiMwMDAiLCJib3JkZXJXaWR0aCI6MX0sIm9yZGluIix7IngiOjExMCwieSI6MTEwfSx7fSwiOTdjNjk0ZWUtMzUwMy00ZWQ3LTlmYWUtMThkN2I4MDcwOWZmIl0=</parameters>
</equivalent>
<hash>a95ae0297e5f0e63bfa65a29c8d14d92</hash>
</actionHistory>
<actionHistory>
<tid>1771794687823</tid>
<inverse>
<actionName>DEL_NODE</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiXQ==</parameters>
</inverse>
<equivalent>
<actionName>ADD_NODE</actionName>
<parameters>WyJjb250cm9sbGVyOmNvbnRyb2xsZXJfUlQucHkiLHsid2lkdGgiOjIwNiwiaGVpZ2h0Ijo2MCwic2hhcGUiOiJyZWN0YW5nbGUiLCJvcGFjaXR5IjoxLCJiYWNrZ3JvdW5kQ29sb3IiOiIjZmZjYzAwIiwiYm9yZGVyQ29sb3IiOiIjMDAwIiwiYm9yZGVyV2lkdGgiOjF9LCJvcmRpbiIseyJ4Ijo2NzAsInkiOjkwfSx7fSwiMWJlMDAyZGItMGZjMi00YzNiLThjYTEtNTRlNGJiYjNmYmNiIl0=</parameters>
</equivalent>
<hash>81165b0ec333e71a4ee794f887493323</hash>
</actionHistory>
<actionHistory>
<tid>1771794690698</tid>
<inverse>
<actionName>SET_POS</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLHsieCI6MTEwLCJ5IjoxMTB9LHsieCI6NDkwLCJ5IjoxMTB9XQ==</parameters>
</inverse>
<equivalent>
<actionName>SET_POS</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLHsieCI6NDkwLCJ5IjoxMTB9LHsieCI6MTEwLCJ5IjoxMTB9XQ==</parameters>
</equivalent>
<hash>2137de444092ba020db5d395a39a3b79</hash>
</actionHistory>
<actionHistory>
<tid>1771794720693</tid>
<inverse>
<actionName>DEL_NODE</actionName>
<parameters>WyIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciXQ==</parameters>
</inverse>
<equivalent>
<actionName>ADD_NODE</actionName>
<parameters>WyJwbG90eW06cGxvdHltX1JULnB5Iix7IndpZHRoIjoxOTYsImhlaWdodCI6NjAsInNoYXBlIjoicmVjdGFuZ2xlIiwib3BhY2l0eSI6MSwiYmFja2dyb3VuZENvbG9yIjoiI2ZmY2MwMCIsImJvcmRlckNvbG9yIjoiIzAwMCIsImJvcmRlcldpZHRoIjoxfSwib3JkaW4iLHsieCI6MzcwLCJ5Ijo0MzB9LHt9LCIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciXQ==</parameters>
</equivalent>
<hash>64c4ee3fac24cbd01e9cf06ea57dd8c2</hash>
</actionHistory>
<actionHistory>
<tid>1771794723359</tid>
<inverse>
<actionName>SET_POS</actionName>
<parameters>WyIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciLHsieCI6MTEwLCJ5IjoxMTB9LHsieCI6MzcwLCJ5IjozNTB9XQ==</parameters>
</inverse>
<equivalent>
<actionName>SET_POS</actionName>
<parameters>WyIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciLHsieCI6MzcwLCJ5IjozNTB9LHsieCI6MTEwLCJ5IjoxMTB9XQ==</parameters>
</equivalent>
<hash>b92c36146ebe446c0907df865f83794d</hash>
</actionHistory>
<actionHistory>
<tid>1771794740309</tid>
<inverse>
<actionName>DEL_EDGE</actionName>
<parameters>WyJkNGRkZDA2Mi00NTUyLTRkNTktOWIzYy0wYzA0ZGU2MGQxOTciXQ==</parameters>
</inverse>
<equivalent>
<actionName>ADD_EDGE</actionName>
<parameters>W3sic291cmNlSUQiOiIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLCJ0YXJnZXRJRCI6Ijk3YzY5NGVlLTM1MDMtNGVkNy05ZmFlLTE4ZDdiODA3MDlmZiIsImxhYmVsIjoiZWRnZTEiLCJzdHlsZSI6eyJ0aGlja25lc3MiOjIsImJhY2tncm91bmRDb2xvciI6IiM1NTUiLCJzaGFwZSI6InNvbGlkIn0sImlkIjoiZDRkZGQwNjItNDU1Mi00ZDU5LTliM2MtMGMwNGRlNjBkMTk3In1d</parameters>
</equivalent>
<hash>8b3c683a137808fb40dc2921313f8115</hash>
</actionHistory>
<actionHistory>
<tid>1771794751288</tid>
<inverse>
<actionName>SET_POS</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLHsieCI6NDkwLCJ5IjoxMTB9LHsieCI6NjMwLCJ5Ijo5MH1d</parameters>
</inverse>
<equivalent>
<actionName>SET_POS</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLHsieCI6NjMwLCJ5Ijo5MH0seyJ4Ijo0OTAsInkiOjExMH1d</parameters>
</equivalent>
<hash>0ce00744b96d9ae529645d9297b56821</hash>
</actionHistory>
<actionHistory>
<tid>1771794765726</tid>
<inverse>
<actionName>DEL_EDGE</actionName>
<parameters>WyIwOGU0NTRhNS1mYjAwLTQ2MDEtOWMxNC00NDA4NGIyMzFiNTciXQ==</parameters>
</inverse>
<equivalent>
<actionName>ADD_EDGE</actionName>
<parameters>W3sic291cmNlSUQiOiI5N2M2OTRlZS0zNTAzLTRlZDctOWZhZS0xOGQ3YjgwNzA5ZmYiLCJ0YXJnZXRJRCI6IjI3YzVkNTI0LWJkYzktNDhjZC05YWE2LTRjYjE4OTRjYjVkNyIsImxhYmVsIjoiZWRnZTIiLCJzdHlsZSI6eyJ0aGlja25lc3MiOjIsImJhY2tncm91bmRDb2xvciI6IiM1NTUiLCJzaGFwZSI6InNvbGlkIn0sImlkIjoiMDhlNDU0YTUtZmIwMC00NjAxLTljMTQtNDQwODRiMjMxYjU3In1d</parameters>
</equivalent>
<hash>901af9eaa14d4bf0fc1ba715fc5ac3d2</hash>
</actionHistory>
<actionHistory>
<tid>1771794782565</tid>
<inverse>
<actionName>DEL_EDGE</actionName>
<parameters>WyI3ZmM3YjQxNy01NDBkLTRhMDgtYTc4Ni0wNDkwYjgyMDg4YWUiXQ==</parameters>
</inverse>
<equivalent>
<actionName>ADD_EDGE</actionName>
<parameters>W3sic291cmNlSUQiOiIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciLCJ0YXJnZXRJRCI6IjFiZTAwMmRiLTBmYzItNGMzYi04Y2ExLTU0ZTRiYmIzZmJjYiIsImxhYmVsIjoiZWRnZTMiLCJzdHlsZSI6eyJ0aGlja25lc3MiOjIsImJhY2tncm91bmRDb2xvciI6IiM1NTUiLCJzaGFwZSI6InNvbGlkIn0sImlkIjoiN2ZjN2I0MTctNTQwZC00YTA4LWE3ODYtMDQ5MGI4MjA4OGFlIn1d</parameters>
</equivalent>
<hash>e157ed01dca772c8461787c1053794ce</hash>
</actionHistory>
<actionHistory>
<tid>1771794788695</tid>
<inverse>
<actionName>SET_POS</actionName>
<parameters>WyIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciLHsieCI6MzcwLCJ5IjozNTB9LHsieCI6MzcwLCJ5Ijo0MzB9XQ==</parameters>
</inverse>
<equivalent>
<actionName>SET_POS</actionName>
<parameters>WyIyN2M1ZDUyNC1iZGM5LTQ4Y2QtOWFhNi00Y2IxODk0Y2I1ZDciLHsieCI6MzcwLCJ5Ijo0MzB9LHsieCI6MzcwLCJ5IjozNTB9XQ==</parameters>
</equivalent>
<hash>aebd758397fec30aac0b59fe643a0da2</hash>
</actionHistory>
<actionHistory>
<tid>1771794795323</tid>
<inverse>
<actionName>SET_POS</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLHsieCI6NjMwLCJ5Ijo5MH0seyJ4Ijo2NzAsInkiOjkwfV0=</parameters>
</inverse>
<equivalent>
<actionName>SET_POS</actionName>
<parameters>WyIxYmUwMDJkYi0wZmMyLTRjM2ItOGNhMS01NGU0YmJiM2ZiY2IiLHsieCI6NjcwLCJ5Ijo5MH0seyJ4Ijo2MzAsInkiOjkwfV0=</parameters>
</equivalent>
<hash>20778f5ad2b1c7bd577f09da007bc0e0</hash>
</actionHistory>
</graph>
</graphml>
Loading