Hello,
here is my class:
Probably some timing/ memory problem and I need skip stop Iteration part and maybe I need to write a function for that but I do not know how to do
Any helps...
Bests
here is my class:
class inportProp:
def __init__(self, t0, tM, incoming, phys, clinkdt, otherport=None, name=''):
self.DEBUG=True
self.lastt=t0
self.tM=tM
if self.tM == 0:
def updateqmem(t):
pass
else :
def updateqmem(t):
perase=-expm1(-(t-self.lastt)/self.tM)
for i,q in enumerate(self.physqueue):
if random()<perase:
q.lost()
del self.physqueue[i]
self.updateqmem=updateqmem
self.incoming=incoming
self.phys=phys
self.physqueue=[]
self.dataqueue=[]
self.clinkdt=clinkdt
self.otherport=otherport
if otherport != None:
if otherport.otherport==None :
otherport.otherport=self
otherport.clinkdt=clinkdt
else: raise ValueError(f"{otherport} already ok")
self.nextitemin()
self.otherport.nextitemin()
self.name=name
def __next__(self):
while True:
if len(self.dataqueue)==0:
self.otherport.nextitemin()
while self.lastt < self.dataqueue[0][0]:
self.nextitemin()
td, cdata = self.dataqueue.pop(0)
self.updateqmem(td)
self.lastt=td
while len(self.physqueue)>0 and self.physqueue[0][1].idt<cdata:
self.physqueue.pop(0)
if len(self.physqueue)>0 and self.physqueue[0][1].idt==cdata:
tq, qb = self.physqueue.pop(0)
return [td, qb]
def nextitemin(self):
tq, q = next(self.incoming)
self.updateqmem(tq)
if self.phys==0 or len(self.physqueue)<=self.phys:
self.physqueue.append([tq, q])
self.lastt=tq
self.otherport.dataqueue.append([tq+self.clinkdt, q.idt])
if self.DEBUG :
print(f'{self.name}.nextitemin')
self.showstate()
def showstate(self):
print(f'{self.name}, t={self.lastt}')
print(f'Physqueue:{self.physqueue}')
print(f'Dataqueue:{self.dataqueue}')here the code that I used for testing:src=source(rate=.5,eta=1)
print("PAIRS************************",src)
Abits=link(eta=.8, deltat=1.5, inputs=src.portA)
Bbits=link(eta=0.7, deltat=3.2, inputs=src.portB)
for x in Abits:
print(f"{x} —> {x[1].idt}, {x[1].QEO.state}")
print('=')
print(f'fifos: A {len(src.Afifo)}, B {len(src.Bfifo)}')
print(10*"=")
for x in Bbits:
print(f"{x} —> {x[1].idt}, {x[1].QEO.state}")
print(f'fifos: A {len(src.Afifo)}, B {len(src.Bfifo)}')
inport1=inportProp(t0=0, tM=0, incoming=Abits, phys=10, clinkdt=4.7, name='A')
inport2=inportProp(t0=0, tM=0, incoming=Bbits, phys=10, clinkdt=4.7, otherport=inport1, name='B')And I am getting this error:Error:...
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-128-6a60e37ecdbf> in <module>
14
15 inport1=inportProp(t0=0, tM=200.0, inbits=Abits, phys=10, clinkdt=4.7,name='A')
---> 16 inport2=inportProp(t0=0, tM=200.0, inbits=Bbits, phys=10, clinkdt=4.7, otherport=Ainport, name='B')#otherport=Ainport,
17
18
<ipython-input-127-5d7a8dbcb4e0> in __init__(self, t0, tM, inbits, phys, clinkdt, otherport, name)
42 otherport.clinkdt=clinkdt
43 else: raise ValueError(f"{otherport} already connected to someone else")
---> 44 self.nextitemin()
45 self.otherport.nextitemin()
46
<ipython-input-127-5d7a8dbcb4e0> in nextitemin(self)
64
65 def nextitemin(self):
---> 66 tq, q = next(self.inbits)
67 self.updateqmem(tq)
68 if self.phys==0 or len(self.physqueue)<=self.physqueuesize:
StopIteration: However if I do not write this part:for x in Abits:
print(f"{x} —> {x[1].idt}, {x[1].QEO.state}")
print('=')
print(f'fifos: A {len(src.Afifo)}, B {len(src.Bfifo)}')
print(10*"=")
for x in Bbits:
print(f"{x} —> {x[1].idt}, {x[1].QEO.state}")
print(f'fifos: A {len(src.Afifo)}, B {len(src.Bfifo)}')code is working..Probably some timing/ memory problem and I need skip stop Iteration part and maybe I need to write a function for that but I do not know how to do
Any helps...
Bests
