Axon Shell Interactive Kamaelia In Tools in the Kamaelia distribution, we have the Axon Shell. This is an integration of IPython with Axon, with Axon running in a secondary shell, thus you can build Axon systems in the same way you build unix systems - interactively from the command line. Starting the Axon Shell The Axon shell can be found in the Tools directory of the Kamaelia distribution, named axonshell.py. In the following run through, we'll use bold italic to indicate something the user types.
First of all, start up the Axon Shell: # ./axonshell.py Starting Axon Interactive Shell ***Called from top level. Hit Ctrl-D to exit interpreter and continue program. In [1]: You're then greeted by the IPython default command line prompt. (This is the line labeled 'In [1]:' ) If you want, you can confirm that Axon is indeed already loaded and available: In [1]: Axon The line starting "Out [1]' is output from IPython, in this case displaying where the Axon module was loaded from. Loading and Running a Component The next thing we might want to know is how to load and run a component. This is pretty much as you would do with a component in a running system, the difference is as soon as we activate the component it starts immediately - this is due to the scheduler running in a separate thread: In [2]: import Kamaelia.UI.Pygame.Ticker In [3]: myticker = Kamaelia.UI.Pygame.Ticker.Ticker() In [4]: myticker Out[4]: <Kamaelia.UI.Pygame.Ticker.Ticker object at 0x40991aec> This shows the creation of a component, which we can now activate: In [5]: myticker.activate() Out[5]: <Kamaelia.UI.Pygame.Ticker.Ticker object at 0x40991aec> At this point in time a pygame window appears with a blank (white on white) ticker. We can then send a message to the tickers main inbox as follows: In [6]: myticker._deliver("This is some text") This text then appears - but it does so instantaneously - too quick to notice... Sending a Component Data OK, so that's relatively interesting, but let's make this more visible. We'll grab a chunk of text, split it into words, and deliver those every tenth of a second. One source of text is documentation, so let's check the size of the docstring for the pydoc module: In [7]: import pydoc In [8]: print len(pydoc.__doc__) 1305 This looks like a reasonable size, but how many chunks would this split into, if we do a rough word split? In [9]: print len(pydoc.__doc__.split()) 217 217 words seems reasonable - if we have this displayed at a rate of 10 words per second this will take about 20 seconds - nice for testing, not too long, not too short. OK, so lets just deliver these every 0.1 seconds apart: In [10]: import time
In [11]: for i in pydoc.__doc__.split(): myticker._deliver(i) time.sleep(0.1) And key presto - we have a working ticker controlled from the command line :) Building and using Pipelines OK, so that's nice, what else can we do? Making the pipeline Let's try the graph viewer. For this we need to build a simple pipeline, because it's a lot simpler to send text strings to the graph viewer rather than data structures (though we could send data structures). First of all we need to import the components we're going to use: In [12]: from Kamaelia.Visualisation.PhysicsGraph.TopologyViewerComponent import TopologyViewerComponent In [13]: from Kamaelia.Visualisation.PhysicsGraph.lines_to_tokenlists import lines_to_tokenlists In [14]: from Kamaelia.Util.PipelineComponent import pipeline Then we can build the pipeline, activate it and take a reference to it. This is however relatively simple: In [15]: myvis = pipeline(lines_to_tokenlists(),
TopologyViewerComponent() ).activate() And just as before, the topology viewer appears instantaneously. Using the pipeline This topology viewer understands messages sent to it of the following two forms:
So let's try it! Let's draw a simple producer consumer system. First of all, let's create a producer node ... In [16]: myvis._deliver("ADD NODE Producer Producer auto -") ... and it appears. So let's create a consumer node ... In [17]: myvis._deliver("ADD NODE Consumer Consumer auto -") ... and that appears. Creating a link between then is then also simple: In [18]: myvis._deliver("ADD LINK Producer Consumer") And the link appears. The topology viewer is then still interactive, so you can move the nodes around etc. Using the pipeline to visualise something more complex OK, that's fairly interesting - let's try visualising the systems described in Simple Reliable Multicast.So we start off by wiping the display: In [19]: myvis._deliver("DEL ALL") We can then add on the 4 components in the server piple line as nodes. For convenience I'm giving them ids "1", "2", "3" and "4". In [20]: myvis._deliver("ADD NODE 1 FileReader auto -") In [21]: myvis._deliver("ADD NODE 2 SRM_Sender auto -") In [22]: myvis._deliver("ADD NODE 3 blockise auto -") In [23]: myvis._deliver("ADD NODE 4 Multicast_transceiver auto -") Then we simply add in the links: In [25]: myvis._deliver("ADD LINK 1 2")
In [26]: myvis._deliver("ADD LINK 2 3") In [27]: myvis._deliver("ADD LINK 3 4") Similarly, we can add in the client side components ... In [48]: myvis._deliver("ADD NODE 5 Multicast_transeiver auto -") In [49]: myvis._deliver("ADD NODE 6 detuple auto -") In [50]: myvis._deliver("ADD NODE 7 SRM_Receiver auto -") In [51]: myvis._deliver("ADD NODE 8 detuple auto -") In [52]: myvis._deliver("ADD NODE 9 VorbisDecode auto -") In [53]: myvis._deliver("ADD NODE 10 AOPlaybackAdaptor auto -") ... and add in their links: In [54]: myvis._deliver("ADD LINK 5 6") In [55]: myvis._deliver("ADD LINK 6 7") In [56]: myvis._deliver("ADD LINK 7 8") In [57]: myvis._deliver("ADD LINK 8 9") In [58]: myvis._deliver("ADD LINK 9 10") Summary This page has shown how you can use IPython and Kamaelia together to run the Axon shell. It's shown how you can build simple pipelines on the command line to do interesting tasks interactively - even things involving external event loops such as pygame based systems. |
Kamaelia
is an open source project originated from and guided by BBC
Research. For more information browse the site or get in
contact.
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved