<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>PyTri, a Visual Agent Programming Language</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Jochen Simon</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Daniel Moldt</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Hamburg, Department of Informatics</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>PyTri is a Python based visual agent programming language which has been designed top-down to utilize the possibilities of graphical representation of control ow by amending the concepts of Petri nets. Its main inspiration, Mulan, which is based on Java nets, originated bottomup from a powerful formalism, which allows modeling and programming multi-agent systems. The here presented PyTri vision uses multiple types of transitions and places, with a specialized Python-based inscription language, in order to o er a rich semantics that allows expressive and compact representation of executable code. GUI widgets can be directly embedded into the nets and can infuse them with tokens upon user interaction. PyTri aims to support coarsening mechanisms, instead of the net within net paradigm, and includes a special place class that allows representation of independent control ow streams. It strives to enable modularization of complex multi-agent applications as one huge at structure, not requiring them to be separated into discrete layers. Integral to PyTri is a future tool for visualization and manipulation which is tailored to the needs of programmers using the language.</p>
      </abstract>
      <kwd-group>
        <kwd>PyTri</kwd>
        <kwd>Renew</kwd>
        <kwd>graphical visual programming language</kwd>
        <kwd>agents</kwd>
        <kwd>Petri nets</kwd>
        <kwd>formalism</kwd>
        <kwd>reactive programming</kwd>
        <kwd>Python</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Visual Languages o er more modalities[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] for representing and incorporating the
semantics of a program, compared to traditional textual languages. They directly
express the control ow of the processes inside an application, unlike line-based
text les with procedural jumps. In recent functional languages a plethora of
di erent ways to compose functions emerged, resulting in arrows which are more
general than monads. However, understanding the underlying mechanisms and
being able to utilize them, requires at least basic pro ciency in category theory.
      </p>
      <p>Petri nets o er a very intuitive way of representing arbitrary computation
processes by decomposing them into atomic actions and intermediate chunks of
data, incorporated by transitions and places. By embedding external triggers
into a net, reactive programming can be done without the hassle of splitting up
the code into steps.</p>
      <p>The human mind in general is very good at memorizing structures visually,
grouping related objects by spatial proximity. There are several types of UML
diagrams which are a popular method to visualize the interrelations of the classes
and objects of an application. By modeling an application with a Petri net like
net formalism in one single huge structure, the big picture can be shown as a
direct map of the internal processes, possibly even in three dimensions. Of course,
mechanisms of coarsening have to be used, in addition to modularizing the code
into organ-like fragments, or none would be able to cope with the complexity.</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] several existing visual languages were looked at, some general
criteria were investigated and PyTri, a visual agent programming language based
on Python was devised. Amongst the investigated languages were YAWL[
        <xref ref-type="bibr" rid="ref9">9</xref>
        ],
