kgmuller | 5 Sep 17:52
Picon
Picon
Favicon

Re: Get time remaining for a Process?

Hi Dan,
I was  away on holiday and just came back today, so I could not answer before.
 
The function should simply return the value of "proc._nextTime - now()", with proc being the process in a yield hold. proc._nextTime is the next event time of process proc. The value returned only makes sense, though, if that process is in a yield hold. You can test for this by using the predicate function "proc.active()".
 
Klaus Muller

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Dan Homerick
Sent: Wednesday, August 27, 2008 2:41 AM
To: simpy-users <at> lists.sourceforge.net
Subject: [Simpy-users] Get time remaining for a Process?

Hi all,

What's the simplest way to get the time remaining before a Process completes a 'yield self, hold, delay'? I'd like to do it from a function that is not part of the Process instance.

Thanks,
 - Dan
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Douglas Macdonald | 10 Sep 19:05
Picon
Favicon

Molecules as process or resource.

Hi,

I hope that you can give me your recommendation on how to set up a population style simulation.

I want to simulate the production of molecules. They will be produced, change from one type to another, and degrade at  particular rates, depending on how many there are.

Should I have the molecules as processes with decay rates built in and use a generating function?

Or molecules as resources and the generation, decay and change rates as the process?

Your thoughts are gratefully received.

Best,

Douglas
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
kgmuller | 10 Sep 21:57
Picon
Picon
Favicon

Re: Molecules as process or resource.

Douglas,

I would make the molecules processes and have a source/generating process. That is the clearest model for this of agent simulation.

 

Regards,

 

Klaus Müller

 

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Douglas Macdonald
Sent: Mittwoch, 10. September 2008 19:06
To: simpy-users <at> lists.sourceforge.net
Subject: [Simpy-users] Molecules as process or resource.

 

Hi,

I hope that you can give me your recommendation on how to set up a population style simulation.

I want to simulate the production of molecules. They will be produced, change from one type to another, and degrade at  particular rates, depending on how many there are.

Should I have the molecules as processes with decay rates built in and use a generating function?

Or molecules as resources and the generation, decay and change rates as the process?

Your thoughts are gratefully received.

Best,

Douglas

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Dan Homerick | 11 Sep 04:08
Picon

Multiple, Simultaneous Interrupts

I'm not sure if this is a problem with SimPy code or mine, but I'm having trouble getting multiple, simultaneous interrupts to both take effect. Any advice or workarounds?

# --- test code ---
import SimPy.SimulationTrace as Sim

class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)

    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        self.interrupt(other)

Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')

Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))

Sim.simulate(until=50)
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Dan Homerick | 11 Sep 04:14
Picon

Re: Multiple, Simultaneous Interrupts

Also, for convenience, here's the output the test code gives. Note that t1 is only interrupted once, although both t2 and t3 terminate:

0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>
5 <t2> terminated
5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated

 - Dan

On Wed, Sep 10, 2008 at 7:08 PM, Dan Homerick <danhomerick <at> gmail.com> wrote:
I'm not sure if this is a problem with SimPy code or mine, but I'm having trouble getting multiple, simultaneous interrupts to both take effect. Any advice or workarounds?

# --- test code ---
import SimPy.SimulationTrace as Sim

class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)

    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        self.interrupt(other)

Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')

Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))

Sim.simulate(until=50)

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
kgmuller | 15 Sep 10:16
Picon
Picon
Favicon

Re: Multiple, Simultaneous Interrupts

Dan,
in SimPy, processes can only interrupt processes which are active, i.e. in a 'yield hold'. An interrupt of a process in an interrupted sttaus is thus not possible.
 
Here is a modification of your program which shows what is happening:
 
import SimPy.SimulationTrace as Sim
 
class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)
 
    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        if other.active():
            self.interrupt(other)
            print "%s interrupted %s"%(self.name,other.name)
        else:
            print "%s not active. %s can't interrupt."%(other.name,self.name)
 
Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')
 
Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))
 
Sim.simulate(until=50)
It produces:
 
0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>
t2 interrupted t1
5 <t2> terminated
t1 not active. t3 can't interrupt.
5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated
 
 
Klaus Muller

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Dan Homerick
Sent: Thursday, September 11, 2008 4:15 AM
To: simpy-users <at> lists.sourceforge.net
Subject: Re: [Simpy-users] Multiple, Simultaneous Interrupts

Also, for convenience, here's the output the test code gives. Note that t1 is only interrupted once, although both t2 and t3 terminate:

0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>
5 <t2> terminated
5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated

 - Dan

On Wed, Sep 10, 2008 at 7:08 PM, Dan Homerick <danhomerick <at> gmail.com> wrote:
I'm not sure if this is a problem with SimPy code or mine, but I'm having trouble getting multiple, simultaneous interrupts to both take effect. Any advice or workarounds?

# --- test code ---
import SimPy.SimulationTrace as Sim

class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)

    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        self.interrupt(other)

Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')

Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))

Sim.simulate(until=50)

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Dan Homerick | 15 Sep 19:02
Picon

Re: Multiple, Simultaneous Interrupts

Hi Klaus,

I don't see quietly dropping interrupts as being the best possible design. Is it something you're open to improving?

From SimPy.Simulation:

    def interrupt(self,victim):
        """Application function to interrupt active processes"""
        # can't interrupt terminated/passive/interrupted process
        if victim.active():
            victim.interruptCause=self  # self causes interrupt
            left=victim._nextTime-_t
            victim.interruptLeft=left   # time left in current 'hold'
            victim._inInterrupt=True
            reactivate(victim)
            return left
        else: #victim not active -- can't interrupt
            return None

Rather than returning None for all cases where the victim is not active, how about raising a SimPy specific exception indicating the reason the interrupt failed? I suspect that most programmers would consider an interrupt failing to be exception worthy.

Alternatively, rather than failing, would you be open to buffering the second interrupt, and firing it off as soon as the victim process resumes? I think that the only data that would need to be buffered is the interruptCause.

I'd be interested in writing a patch to accomplish one or the other, but don't want to do so unless you're in favor of the change.

Cheers,
 - Dan

On Mon, Sep 15, 2008 at 1:16 AM, kgmuller <kgmuller <at> xs4all.nl> wrote:
Dan,
in SimPy, processes can only interrupt processes which are active, i.e. in a 'yield hold'. An interrupt of a process in an interrupted sttaus is thus not possible.
 
Here is a modification of your program which shows what is happening:
 
import SimPy.SimulationTrace as Sim
 
class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)
 
    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        if other.active():
            self.interrupt(other)
            print "%s interrupted %s"%(self.name,other.name)
        else:
            print "%s not active. %s can't interrupt."%(other.name,self.name)
 
Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')
 
Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))
 
Sim.simulate(until=50)
It produces:
 
0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>
t2 interrupted t1
5 <t2> terminated
t1 not active. t3 can't interrupt.

5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated
 
 
Klaus Muller

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Dan Homerick
Sent: Thursday, September 11, 2008 4:15 AM
To: simpy-users <at> lists.sourceforge.net
Subject: Re: [Simpy-users] Multiple, Simultaneous Interrupts

Also, for convenience, here's the output the test code gives. Note that t1 is only interrupted once, although both t2 and t3 terminate:

0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>
5 <t2> terminated
5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated

 - Dan

On Wed, Sep 10, 2008 at 7:08 PM, Dan Homerick <danhomerick <at> gmail.com> wrote:
I'm not sure if this is a problem with SimPy code or mine, but I'm having trouble getting multiple, simultaneous interrupts to both take effect. Any advice or workarounds?

# --- test code ---
import SimPy.SimulationTrace as Sim

class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)

    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        self.interrupt(other)

Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')

Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))

Sim.simulate(until=50)


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
kgmuller | 17 Sep 10:22
Picon
Picon
Favicon

Re: Multiple, Simultaneous Interrupts

xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

Dan,

Thank you for your questions/proposals. I would be happy if you could improve on SimPy’s interrupt handling.

 

