2

I'm coming from a SystemC world and I am trying to code something simple in Python. I wonder if Python has something similar to peq_with_get() (from SystemC) which is basically a queue that preserves all the triggers made to an event. I developed the following code to test it but it doesn't seem to be working. Wondering if you guys can guide me through to know wheter simpy has event queues or not.

import simpy

SIM_DURATION = 100

class SomeClass(object):

    def __init__(self, env):
        self.env = env
        self.event_trig     = self.env.event()
        self.event_recvd    = self.env.event()

        simpy.events.Process( self.env, self._submit_loop() )
        simpy.events.Process( self.env, self._complete_loop() )

    def _submit_loop(self):
        while True:
            print('Waiting to Receive the Trigger')
            yield self.event_trig
            print('Event Received at Time %d' % env.now )
            self.event_recvd.succeed()


    def _complete_loop(self):
        while True:
            print('Trigger at time %d' % (env.now + 5) )
            self.event_trig = self.env.timeout(5)
            print('Trigger at time %d' % (env.now + 6) ) 
            self.event_trig = self.env.timeout(6)
            print('Trigger at time %d' % (env.now + 7) ) 
            self.event_trig = self.env.timeout(7)
            yield self.event_recvd
            print('Current Time is %d. Wait for 10' % env.now)
            yield self.env.timeout(10)

print('Start Sim')
env = simpy.Environment()
someCls = SomeClass( env )
env.run()
Amir
  • 421
  • 1
  • 4
  • 14
  • Hi Amir, I'm not sure I understood what you mean with "event queues". I have no idea of SystemC. You code pasted above has several problems: (a) you never trigger the original `self.event_trig` event which `_submit_loop()` is waiting for. (b) In `_complete_loop()` you create several `timeout()` events and bind them to `self.event_trig`. This does not change the event that `_submit_loop()` is waiting for. The timeouts just get queued and no one cares anymore. (c) `self.even_recv` will never be triggered since `self.event_trig` is also never being triggered. – Stefan Scherfke Sep 01 '16 at 07:11
  • 1
    Hi Stefan, Thanks for the answer. What you mentioned is exactly what I'm experiencing. What I want to do is to go ahead of simulation time instead of going in lock-steps. I mean to independently generate events at times 5, 6 and 7 and have _submit_loop be triggered at those times. Then resume _complete_loop to generate more triggers. Think of it as an event container that can queue events and once the simulation time reaches the head of the queue it triggers the waiting process. Does that make sense? I noticed there is a Store construct which does something similar. But not straightforward . – Amir Sep 01 '16 at 17:40
  • 1
    BTW, I'm actually wondering why self.evet_trig is not triggered. To my understand self.env.timeout() creates and event. I thought by having self.event_trig to be equal to timeout it will be triggered. Thanks. – Amir Sep 01 '16 at 21:05
  • 1
    "self.event_trig" is just a name or a label that you bind to an object in memory. If you do "self.event_trig = event(); self.event_trig = timeout()", you first create a normal event and label it "event_trig", then you create a new timeout event and bind the "event_trig" to it. You can now no longer acces the former event via that label. http://nedbatchelder.com/text/names.html – Stefan Scherfke Sep 03 '16 at 05:48
  • 1
    Very good explanation. Thanks for that. When I initially define "self.event_trig" as a normal event by "=event()", how can I trigger it using timeout? – Amir Sep 12 '16 at 15:45

1 Answers1

0

What I figured out is that an event can't hold multiple trigger points (I don't explicitly know the answer but everything indicates that). However an equivalent of peq_with_get in SystemC world is simpy.Store() which can be enhanced by defining a process on its "put" method. It's not as straight-forward as peq_with_get but it delivers the same functionality. You can get more info from the code snippet if you follow this link: http://simpy.readthedocs.io/en/latest/examples/latency.html

Just to add a bit of explanation about functionality of peq_with_get, it is a Payload Event Queue which you can notify (trigger) by pushing an object to it which is made available for the consuming thread at a delay which is specified at notification (trigger statement) time.

Amir
  • 421
  • 1
  • 4
  • 14