Package: simpy-events
simpy-eventsevent system withSimPyto decouple simulation code and increase reusability( >>>>>>>WORK IN PROGRESS<<<<<<< )A basic exampleNoteSimPyis a process-based discrete-event simulation framework based on standard Python.Our simplified scenario is composed of:satellites emitting signalsreceivers receiving and processing signalsbasic imports and creating the root namespace:fromsimpy_events.managerimportRootNameSpaceimportsimpyroot=RootNameSpace()implementing a satellite model:sat=root.ns('satellite')classSatellite:chunk=4def__init__(self,name,data):self.signal=sat.event('signal',sat=name)self.data=tuple(map(str,data))defprocess(self,env):signal=self.signaldata=self.datachunk=self.chunk# slice data in chunksforchunkin[data[chunk*i:chunk*i+chunk]foriinrange(int(len(data)/chunk))]:event=env.timeout(1,','.join(chunk))yieldsignal(event)implementing a receiver model:receiver=root.ns('receiver')signals=receiver.topic('signals')@signals.afterdefreceive_signal(context,event):env=event.envmetadata=context.event.metadataheader=str({key:valforkey,valinmetadata.items()ifkeynotin('name','ns')})env.process(process_signal(env,header,event.value))defprocess_signal(env,header,signal):receive=receiver.event('process')fordatainsignal.split(','):yieldreceive(env.timeout(0,f'{header}:{data}'))creating code to analyse what’s going on:@root.enable('analyse')defnew_process(context,event):metadata=context.event.metadatacontext={key:str(val)forkey,valinmetadata.items()}print(f'new signal process:{context}')@root.after('analyse')defsignal(context,event):metadata=context.event.metadatans=metadata['ns']print(f'signal:{ns.path}:{event.value}')setting up our simulation:root.topic('receiver::signals').extend(['::satellite::signal',])root.topic('analyse').extend(['::satellite::signal','::receiver::process',])defrun(env):# create some actorss1=Satellite('sat1',range(8))s2=Satellite('sat2',range(100,108))env.process(s1.process(env))env.process(s2.process(env))# executeroot.enabled=Trueenv.run()running the simulationnew signal process: {'ns': '::satellite', 'name': 'signal', 'sat': 'sat1'}
new signal process: {'ns': '::satellite', 'name': 'signal', 'sat': 'sat2'}
signal: ::satellite: 0,1,2,3
new signal process: {'ns': '::receiver', 'name': 'process'}
signal: ::satellite: 100,101,102,103
new signal process: {'ns': '::receiver', 'name': 'process'}
signal: ::receiver: {'sat': 'sat1'}: 0
signal: ::receiver: {'sat': 'sat2'}: 100
signal: ::receiver: {'sat': 'sat1'}: 1
signal: ::receiver: {'sat': 'sat2'}: 101
signal: ::receiver: {'sat': 'sat1'}: 2
signal: ::receiver: {'sat': 'sat2'}: 102
signal: ::receiver: {'sat': 'sat1'}: 3
signal: ::receiver: {'sat': 'sat2'}: 103
signal: ::satellite: 4,5,6,7
new signal process: {'ns': '::receiver', 'name': 'process'}
signal: ::satellite: 104,105,106,107
new signal process: {'ns': '::receiver', 'name': 'process'}
signal: ::receiver: {'sat': 'sat1'}: 4
signal: ::receiver: {'sat': 'sat2'}: 104
signal: ::receiver: {'sat': 'sat1'}: 5
signal: ::receiver: {'sat': 'sat2'}: 105
signal: ::receiver: {'sat': 'sat1'}: 6
signal: ::receiver: {'sat': 'sat2'}: 106
signal: ::receiver: {'sat': 'sat1'}: 7
signal: ::receiver: {'sat': 'sat2'}: 107install and testinstall from pypiusing pip:$pipinstallsimpy-eventsdev installThere is a makefile in the project root directory:$makedevUsing pip, the above is equivalent to:$pipinstall-rrequirements-dev.txt$pipinstall-e.run the testsUse the makefile in the project root directory:$maketestThis runs the tests generating a coverage html reportbuild the docThe documentation is made with sphinx, you can use the makefile in the
project root directory to build html doc:$makedocDocumentationDocumentation onRead The Docs.Metaloicpw -peronloic.us@gmail.comDistributed under the MIT license. SeeLICENSE.txtfor more information.https://github.com/loicpw