AgentSheets[
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], AUML[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], LabVIEW[
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] and Quartz Composer[
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. PyTri is heavily
inspired by the Java net formalism of Renew, which is based on reference nets,
whose theoretical foundations were laid down in [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Java nets allow modeling
and execution of complex multi-agent based distributed applications[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], through
a sophisticated tool set[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. Java nets have been designed bottom-up, starting
with the reference net formalism, and are especially suited for modeling.
      </p>
      <p>In Section 2 the mission statement for PyTri, the aims of its semantics, and
the most important properties of its formalism are given. Section 3 introduces
the idea of specialized types of places and transitions, a mixed class of elements,
PyTri's focus on coarsening and re nement, and tool support. Section 4 discusses
the results of the design of PyTri and future work.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Goals of PyTri</title>
      <p>PyTri aims to be an expressive and compact language, condensing common
programming tasks to a clean and descriptive representation. PyTri has been
designed from the start with the goal of making the creation of multi-agent
based applications as comfortable as possible. Essential to PyTri is an extensive
graphical editor displaying the net code, designed for developing, debugging and
manipulating. The concepts of PyTri have been designed top-down with a focus
on programming, not modeling. PyTri aims to employ a rather complex semantics,
and is targeted at experienced programmers willing to learn its large vocabulary.
It still tries to be intuitive, without dumbing down, in order to be accessible to
novices, given a set of good tutorials, gradually introducing the concepts.</p>
      <p>The Java net formalism has some assembler like aspects to it, because
one has to perform a lot of bookkeeping by hand to perform basic tasks. The
formalism of PyTri attempts to take graphical programming to a higher level
of abstraction, retaining a semantics that is very similar to that of Petri nets,
but di ering in several important ways, still including elements that act very
much like traditional places and transitions. Rather than having one kind of place
and transition that is used for everything, the formalism is based on specialized
elements that are the basic primitives of the language and can be compared to
statements in textual languages, like if, while, try, def or return.</p>
      <p>In order to allow compact branching of control ow, the PyTri formalism
deviates from the Petri net semantics by allowing transitions to dynamically
decide to suppress the donation of tokens to speci c target places. This means
that the actual control ow is no longer apparent from the arc connections alone,
but dependent on the inscriptions of the transitions. Such conditional branching
would su ce, and may be the best solution in some cases, but in other cases
having a specialized transition type, with a di erent inscription semantics, can
be useful syntactic sugar and convey the intention of the code in a better way.
An example is the Switch transition shown in Figure 1, which can be used to
evaluate an expression and donate a token only through the arc whose inscription
matches, or can evaluate a set of arcs inscribed with boolean expressions and
independently donate tokens through all those that are true.</p>
      <p>PyTri's inscription language is based on Python, which was chosen because it
is a very compact and powerful high-level language and o ers a great standard
library. It is attempted to allow almost arbitrary Python code in the
inscriptions, while amending the inscription language with the required new concepts,
pythonically. It uses pythonic duck typing, where Java nets guarantee that only
certain types of objects can traverse an arc. A lot of the expressiveness of Java
nets comes from uni cation, which allows fully dynamic connections between
elements. PyTri aims for a simpler and easier to understand semantics, which
introduces other mechanisms to cope with the loss of the prolog-like power.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Complex Elements and Tool Support</title>
      <p>Place Types. Just like in Petri nets and Java nets, places are passive and do not
initiate actions by themselves, however, they are preconditions to the transitions
that accept tokens from them. Instead of having one general kind of place which
is used universally to store data, PyTri o ers several types. Usually, places are
either used to store a single token or to store a collection of tokens, rarely both.</p>
      <p>When storing single tokens, places are usually used either for signifying and
determining the control ow, or as a single variable holding intermediate or
persistent data objects, which leads to the place types Flow and Variable.</p>
      <p>When storing a collection of tokens, one usually wants it to behave like one
common abstract data type, depending on the context. By incorporating the
required behavior in a place type, Queue or Stack for example, the programmer
can be spared of the otherwise necessary manual bookkeeping. Also, special place
types can exist simply to provide helpful eye candy to the developer, or simplify
debugging of agents by easing the assignment of the states an agent can be in.
Transition Types. Many abstract mechanisms integral to programming are not
atomic, but are composed of multiple steps. By having basic elements that execute
multiple atomic phases when needed, while storing internal data, the language
becomes more compact in its expressiveness. Those elements of this kind, which
in essence are transition-bordered components, can be considered similar enough
in concept to transitions to justify raising them to their level. Through this
the concept of transitions is extended to a set of basic graphical statements
building the core language. Since the individual phases are still atomic, complex
multi-phase transitions should be decomposable to nets of places and atomic
transitions. This decomposition however can also be virtual, since the behavior
may be implemented through pure Python objects with a certain interface.</p>
      <p>Some transition types require special interactions with certain types of places
in order to achieve their purpose. Some transitions work like components built
out of elements connected to other transitions via virtual arcs. PyTri has been
designed from the start with the aim of creating a language tailored to the
creation of multi-agent systems. Amongst the basic transitions are elements that
allow sending messages to other agents, receiving messages, or a combination.
Gadgets. In order to directly embed GUI components into the nets, a new general
type of element was devised. Gadgets are the representation for mixed-border
components, which can perform proactive actions, but also expose their internal
data to connected transitions, like a place. The internal virtual elements of
a gadget are connected to the elements around it, based on the aliases of the
connecting arcs. Gadgets have a consistent semantics that enables them to directly
interact with the surrounding net by donating tokens, acting as a precondition,
and receiving tokens. For GUI components, the behavior can be encapsulated in
pure Python proxy objects that perform all required bookkeeping transparently.
In Figure 2, a dialog is visible and tangible to a local user, as long as a token is
inside the leftmost place. When one of the two buttons is pressed, the dialog hides,
consumes the rst token and donates a new token through the matching arc. As
a result, either the user name is copied into the net, or the agent terminates.
Coarsening. The main mechanism of modularization in Java nets is the nets
within nets approach, since places can contain net objects. Contained nets can
interact, through their own internal transitions, with outer transitions connected
to their place, using synchronous channels. However, this approach introduces a
sharp partitionment of the code into layers, resulting in a break of continuity.</p>
      <p>PyTri favors a at structure where all elements are on one universal layer, and
other mechanisms for partitioning are used instead. Some control ows need to
be executed in multiple independent instantiations, for example protocols that
control interactions between agents. Instead of instantiating protocol nets as is
done in Mulan, such code can be modeled through a new class of place. Parallel
places transparently manage all bookkeeping necessary to atten the behavior
into a single structure, where tokens move in independent streams, separating
the structure into virtual instances. Such places can also give an informational
summary of all independent streams to the developer, during execution. This
mechanism can be enhanced to allow piecing together net structures that look
like AUML diagrams.</p>
      <p>Coarsening and re nement of nets is a very powerful mechanism to make
big structures controllable. By allowing to collapse and expand collections of
elements forming a component, one can choose the optimal level of detail of
the representation of the code. This can be used to modularize the code and
the resulting segments can be coarsened to look just like normal elements. An
interface for such a segment can be de ned by specifying which of the contained
elements are accessible through certain aliases. Depending on whether only places,
transitions, or both are accessible, segments are represented as such an element,
in the mixed case as a gadget.</p>
      <p>Tool Support. An integral part of PyTri is having tool support for the language,
namely a Monipulator that allows creation, manipulation, monitoring and
debugging of net code. In order to allow developers to separate big nets into manageable
chunks, they can be partitioned into fragments, which are joined into a at whole
net, maintaining the original semantics.</p>
      <p>The preliminary maxim of PyTri, which arose due to the global interpreter
lock of Python, is that every agent is its own process. There is no global simulator
process that contains, manages and controls agents. Memory is not shared between
agents, which have to rely on interprocess-interaction, facilitated by a process
present on every machine of a distributed environment.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Conclusions</title>
      <p>
        Programing complex systems remains a challenge. This paper provides a vision
in form of a new graphical programming language to address this problem. PyTri
overcomes some drawbacks of the successful extension of Java in the form of
reference nets with agent concepts from Mulan. It does so by amending a di erent
language, namely Python, and adding several new or adapted constructs and
concepts to the language with respect to the graphical underpinning. While it is
strongly in uenced by Petri nets, its semantics is adapted to the requirements of
programming and explores a lot of di erent possible programming mechanisms,
in order to investigate the realm of possibility. This allows for powerful expression
of behavior through new constructs and concepts. PyTri's concepts, the
prototypical implementation, written in Stackless Python, using PyQt, and the whole
background of the language has been intensively discussed in [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. Currently the
main features are: Python as the inscription language, a powerful semantics with
concepts and constructs to express important agent features, and an available
prototype for some of the central concepts.
      </p>
      <p>Our current direction of research is now to provide a proper Petri net semantics
for the current concepts and constructs. Concepts and experiences from reference
nets, Renew and Mulan/Capa will give further directions of development
beside the direct evaluation of the current PyTri tool set. The main goal is
to keep and extend PyTri as a powerful modeling and programming language
while trying to regain the analytical power of Petri nets, which is currently
lost. In order to truly seize the power of a language which directly expresses
concurrency, a di erent implementation base for the execution core and the
inscription language has to be considered, possibly based on PyPy or C++.
Besides PyTri as a language, the tools around PyTri will also be subject to several
di erent investigations. In the future, a series of prototypes, no longer based on
Stackless, which gradually implement more and more concepts of the language,
will be created. Here concrete, at the beginning rather arti cial applications will
further help to nd the right modeling and programming concepts.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Apple</given-names>
            <surname>Developer</surname>
          </string-name>
          <article-title>Connection { Quartz Composer</article-title>
          . http://developer.apple.com/graphicsimaging/quartzcomposer/ (
          <year>2009</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Cabac</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          :
          <article-title>Modeling Agent Interaction Protocols with AUML Diagrams and Petri Nets</article-title>
          .
          <source>Diploma thesis</source>
          , University of Hamburg, Department of Computer Science, Vogt-Kolln Str. 30,
          <string-name>
            <given-names>D</given-names>
            <surname>-</surname>
          </string-name>
          22527
          <string-name>
            <surname>Hamburg</surname>
          </string-name>
          (Dec
          <year>2003</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Cabac</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          :
          <article-title>Modeling Petri Net-Based Multi-Agent Applications</article-title>
          . Logos Verlag, Berlin (
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Cabac</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          , Dorges,
          <string-name>
            <surname>T.</surname>
          </string-name>
          , Rolke, H.:
          <article-title>A monitoring toolset for Petri net-based agentoriented software engineering</article-title>
          . In: Valk, R., van Hee,
          <string-name>
            <surname>K.M.</surname>
          </string-name>
          <article-title>(eds.) 29th Petri net conference</article-title>
          ,
          <source>Xi'an, China. LNCS</source>
          , vol.
          <volume>5062</volume>
          , pp.
          <volume>399</volume>
          {
          <fpage>408</fpage>
          . Springer-Verlag (
          <year>Jun 2008</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Jensen</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          :
          <source>Coloured Petri Nets : Basic Concepts</source>
          ,
          <source>Analysis Methods and Practical Use</source>
          . Volume
          <volume>1</volume>
          (
          <article-title>Monographs in TCS</article-title>
          .
          <source>An EATCS Series)</source>
          . Springer-Verlag (
          <year>1992</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Johnson</surname>
          </string-name>
          , G.,
          <string-name>
            <surname>Jennings</surname>
          </string-name>
          , R.:
          <article-title>LabVIEW graphical programming</article-title>
          .
          <string-name>
            <surname>McGraw-Hill Professional</surname>
          </string-name>
          (
          <year>2006</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Kummer</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          :
          <string-name>
            <surname>Referenznetze</surname>
          </string-name>
          . Logos Verlag, Berlin (
          <year>2002</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Repenning</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ioannidou</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>Agent-based end-user development</article-title>
          .
          <source>Commun. ACM</source>
          <volume>47</volume>
          (
          <issue>9</issue>
          ),
          <volume>43</volume>
          {
          <fpage>46</fpage>
          (
          <year>2004</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9. Russell:
          <article-title>Work ow control- ow patterns: A revised view</article-title>
          . http://www. work owpatterns.com/documentation/documents/BPM-06-22.pdf (
          <year>2006</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Simon</surname>
          </string-name>
          , J.:
          <article-title>Design of a Python Based Visual Agent Programming Language and its Prototypical Implementation</article-title>
          .
          <source>Bachelor thesis</source>
          , University of Hamburg, Department of Informatics (
          <year>2009</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>