Hello,
The idea is that: I am producing my pairs which is made by bits. Bits are the objects which is produced by another class(this part is ok). After that I am sending them into the ports(this part is ok). And then I am sending them into the inports. And here the problem begins.. In the inportPort class, I have memory which is called by physqueue and I have dataqueu. The reason is we have dataqueue is that: Once A port catch the bit in the memory(physqueue), it is sending a classical message to otherport to say "I have the bit". In the inportProp class, once I catch the bits, I am sending them to the memory and once I catch them in the memory this time I am sending them into the dataqueue. SO timing should be that time in the physqueue < lastt <time in the dataqueue. But the results are totally irrelevant. Sometimes times coming correctly, sometimes times coming totally irrelevant.
when I call my function inside my class, I see that time is decreasing instead of increasing.
Here in the results: the first timing is 20.7 for Bport and dataqueu starts with 10.5. It should be impossible because first the bit arrive to me and I update the time and after that I send it to physqueu and after that I send it to dataqueue . And also The second time of B is coming as 10.5 ..
What is the problem here?
and can a function be written for preventing this event like raise an error?
The idea is that: I am producing my pairs which is made by bits. Bits are the objects which is produced by another class(this part is ok). After that I am sending them into the ports(this part is ok). And then I am sending them into the inports. And here the problem begins.. In the inportPort class, I have memory which is called by physqueue and I have dataqueu. The reason is we have dataqueue is that: Once A port catch the bit in the memory(physqueue), it is sending a classical message to otherport to say "I have the bit". In the inportProp class, once I catch the bits, I am sending them to the memory and once I catch them in the memory this time I am sending them into the dataqueue. SO timing should be that time in the physqueue < lastt <time in the dataqueue. But the results are totally irrelevant. Sometimes times coming correctly, sometimes times coming totally irrelevant.
when I call my function inside my class, I see that time is decreasing instead of increasing.
class inportProp: #Take bits, store them in physical queue and coordinates with the other end via classical links. #bit comes at lastt #send it to physqueue and in that time, save the time so update time in physqueue #finally send it to dataqueue from physqueue so update time in dataqueue def __init__(self, t0, tM, incoming, phys, clinkdt, port=None, name=''): self.DEBUG=True self.lastt=t0 #lastt is the time for bits and it starts with t0 self.tM=tM #this is memory life time if self.tM == 0: #this implies infinite memory 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 #incoming bits self.phys=phys #maximum bit number in the physqueue self.physqueue=[] #physcial queue self.dataqueue=[] #just after saving bits in the memory, we send them to dataqueue with delay self.clinkdt=clinkdt #delay between classical message (for dataqueue's) self.port=port if port != None: if port.port==None : port.port=self port.clinkdt=clinkdt else: raise ValueError(f"{port} already ok") self.nextitemin() self.port.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) #td is the time of bit cdata is the bit in the dataqueue 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) #tq is the time of bit qb is the bit in the physqueue 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 my codes to run my class
src=source(rate=.4,eta=1) #I produced the pairs Abits=link(eta=.8, deltat=1.5, inputs=src.portA) # I send them into the ports Bbits=link(eta=0.7, deltat=3.2, inputs=src.portB) # I send them into the ports Aport=inportProp(t0=0, tM=50, incoming=Abits, phys=5, clinkdt=4,name='A') Bport=inportProp(t0=0, tM=50, incoming=Bbits, phys=5, clinkdt=4,port=Ainport, name='B') Aout=[x for x in Aport] Bout=[x for x in Bport] print(f'bits out of A {[x[1].dt for x in Aout]}') print(f'bits out of B {[x[1].dt for x in Bout]}') for port in [Ainport, Binport]: port.showstate()My results are here:
Quote:A, t=19.0 Physqueue:[[14.0, <__main__.bit object at 0x7f9888799fd0>], [16.5, <__main__.bit object at 0x7f98887993a0>], [19.0, <__main__.bit object at 0x7f9888880070>]] Dataqueue:[[19.7, (12.5,)], [22.2, (15.0,)]]
bit name=B (12.5,) is lost at t=20.7
B.nextqubitin
B, t=20.7 Physqueue:[[5.7, <__main__.bit object at 0x7f988886c1f0>], [8.2, <__main__.bit object at 0x7f98887a0040>], [10.7, <__main__.bit object at 0x7f9888880eb0>], [18.2, <__main__.bit object at 0x7f98887845e0>], [20.7, <__main__.bit object at 0x7f9888880430>]] Dataqueue:[[10.5, (5.0,)], [13.0, (7.5,)], [15.5, (10.0,)], [18.0, (12.5,)], [20.5, (15.0,)], [23.0, (17.5,)]]
====================
bits out of A [(5.0,), (7.5,)]
bits out of B [(5.0,)]
State of the queus at the end:
A, t=19.0 Physqueue:[[14.0, <__main__.bit object at 0x7f9888799fd0>], [16.5, <__main__.bit object at 0x7f98887993a0>], [19.0, <__main__.bit object at 0x7f9888880070>]] Dataqueue:[[19.7, (12.5,)], [22.2, (15.0,)], [24.7, (17.5,)]]
B, t=10.5 Physqueue:[[10.7, <__main__.bit object at 0x7f9888880eb0>], [18.2, <__main__.bit object at 0x7f98887845e0>], [20.7, <__main__.bit object at 0x7f9888880430>]] Dataqueue:[[13.0, (7.5,)], [15.5, (10.0,)], [18.0, (12.5,)], [20.5, (15.0,)], [23.0, (17.5,)]]
the end******************************************************
Here in the results: the first timing is 20.7 for Bport and dataqueu starts with 10.5. It should be impossible because first the bit arrive to me and I update the time and after that I send it to physqueu and after that I send it to dataqueue . And also The second time of B is coming as 10.5 ..
What is the problem here?
and can a function be written for preventing this event like raise an error?