Using a specific exception is not my preferred solution. Nowhere else does the SimPy API use exceptions to signal a non-error condition.

 

I am looking forward to your proposed code change!

 

Klaus Müller

 

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Dan Homerick
Sent: Montag, 15. September 2008 19:02
Cc: simpy-users <at> lists.sourceforge.net
Subject: Re: [Simpy-users] Multiple, Simultaneous Interrupts

 

Hi Klaus,

I don't see quietly dropping interrupts as being the best possible design. Is it something you're open to improving?

>From SimPy.Simulation:

    def interrupt(self,victim):
        """Application function to interrupt active processes"""
        # can't interrupt terminated/passive/interrupted process
        if victim.active():
            victim.interruptCause=self  # self causes interrupt
            left=victim._nextTime-_t
            victim.interruptLeft=left   # time left in current 'hold'
            victim._inInterrupt=True
            reactivate(victim)
            return left
        else: #victim not active -- can't interrupt
            return None

Rather than returning None for all cases where the victim is not active, how about raising a SimPy specific exception indicating the reason the interrupt failed? I suspect that most programmers would consider an interrupt failing to be exception worthy.

Alternatively, rather than failing, would you be open to buffering the second interrupt, and firing it off as soon as the victim process resumes? I think that the only data that would need to be buffered is the interruptCause.

I'd be interested in writing a patch to accomplish one or the other, but don't want to do so unless you're in favor of the change.

Cheers,
 - Dan

On Mon, Sep 15, 2008 at 1:16 AM, kgmuller <kgmuller <at> xs4all.nl> wrote:

Dan,

in SimPy, processes can only interrupt processes which are active, i.e. in a 'yield hold'. An interrupt of a process in an interrupted sttaus is thus not possible.

 

Here is a modification of your program which shows what is happening:

 

import SimPy.SimulationTrace as Sim

 

class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)

 

    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5

        if other.active():
            self.interrupt(other)
            print "%s interrupted %s"%(self.name,other.name)
        else:
            print "%s not active. %s can't interrupt."%(other.name,self.name)

 

Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')

 

Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))

 

Sim.simulate(until=50)

It produces:

 

0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>

t2 interrupted t1
5 <t2> terminated
t1 not active. t3 can't interrupt.


5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated

 

 

Klaus Muller

 

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Dan Homerick
Sent: Thursday, September 11, 2008 4:15 AM
To: simpy-users <at> lists.sourceforge.net
Subject: Re: [Simpy-users] Multiple, Simultaneous Interrupts

Also, for convenience, here's the output the test code gives. Note that t1 is only interrupted once, although both t2 and t3 terminate:

0 activate <t1> at time: 0 prior: False
0 activate <t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior: False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0 hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate <t1> time: 5 prior: False
5 interrupt by: <t2> of: <t1>
5 <t2> terminated
5 <t3> terminated
5 hold <t1> delay: 45
50 <t1> terminated

 - Dan

On Wed, Sep 10, 2008 at 7:08 PM, Dan Homerick <danhomerick <at> gmail.com> wrote:

I'm not sure if this is a problem with SimPy code or mine, but I'm having trouble getting multiple, simultaneous interrupts to both take effect. Any advice or workarounds?

# --- test code ---
import SimPy.SimulationTrace as Sim

class Test(Sim.Process):
    def __init__(self, name):
        Sim.Process.__init__(self, name=name)

    def be_interrupted(self):       
        print self.name, "waiting to be interrupted..."
        yield Sim.hold, self, 50
        while self.interrupted():
            self.interruptReset()
            yield Sim.hold, self, self.interruptLeft
   
    def interrupt_other(self, other):
        yield Sim.hold, self, 5
        self.interrupt(other)

Sim.initialize()
t1 = Test('t1')
t2 = Test('t2')
t3 = Test('t3')

Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2, t2.interrupt_other(t1))
Sim.activate(t3, t3.interrupt_other(t1))

Sim.simulate(until=50)

 

 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users

Gmane