#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Options

# Blog - Petri net programming (part 1)

Hi, I've added the following Article Blog - Petri net programming (part 1) and linked to it from the Blog-articles-in-progress page.

It's an introductory applied theory article, on Petri net programming. The idea for the writing format is to approach the concepts with the aim of writing programs that make them work. The readership would include coding enthusiasts, professional programmers, scientists interested in programming models, software engineers and computer scientists. They start with a tutorial recap of the topic, and then give programs to exercise the concepts, followed by a concept-based analysis of the code. The programs will be working toy models, which should give the readers some "clay" to work with.

This is the first of two articles on Petri net programming. It introduces Petri nets and then gives an expository presentation of a simulator program. This is applied to the simplified model of water synthesis / dissociation presented in the Network Theory blog. The firing rule is just to choose a random enabled transition. Here is the output from a sample run:

H, O, H2O, Transition
5, 3, 4, split
7, 4, 3, split
9, 5, 2, combine
7, 4, 3, combine
5, 3, 4, split
7, 4, 3, split
9, 5, 2, split
11, 6, 1, combine
9, 5, 2, split
...


The following article will extend the discussion and the code to cover the stochastic Petri nets.

By and large, it says what I meant to say, in the way I meant to say it. I am open to any feedback or suggestions, and whether there are any revisions I should make to get it blog-appropriate. I will be editing it, to change markdown to html, and to get the links right.

Personal note: I find blog writing to be really fun and educational. If you can learn enough about a topic to be able to write about it, and say something that is true and useful, then you can make a contribution without being an expert. You just need to be a sufficient number of steps ahead of your hypothesized reader. And if you did your homework, and "blogged" really far and wide, you'd be on the path towards becoming an expert.

«1

## Comments

• Options
1.

Added a couple of programming exercises.

Comment Source:Added a couple of programming exercises.
• Options
2.

Looks good. The one thing I'd recommend is just some messing around with the object constructor to make it slightly easier to specify the model, eg, you could use

petriNet = PetriNet([
([(2,"H"), (1,"O")], "combine", [(1,"H2O")]), # combine has 2 H inputs, 1 O input, and 1 H2O output
([(1,"H2O")], "split", [(2,"H"), (1,"O")]) # split has 1 H20 input, 2 H outputs, and 1 O output
])


with some minimal changes

    def __init__(this, systemSpec):
this.speciesNames = list(set([species for trans in systemSpec for idx in [0,2] for (_,species) in trans[idx]]))
this.transitionNames = [name for (_,name,_) in systemSpec]
this.transitions = this.BuildTransitions(systemSpec)

def BuildTransitions(this, systemSpec):

# map: transitionName -> Transition object
transitionMap = {}

for (inputSpecs,transitionName,outputSpecs) in systemSpec:
for (degree, speciesName) in inputSpecs:
if not(transitionMap.has_key(transitionName)):
transitionMap[transitionName] = Transition(transitionName)
transitionMap[transitionName].inputMap[speciesName] = degree

for (degree, speciesName) in outputSpecs:
if not(transitionMap.has_key(transitionName)):
transitionMap[transitionName] = Transition(transitionName)
transitionMap[transitionName].outputMap[speciesName] = degree

return transitionMap.values()


This hasn't changed any of the signifcant bits of the script, but might make it easier for people to take the "first steps" towards playing with it, eg adding some nonphysical extra reactions like H+H -> H2, H2-> H+H

Comment Source:Looks good. The one thing I'd recommend is just some messing around with the object constructor to make it slightly easier to specify the model, eg, you could use ~~~~ petriNet = PetriNet([ ([(2,"H"), (1,"O")], "combine", [(1,"H2O")]), # combine has 2 H inputs, 1 O input, and 1 H2O output ([(1,"H2O")], "split", [(2,"H"), (1,"O")]) # split has 1 H20 input, 2 H outputs, and 1 O output ]) ~~~~ with some minimal changes ~~~~ def __init__(this, systemSpec): this.speciesNames = list(set([species for trans in systemSpec for idx in [0,2] for (_,species) in trans[idx]])) this.transitionNames = [name for (_,name,_) in systemSpec] this.transitions = this.BuildTransitions(systemSpec) def BuildTransitions(this, systemSpec): # map: transitionName -> Transition object transitionMap = {} for (inputSpecs,transitionName,outputSpecs) in systemSpec: for (degree, speciesName) in inputSpecs: if not(transitionMap.has_key(transitionName)): transitionMap[transitionName] = Transition(transitionName) transitionMap[transitionName].inputMap[speciesName] = degree for (degree, speciesName) in outputSpecs: if not(transitionMap.has_key(transitionName)): transitionMap[transitionName] = Transition(transitionName) transitionMap[transitionName].outputMap[speciesName] = degree return transitionMap.values() ~~~~ This hasn't changed any of the signifcant bits of the script, but might make it easier for people to take the "first steps" towards playing with it, eg adding some nonphysical extra reactions like H+H -> H2, H2-> H+H
• Options
3.

I like what David Tanzer has done here. It's a simple text-based format, and the Python code starts and runs very quickly (instantly) on my ubuntu system. The output is in a comma-delimited format, so it could be loaded into a spreadsheet package as a .csv file and graphed.

I like part of David Tweed's idea for simplifying the syntax, but I would prefer being able to specify it as:

petriNet = PetriNet([
["H", "O", "H2O"],    # species
["combine", "split"], # transitions
([(2,"H"), (1,"O")], "combine", [(1,"H2O")]), # combine has 2 H inputs, 1 O input, and 1 H2O output
([(1,"H2O")], "split", [(2,"H"), (1,"O")]) # split has 1 H20 input, 2 H outputs, and 1 O output
])


This matches fairly closely the Petri net specification at wikipedia, where A net is a triple N = (P, T, F ). P is the set of places/states/species, T is the set of transitions, and F is the set of arcs between places and transitions. David Tweed's approach to organizing the arcs is more concise, and it highlights the important idea of complexes found in the Chemical Reaction Network literature. [(2,"H"), (1,"O")] and [(1,"H2O")] are the two complexes in this Petri net. I think it's important for users to have the separate lists of species and transitions, especially with a larger Petri net where it's easy to forget exactly what all the species and transition names are while you're working on specifying the arcs.

One other suggestion. In many Petri nets, the arc weight is always 1. Could you make the number optional, with a default value of 1? For example:

([(2,"H"), ("O")], "combine", [("H2O")])

Comment Source:I like what David Tanzer has done here. It's a simple text-based format, and the Python code starts and runs very quickly (instantly) on my ubuntu system. The output is in a comma-delimited format, so it could be loaded into a spreadsheet package as a .csv file and graphed. I like part of David Tweed's idea for simplifying the syntax, but I would prefer being able to specify it as: ~~~~ petriNet = PetriNet([ ["H", "O", "H2O"], # species ["combine", "split"], # transitions ([(2,"H"), (1,"O")], "combine", [(1,"H2O")]), # combine has 2 H inputs, 1 O input, and 1 H2O output ([(1,"H2O")], "split", [(2,"H"), (1,"O")]) # split has 1 H20 input, 2 H outputs, and 1 O output ]) ~~~~ This matches fairly closely the Petri net specification at [wikipedia](http://en.wikipedia.org/wiki/Petri_net), where _A net is a triple N = (P, T, F )_. P is the set of places/states/species, T is the set of transitions, and F is the set of arcs between places and transitions. David Tweed's approach to organizing the arcs is more concise, and it highlights the important idea of complexes found in the [Chemical Reaction Network literature](http://www.chbmeng.ohio-state.edu/~feinberg/LecturesOnReactionNetworks/). _[(2,"H"), (1,"O")]_ and _[(1,"H2O")]_ are the two complexes in this Petri net. I think it's important for users to have the separate lists of species and transitions, especially with a larger Petri net where it's easy to forget exactly what all the species and transition names are while you're working on specifying the arcs. One other suggestion. In many Petri nets, the arc weight is always 1. Could you make the number optional, with a default value of 1? For example: ~~~~ ([(2,"H"), ("O")], "combine", [("H2O")]) ~~~~
• Options
4.

FWIW, the reasoning behind my suggestion for changing the constructor syntax is the general principle in programming that it's a a bad idea to require the same thing to be specified manually multiple times in program source (because you're bound to forget one of the places to update). I'm less concerned about the internal representation as the "annoyance" factor of, say, adding a

    ([(2,"H")], "nonsense", (1,"H2")])


transition and getting a Python key-error whilst running because I didn't add "H2" to the list of species as well. But it's probably not a huge issue.

Regarding default weights, there's not a really easy way I know of. You could start with representing a set of input/output species as a list so that just with standard Python

["H"] * 2


evaluates to

["H","H"]


and then "recompress" within the function to get (2,"H"). This also raises the issue of if the multiply operator looks wrong in this context.

Comment Source:FWIW, the reasoning behind my suggestion for changing the constructor syntax is the general principle in programming that it's a a bad idea to require the same thing to be specified manually multiple times in program source (because you're bound to forget one of the places to update). I'm less concerned about the internal representation as the "annoyance" factor of, say, adding a ~~~~ ([(2,"H")], "nonsense", (1,"H2")]) ~~~~ transition and getting a Python key-error whilst running because I didn't add "H2" to the list of species as well. But it's probably not a huge issue. Regarding default weights, there's not a really easy way I know of. You could start with representing a set of input/output species as a list so that just with standard Python ~~~~ ["H"] * 2 ~~~~ evaluates to ~~~~ ["H","H"] ~~~~ and then "recompress" within the function to get (2,"H"). This also raises the issue of if the multiply operator looks wrong in this context.
• Options
5.
edited September 2012

I really like the idea of this article, David Tanzer! A couple of things before I post it:

1) Can I get you to click on the link to your name and add either information about what you do and what you hope to do on Azimuth, and/or a link to a webpage with more information about you? Then, when I say, "blog post by David Tanzer", people can find out more about you.

2) I like the idea of simplifying the syntax as David Tweed and/or Ken Webb suggests. Is that okay with you? Could you do one of those? With either of their syntaxes1, I can easily read the specification of a Petri net and understand it without knowing the nitty-gritty details of what's going on behind the scenes.

3) Converting from markdown to html is nice, but the first two points are more important. I'll be glad to do the html conversion just as payment for this first article. I find that's also a good way for me to read an article really carefully... I will probably wind up making lots of small spelling/grammar/style corrections/improvements, too, unless you tell me not to.

Anyway, this is great!

Comment Source:I really like the idea of this article, [[David Tanzer]]! A couple of things before I post it: 1) Can I get you to click on the link to your name and add either information about what you do and what you hope to do on Azimuth, and/or a link to a webpage with more information about you? Then, when I say, "blog post by [[David Tanzer]]", people can find out more about you. 2) I like the idea of simplifying the syntax as David Tweed and/or Ken Webb suggests. Is that okay with you? Could you do one of those? With either of their syntaxes<sup>1</sup>, I can easily read the specification of a Petri net and understand it without knowing the nitty-gritty details of what's going on behind the scenes. 3) Converting from markdown to html is nice, but the first two points are more important. I'll be glad to do the html conversion just as payment for this first article. I find that's also a good way for me to read an article really carefully... I will probably wind up making lots of small spelling/grammar/style corrections/improvements, too, unless you tell me not to. Anyway, this is great!
• Options
6.

I made a tiny change regarding David Tanzer's link to the 'network theory' series.

I'm gonna try to get Jacob Biamonte to draw this Petri net in our trademark style, for inclusion in this article - it'll tie this post to the other series, for people who already read that.

Comment Source:I made a tiny change regarding David Tanzer's link to the 'network theory' series. I'm gonna try to get Jacob Biamonte to draw this Petri net in our trademark style, for inclusion in this article - it'll tie this post to the other series, for people who already read that.
• Options
7.

Guys, thanks for the positive reviews!

David and Ken, those were good suggestions about improving the syntax for specifying the Petri nets. I assimilated these ideas and changed the program and the wiki page.

Here is how the toplevel now reads:

# combine: 2H + 1O -> 1H2O
combineSpec = ("combine", [["H",2],["O",1]], [["H2O",1]])

# split: 1H2O -> 2H + 1O
splitSpec = ("split", [["H2O",1]], [["H",2],["O",1]])

petriNet = PetriNet(
["H","O","H2O"],         # species
[combineSpec,splitSpec]  # transitions
)


Because it was getting a little dense, I defined each transition on its own line.

It was a big improvement in the syntax to bring all the information for each transition into the same place. Also, I put in the logic in the constructor to default the degree to 1. So this would also work:

# split: 1H2O -> 2H + 1O
splitSpec = ("split", [["H2O"]], [["H",2],["O"]])


I left the explicit 1's in the article, in that pedagogical context.

Also, I decided to retain the species list, because (1) it improves the readability, and (2) it serves a function, which is to define the ordering in which the columns get printed in the output.

John, thanks a lot for the encouragement, and for offering to do the final editing. It's fine with me for you to fix spelling, style, etc. A picture from Jacob Biamonte would be great! The only changes that I am still going to make are to the references. Also I will be expanding the information on my home page, as you suggested. I'll let you know when I am done. We are moving this week, intra-Brooklyn, so I may or may not get slowed down.

But there is no real overlap between our edit sets, so you can start any time that you want to. Also, let me know when you're done, I'd like to give it a final review.

Thanks!

Comment Source:Guys, thanks for the positive reviews! David and Ken, those were good suggestions about improving the syntax for specifying the Petri nets. I assimilated these ideas and changed the program and the wiki page. Here is how the toplevel now reads: # combine: 2H + 1O -> 1H2O combineSpec = ("combine", [["H",2],["O",1]], [["H2O",1]]) # split: 1H2O -> 2H + 1O splitSpec = ("split", [["H2O",1]], [["H",2],["O",1]]) petriNet = PetriNet( ["H","O","H2O"], # species [combineSpec,splitSpec] # transitions ) Because it was getting a little dense, I defined each transition on its own line. It was a big improvement in the syntax to bring all the information for each transition into the same place. Also, I put in the logic in the constructor to default the degree to 1. So this would also work: # split: 1H2O -> 2H + 1O splitSpec = ("split", [["H2O"]], [["H",2],["O"]]) I left the explicit 1's in the article, in that pedagogical context. Also, I decided to retain the species list, because (1) it improves the readability, and (2) it serves a function, which is to define the ordering in which the columns get printed in the output. John, thanks a lot for the encouragement, and for offering to do the final editing. It's fine with me for you to fix spelling, style, etc. A picture from Jacob Biamonte would be great! The only changes that I am still going to make are to the references. Also I will be expanding the information on my home page, as you suggested. I'll let you know when I am done. We are moving this week, intra-Brooklyn, so I may or may not get slowed down. But there is no real overlap between our edit sets, so you can start any time that you want to. Also, let me know when you're done, I'd like to give it a final review. Thanks!
• Options
8.

Looking good! I'm here to draw Petri nets, as we need them. I'll read this in detail and suspect it should be evident what we need... Interesting topic!

Comment Source:Looking good! I'm here to draw Petri nets, as we need them. I'll read this in detail and suspect it should be evident what we need... Interesting topic!
• Options
9.
edited September 2012

I'm given this blog article a little polishing. A few comments that may be useful to David Tanzer and other people who want to write more blog articles:

1. There's a standard header for blog articles in progress - if you write a blog article, just go here, for example, and copy it. I've done it for David's.

2. Instead of saying "we", be bold and use "I" if there's just one of you. This isn't an academic paper; this is you talking to the world and trying to get people to join a conversation.

3. Don't use markup like _this_ and **this** for italics and bold - it's fine on the wiki, but the blog only accepts HTML, and the wiki is happy with it too, so use <i>this</i> and <b>this</b>.

4. Similarly, use html like <h3> This </h3> to get section headers.

5. Similarly, use html &bull; to make bullets instead of *

6. I have changed the wording so that you're not promising to write another article. Having started many more blog article series than I've finished in my life, I've learned not to make promises. Of course I want you to keep on writing, but I don't want you to feel lousy if you don't. So, when I post this blog article I'll drop the "Part 1" in the title... and add it back on iff and when you write "Part 2".

7. Don't worry - be happy. I'd much rather have people write nice blog articles that are imperfectly formatted than to get intimidated by this list of instructions and give up before they start! I find that for me, the best way to read a blog article is in the process of editing it.

Comment Source:I'm given this blog article a little polishing. A few comments that may be useful to David Tanzer and other people who want to write more blog articles: 1. **[Please read and follow the advice about how to write a blog entry on the Azimuth Wiki](http://www.azimuthproject.org/azimuth/show/How+to#blog)**. 1. There's a standard header for blog articles in progress - if you write a blog article, just go [here](http://www.azimuthproject.org/azimuth/show/Blog+-+hierarchical+organization+and+biological+evolution+%28part+1%29), for example, and copy it. I've done it for David's. 1. Instead of saying "we", be bold and use "I" if there's just one of you. This isn't an academic paper; this is you talking to the world and trying to get people to join a conversation. 1. Don't use markup like _this_ and **this** for italics and bold - it's fine on the wiki, but the blog only accepts HTML, and the wiki is happy with it too, so use <i>this</i> and <b>this</b>. 1. Similarly, use html like <h3> This </h3> to get section headers. 1. Similarly, use html &bull; to make bullets instead of * 1. I have changed the wording so that you're not _promising_ to write another article. Having started many more blog article series than I've finished in my life, I've learned not to make promises. Of course I want you to keep on writing, but I don't want you to feel lousy if you don't. So, when I post this blog article I'll drop the "Part 1" in the title... and add it back on iff and when you write "Part 2". 1. **Don't worry - be happy**. I'd much rather have people write nice blog articles that are imperfectly formatted than to get intimidated by this list of instructions and give up before they start! I find that for me, the best way to read a blog article is in the process of editing it.
• Options
10.

A few more comments:

1. I got rid of the footnote-style references, since that's not the style the Azimuth blog has been using. Links to phrases are usually okay, but for more scholarly references see this advice - go down to For blog articles, do references nicely. I don't think we need that in this article, though!

2. In the process, I accidentally destroyed the reference David Tanzer had to Python... I guess to some official Python website. I hope he can fix that. Sorry!

3. It would look cuter to write wolf and rabbit rather than Wolf and Rabbit, since then it'll match the picture I included. However, I know that capitalized names better match the style of the Python progams... so whatever you prefer, David, is fine.

4. Finally, an actual substantive remark! David writes:

This is a good beginning, but observe the following limitation of our current program: it just randomly picks a rule.

How does it do that? How are the probabilities determined? I don't see an explanation of that anywhere in the article. True, you say:

FireOneRule obtains the list of enabled transitions, chooses one randomly, and fires it.

But I'd like to know the details - 'chooses one randomly' is not a precise specification of what's going on. Perhaps if I were smarter I could figure out what's going on from looking at the code... but I'm not, and there will be other people curious about this point.

Of course, as you note, this leads into the issue of stochastic Petri nets, but right now it seems you're somehow doing things randomly without specifying the probabilities. I know that 'indeterminism' in computer science is all about this, but I'd like to know how it's implemented here! Just a sentence or two, when the issue first shows up, would help a lot.

Comment Source:A few more comments: 1. I got rid of the footnote-style references, since that's not the style the Azimuth blog has been using. Links to phrases are usually okay, but for more scholarly references see [this advice](http://www.azimuthproject.org/azimuth/show/How+to#blog) - go down to **For blog articles, do references nicely**. I don't think we need that in this article, though! 1. In the process, I accidentally destroyed the reference David Tanzer had to Python... I guess to some official Python website. I hope he can fix that. Sorry! 1. It would look cuter to write **wolf** and **rabbit** rather than Wolf and Rabbit, since then it'll match the picture I included. However, I know that capitalized names better match the style of the Python progams... so whatever you prefer, David, is fine. 1. Finally, an actual substantive remark! David writes: > This is a good beginning, but observe the following limitation of our current program: it just randomly picks a rule. How does it do that? How are the probabilities determined? I don't see an explanation of that anywhere in the article. True, you say: > FireOneRule obtains the list of enabled transitions, chooses one randomly, and fires it. But I'd like to know the details - 'chooses one randomly' is not a precise specification of what's going on. Perhaps if I were smarter I could figure out what's going on from looking at the code... but I'm not, and there will be other people curious about this point. Of course, as you note, this leads into the issue of stochastic Petri nets, but right now it seems you're somehow doing things randomly without specifying the probabilities. I know that 'indeterminism' in computer science is all about this, but I'd like to know how it's implemented here! Just a sentence or two, when the issue first shows up, would help a lot.
• Options
11.
edited September 2012

Hi, David! Jacob Biamonte has drawn a picture of the Petri net for your main example, and I added it to the article. So, the article is ready to go apart from my comments above, and your approval of the changes I made.

I decided to make wolf and rabbit and death etc. be boldface, since I see you did something similar for the water Petri net.

So - let me know when you're happy for me to post this on the blog!

Comment Source:Hi, David! [[Jacob Biamonte]] has drawn a picture of the Petri net for your main example, and I added it to the article. So, the article is ready to go apart from my comments above, and your approval of the changes I made. I decided to make **wolf** and **rabbit** and **death** etc. be boldface, since I see you did something similar for the water Petri net. So - let me know when you're happy for me to post this on the blog!
• Options
12.

Great, I'm very excited about this progress. Jacob, thanks for the beautiful diagrams, and John thanks for the writing improvements.

After reading your changes, that led me to make one more pass, which I believe improves the flow. I would definitely accept your version for the submitted one, but John could you give this latest version a look. Here is a summary of the changes:

1. Introduction. I shortened this up. What I had written before contained meta-discussion about how I was planning to write the article (I was thinking out loud). That's not needed so much, once the article is written -- you can just do it, rather than explain your intentions about the writing.

2. I love the virus example, it really brings home the relevance of the topic. I just separated it out into its own section called "Example 1: Disease processes." The definition section is a bit dry and dense, but it's only four paragraphs, and I think its good to have it for reference all in one chunk, without an example inside of it.

3. Added section headers "Example 2: Population dynamics" and "Example 3: Chemical reaction networks."

4. Removed the exercise at the end of the section called "Top-level structure of the script," because this is already included in the exercises at the end.

5. Moved the method "SelectRandom" from the base class, up to the main class PetriNet. This should make the selection method more visible. The method is just this: let enabledList = the list of enabled transitions, let i be a random integer between 1 and length(enabledList), then choose enabledList[i].

6. Added a sentence at the end of the text for "Class PetriNet" which describes the selection method.

7. Added to acknowledgments, for the help of you and Jacob.

I had to tweak the program a drop, for step 5. Tonight I will post the updated source code on my NYU home page, and update the link to point to it. That will also give me the option of making adjustments later on.

Thanks!!

Comment Source:Great, I'm very excited about this progress. Jacob, thanks for the beautiful diagrams, and John thanks for the writing improvements. After reading your changes, that led me to make one more pass, which I believe improves the flow. I would definitely accept your version for the submitted one, but John could you give this latest version a look. Here is a summary of the changes: 1. Introduction. I shortened this up. What I had written before contained meta-discussion about how I was planning to write the article (I was thinking out loud). That's not needed so much, once the article is written -- you can just do it, rather than explain your intentions about the writing. 2. I love the virus example, it really brings home the relevance of the topic. I just separated it out into its own section called "Example 1: Disease processes." The definition section is a bit dry and dense, but it's only four paragraphs, and I think its good to have it for reference all in one chunk, without an example inside of it. 3. Added section headers "Example 2: Population dynamics" and "Example 3: Chemical reaction networks." 4. Removed the exercise at the end of the section called "Top-level structure of the script," because this is already included in the exercises at the end. 5. Moved the method "SelectRandom" from the base class, up to the main class PetriNet. This should make the selection method more visible. The method is just this: let enabledList = the list of enabled transitions, let i be a random integer between 1 and length(enabledList), then choose enabledList[i]. 6. Added a sentence at the end of the text for "Class PetriNet" which describes the selection method. 7. Added to acknowledgments, for the help of you and Jacob. I had to tweak the program a drop, for step 5. Tonight I will post the updated source code on my NYU home page, and update the link to point to it. That will also give me the option of making adjustments later on. Thanks!!
• Options
13.

Those all sounds like good changes, David. I'll give the article another gentle edit. For example, if you like that virus model, and you didn't include a link to the blog article where I talked about it, I'll do that now.

The method is just this: let enabledList = the list of enabled transitions, let i be a random integer between 1 and length(enabledList), then choose enabledList[i].

Okay, that makes sense! If you didn't explain this in words, I'll add an explanation. There are some sort of people who won't want to peek into the code to see what's going on.

Comment Source:Those all sounds like good changes, David. I'll give the article another gentle edit. For example, if you like that virus model, and you didn't include a link to the blog article where I talked about it, I'll do that now. > The method is just this: let enabledList = the list of enabled transitions, let i be a random integer between 1 and length(enabledList), then choose enabledList[i]. Okay, that makes sense! If you didn't explain this in words, I'll add an explanation. There are some sort of people who won't want to peek into the code to see what's going on.
• Options
14.
edited September 2012

David Tanzer - I changed your 'Exercise' a bit, like this:

Exercise: Improve the script to accept the model parameters from the command-line.

By the way: if you do this exercise, please post a comment including your code, or a link to your code! To make Python code look pretty on this blog, see this.

I think it could be cool if people like you and Ken Webb and others posted blog articles containing exercises that involve writing programs that would actually be useful - at least for educational purposes. Then, if people solved them and posted working code, we could gather up these programs and do something interesting with them, like make a website full of Petri net programs.

One can imagine various levels of ambition here. It's dangerous to commit oneself prematurely to ambitious projects, but the great thing is that even with minimal ambition, we've got a blog article discussing a concept, followed by some comments containing programs that illustrate this concept. That's already a useful resource.

So, don't be shy about posting exercises.

By the way, I'll do what it takes to make your Python code look decent on the blog. If the instructions I linked to don't work, I'll find something that does.

Comment Source:[[David Tanzer]] - I changed your 'Exercise' a bit, like this: > **Exercise:** Improve the script to accept the model parameters from the command-line. > By the way: if you do this exercise, please post a comment including your code, or a link to your code! To make Python code look pretty on this blog, see <a href = "http://pythonconquerstheuniverse.wordpress.com/2011/11/06/posting-sourcecode-on-wordpress/">this</a>. I think it could be cool if people like you and [[Ken Webb]] and others posted blog articles containing exercises that involve writing programs that would actually be useful - at least for educational purposes. Then, if people solved them and posted working code, we could gather up these programs and do something interesting with them, like make a website full of Petri net programs. One can imagine various levels of ambition here. It's dangerous to commit oneself prematurely to ambitious projects, but the great thing is that even with _minimal_ ambition, we've got a blog article discussing a concept, followed by some comments containing programs that illustrate this concept. That's already a useful resource. So, don't be shy about posting exercises. By the way, I'll do what it takes to make your Python code look decent on the blog. If the instructions I linked to don't work, I'll find something that does.
• Options
15.

I made an editing mistake, and saved the changes that I described to a temporary page, not the blog page as I intended to do.

I've just saved them now to the blog article. And I merged in your change to the Exercise. You will find that at the end of the article.

Sorry for the confusion.

As far as making the Python code look nice, don't sweat it too much. Verbatim text is also fine, and fits in with the fact that the whole article is a text.

Comment Source:I made an editing mistake, and saved the changes that I described to a temporary page, not the blog page as I intended to do. I've just saved them now to the blog article. And I merged in your change to the Exercise. You will find that at the end of the article. Sorry for the confusion. As far as making the Python code look nice, don't sweat it too much. Verbatim text is also fine, and fits in with the fact that the whole article is a text.
• Options
16.
edited September 2012

John, In the section 1 on Disease processes, which contains the virus example, I started with one sentence to that describes one of the transitions. Could you add a couple of sentences that give color on the other transitions, especially the one called production? Maybe also a sentence about the Grim Reaper transitions. Thanks.

Comment Source:John, In the section 1 on Disease processes, which contains the virus example, I started with one sentence to that describes one of the transitions. Could you add a couple of sentences that give color on the other transitions, especially the one called production? Maybe also a sentence about the Grim Reaper transitions. Thanks.
• Options
17.

In full disclosure, I have some bias against "pretty printing" of programs, when the think looks more like a marquee than a set of formal definitions. Also, if forced the code into a small window with a scrollbar, there is less chance that people would read it as part of the text. I worked to make the classes small, so that none would go on for too long.

Granted it is very useful in an IDE, the question is will "prettification" contribute to, or detract from, a pedagogical article. I will retain an open mind about this.

Regards

Comment Source:In full disclosure, I have some bias against "pretty printing" of programs, when the think looks more like a marquee than a set of formal definitions. Also, if forced the code into a small window with a scrollbar, there is less chance that people would _read_ it as part of the text. I worked to make the classes small, so that none would go on for _too_ long. Granted it is very useful in an IDE, the question is will "prettification" contribute to, or detract from, a pedagogical article. I will retain an open mind about this. Regards
• Options
18.
edited September 2012

I don't know what an IDE is.

You can see what so-called "pretty" Python code looks like on a Wordpress blog here.

By the way, I wasn't using "pretty" in any sort of technical sense - I know nothing about this subject, so I don't know if experts consider this "pretty printing" or not. It's just a way I happen to know to get Python code to show up on a Wordpress blog. I believe the method you used here on the Wiki, where you just indent the text, doesn't work there. You can use <pre> </pre>, but that tends to create a window with a scrollbar, and I agree that sucks.

Comment Source:I don't know what an IDE is. You can see what so-called "pretty" Python code looks like on a Wordpress blog [here](http://pythonconquerstheuniverse.wordpress.com/2011/11/06/posting-sourcecode-on-wordpress/). By the way, I wasn't using "pretty" in any sort of technical sense - I know nothing about this subject, so I don't know if experts consider this "pretty printing" or not. It's just a way I happen to know to get Python code to show up on a Wordpress blog. I believe the method you used here on the Wiki, where you just indent the text, doesn't work there. You can use <pre> </pre>, but that tends to create a window with a scrollbar, and I agree that sucks.
• Options
19.

David Tanzer wrote:

John, In the section 1 on Disease processes, which contains the virus example, I started with one sentence to that describes one of the transitions. Could you add a couple of sentences that give color on the other transitions, especially the one called production? Maybe also a sentence about the Grim Reaper transitions. Thanks.

Okay, I did this, and also added a link to the blog article where I discussed this example, based on a talk I heard.

Comment Source:[[David Tanzer]] wrote: > John, In the section 1 on Disease processes, which contains the virus example, I started with one sentence to that describes one of the transitions. Could you add a couple of sentences that give color on the other transitions, especially the one called production? Maybe also a sentence about the Grim Reaper transitions. Thanks. Okay, I did this, and also added a link to the blog article where I discussed this example, based on a talk I heard.
• Options
20.

John, it's coming into shape. Thanks for the explanation of the disease process example.

I made the following edits:

1. Added some introductory sentences to the disease process example, and shortened up some of the other phrases. See if you like how it reads.

2. Posted the program on my external website, and changed the link to point to it.

3. Rewrote the SelectedRandom method of class PetriNet, to give a more transparent reading of how the random selection process works. See if this makes it self-explanatory.

4. Changed the closing phrase to say the second blog article that I am writing, rather than hope to write. I have a draft, on paper but not yet on the wiki.

5. Include acknowledgement for your contribution of the examples.

Pretty printing on wordpress looks fine. Why not have some more color in our lives. I leave it to you to format it as you see fit. The guiding principle is simply that it should be as readable as possible, and it would be nice if when you printed it, the whole text showed up. As the guy in the article points out, horizontal wrapping will kill the meaning of a Python program, since it is whitespace dependent. If we keep the lines short enough then they should fit in the window. Let me know if I should rewrite it with shorter lines. Because of the whitespace dependency of Python, it's a bit finicky about where you can break a line. So if we have to change it, it would be better for me to change the source, make sure it still runs, and post back to the wiki page. If it ends up forcing a vertical scrollbar, and you think it doesn't look good, I could increase the granularity of the discussion a bit, and quote only some of the class methods in each block. The base class is the longest one, at greatest risk of being put behind a window.

Thanks again.

p.s. Before I slipped into crotchety programmer mentality, and let an acronym slip out. IDE stands for integrated development environment, the all-in-one tools for developing and debugging programs. Examples being Visual Studio, Eclipse and Idle.

Comment Source:John, it's coming into shape. Thanks for the explanation of the disease process example. I made the following edits: 1. Added some introductory sentences to the disease process example, and shortened up some of the other phrases. See if you like how it reads. 2. Posted the program on my external website, and changed the link to point to it. 3. Rewrote the SelectedRandom method of class PetriNet, to give a more transparent reading of how the random selection process works. See if this makes it self-explanatory. 4. Changed the closing phrase to say the second blog article that I am writing, rather than hope to write. I have a draft, on paper but not yet on the wiki. 5. Include acknowledgement for your contribution of the examples. Pretty printing on wordpress looks fine. Why not have some more color in our lives. I leave it to you to format it as you see fit. The guiding principle is simply that it should be as readable as possible, and it would be nice if when you printed it, the whole text showed up. As the guy in the article points out, horizontal wrapping will kill the meaning of a Python program, since it is whitespace dependent. If we keep the lines short enough then they should fit in the window. Let me know if I should rewrite it with shorter lines. Because of the whitespace dependency of Python, it's a bit finicky about where you can break a line. So if we have to change it, it would be better for me to change the source, make sure it still runs, and post back to the wiki page. If it ends up forcing a vertical scrollbar, and you think it doesn't look good, I could increase the granularity of the discussion a bit, and quote only some of the class methods in each block. The base class is the longest one, at greatest risk of being put behind a window. Thanks again. p.s. Before I slipped into crotchety programmer mentality, and let an acronym slip out. IDE stands for integrated development environment, the all-in-one tools for developing and debugging programs. Examples being Visual Studio, Eclipse and Idle.
• Options
21.

Okay, David, it sounds like your blog article is ready to for me to transport to the Azimuth Blog. It looks good to me. This is really great - and I'm glad you've started work on part 2; starting something and telling other people about it is a good way to make oneself finish it.

The best time to post blog articles is early in the week, when people are groggily looking for excuses to not work: that's when my blog gets the most traffic.

So, Friday or this weekend, I'd like to post a short article announcing some things that are happening on Azimuth: your article, and another one I have lined up, and one by Matteo Smerlak called Blog - the mathematical origins of irreversibility, and Ken Webb's work on Petri nets, and Jim Stuttard's work on the Azimuth Server (something very short and nontechnical, just to whet people's appetite), and anything else I remember... That'll be a way for me to introduce you folks, and get people in the mood for what's to come.

Comment Source:Okay, David, it sounds like your blog article is ready to for me to transport to the Azimuth Blog. It looks good to me. This is really great - and I'm glad you've started work on part 2; starting something and telling other people about it is a good way to make oneself finish it. The best time to post blog articles is early in the week, when people are groggily looking for excuses to not work: that's when my blog gets the most traffic. So, Friday or this weekend, I'd like to post a short article announcing some things that are happening on Azimuth: your article, and another one I have lined up, and one by Matteo Smerlak called [[Blog - the mathematical origins of irreversibility]], and Ken Webb's work on Petri nets, and Jim Stuttard's work on the Azimuth Server (something very short and nontechnical, just to whet people's appetite), and anything else I remember... That'll be a way for me to introduce you folks, and get people in the mood for what's to come.
• Options
22.

Excellent.

I just added http links to the software distribution sites mentioned in the Appendix.

Comment Source:Excellent. I just added http links to the software distribution sites mentioned in the Appendix.
• Options
23.
edited September 2012

Hi David, this article looks really nice. I'm happy to draw as many Petri nets as you need, either ask John or please email me at jacob dot biamonte at qubit dot org.

Comment Source:Hi David, this article looks really nice. I'm happy to draw as many Petri nets as you need, either ask John or please email me at jacob dot biamonte at qubit dot org.
• Options
24.

I'm going to redraw the figure in section "Example 1: Disease processes". Currently, the font does not match the other Petri nets in the series, and the arrows seem slightly different. I can't do this now, as my linux machine (I use inkscape to draw these) is in the office.

Comment Source:I'm going to redraw the figure in section "Example 1: Disease processes". Currently, the font does not match the other Petri nets in the series, and the arrows seem slightly different. I can't do this now, as my linux machine (I use inkscape to draw these) is in the office.
• Options
25.

I will try to post this article on Monday, but whenever you create a new improved figure I'll replace the existing one with that, Jacob. Thanks!

Comment Source:I will try to post this article on Monday, but whenever you create a new improved figure I'll replace the existing one with that, Jacob. Thanks!
• Options
26.

OK, sounds great. We might as well make all the Petri net figures match, since we've managed to torture me this far drawing these things :D

About the article: we explain Petri nets, but not computer programming. Since this is not (yet anyway) a hacker friendly blog, I would at least benefit from a few lines here and there explaining the programming side of things!

For instance, I would maybe suggest before the section "A Petri net simulator" putting another short section, called "why python" or something like that. This way it could be justified why Python is an ideal choice for scientific programming, and some of its interesting features compared to other languages. For me, I have written a program in C/C++ and JAVA, but it was a while ago, but pointing out some of the cool reasons Python is the modern way to go might be fun. Actually, I plan to attempt the exercises just so I can follow along with this series!

Cheers and take everything I say with a grain of salt! (except for the Petri net figures, that's serious!)

Comment Source:OK, sounds great. We might as well make all the Petri net figures match, since we've managed to torture me this far drawing these things :D About the article: we explain Petri nets, but not computer programming. Since this is not (yet anyway) a hacker friendly blog, I would at least benefit from a few lines here and there explaining the programming side of things! For instance, I would maybe suggest before the section "A Petri net simulator" putting another short section, called "why python" or something like that. This way it could be justified why Python is an ideal choice for scientific programming, and some of its interesting features compared to other languages. For me, I have written a program in C/C++ and JAVA, but it was a while ago, but pointing out some of the cool reasons Python is the modern way to go might be fun. Actually, I plan to attempt the exercises just so I can follow along with this series! Cheers and take everything I say with a grain of salt! (except for the Petri net figures, that's serious!)
• Options
27.
edited September 2012

Jacob wrote:

Since this is not (yet anyway) a hacker friendly blog...

The blog is not particularly hacker friendly, since it's mainly written by me so far. But curiously, the forum here seems to attract good programmers. My latest article saying what we're up to has by now gotten about 8 new people to join the forum, and since the article was rather hacker-ish, I bet we'll get even more programmers. This is great, because programmers can actually do stuff. But I find it challenging since I feel like a sea captain who doesn't know the names of all the sails on the boat. Luckily I enjoy challenges...

Comment Source:Jacob wrote: > Since this is not (yet anyway) a hacker friendly blog... The blog is not particularly hacker friendly, since it's mainly written by me so far. But curiously, the forum here seems to attract good programmers. My latest article saying [what we're up to](http://johncarlosbaez.wordpress.com/2012/09/28/azimuth-news-part-2/) has by now gotten about 8 new people to join the forum, and since the article was rather hacker-ish, I bet we'll get even more programmers. This is great, because programmers can actually _do_ stuff. But I find it challenging since I feel like a sea captain who doesn't know the names of all the sails on the boat. Luckily I enjoy challenges...
• Options
28.

Hi Jacob, that is useful feedback about the text.

I was actually trying to de-emphasize the language choice of Python, for psychological reasons. For some reason, people (myself included) tend to get very partisan about choices of language, and it can that can become a distraction from the subject matter at hand, which the programmatic representation of a Petri net. The code I gave could be easily translated into equivalents in any modern object-oriented language. I think that the high valence for opinion formation stems from the fact that these are languages. You can imagine people from different nationalities arguing about which language is most logical, clear, or beautiful. I would hate to provoke this kind of discussion in the blog about Petri nets -- and it is not hard to provoke.

That said, I did indicate some basic reasons why Python works for me in the Appendix:

The sample program is written in Python, which is a low-fuss scripting language with abstraction capabilities.  The language is well-suited for proof-of-concept programming, and it has a medium-sized user base and support community.


The other thing is that I do like the way the syntax reads, and I hoped to to show that by using it, rather than asserting an opinion. Plus the casual user doesn't need to fuss with a compiler.

But none of this addresses your point. The solution I'm thinking of will be to introduce a small section explaining what programming constructs will be used in the simulator, most notably, objects with methods. Then in passing I can say that I chose Python for this blog article for expository reasons. I'll try to get this in tonight.

Thanks again for your help with the diagrams, and for giving the article a good read!

Comment Source:Hi Jacob, that is useful feedback about the text. I was actually trying to de-emphasize the language choice of Python, for psychological reasons. For some reason, people (myself included) tend to get very partisan about choices of language, and it can that can become a distraction from the subject matter at hand, which the programmatic representation of a Petri net. The code I gave could be easily translated into equivalents in any modern object-oriented language. I think that the high valence for opinion formation stems from the fact that these are _languages_. You can imagine people from different nationalities arguing about which language is most logical, clear, or beautiful. I would hate to provoke this kind of discussion in the blog about Petri nets -- and it is not hard to provoke. That said, I did indicate some basic reasons why Python works for me in the Appendix: The sample program is written in Python, which is a low-fuss scripting language with abstraction capabilities. The language is well-suited for proof-of-concept programming, and it has a medium-sized user base and support community. The other thing is that I do like the way the syntax reads, and I hoped to to show that by using it, rather than asserting an opinion. Plus the casual user doesn't need to fuss with a compiler. But none of this addresses your point. The solution I'm thinking of will be to introduce a small section explaining what programming _constructs_ will be used in the simulator, most notably, objects with methods. Then in passing I can say that I chose Python for this blog article for expository reasons. I'll try to get this in tonight. Thanks again for your help with the diagrams, and for giving the article a good read!
• Options
29.

I added a section called "Software structures used in the program". Also added one introductory sentence to the following section, called Top-level structure of the script.

The new section addresses Jacob's point, which is that there is another category of potential readers: people who want to learn more about programming itself, by means of some juicy examples.

I followed the approach of speaking neutrally first about the language constructs themselves, and then segued into some semi-objective semi-subjective discussion of the Python language.

John, if it's not too late, would would consider added this section to the blog. Sorry if this is a nuisance -- and I'd still be very happy to have the blog article posted as it was before this change.

Thanks, Dave.

Comment Source:I added a section called "Software structures used in the program". Also added one introductory sentence to the following section, called Top-level structure of the script. The new section addresses Jacob's point, which is that there is another category of potential readers: people who want to learn more about programming itself, by means of some juicy examples. I followed the approach of speaking neutrally first about the language constructs themselves, and then segued into some semi-objective semi-subjective discussion of the Python language. John, if it's not too late, would would consider added this section to the blog. Sorry if this is a nuisance -- and I'd still be very happy to have the blog article posted as it was before this change. Thanks, Dave.
• Options
30.
edited September 2012

David wrote:

John, if it’s not too late, would you consider adding this section to the blog.

Sure! On Monday I will take what's on the wiki, transfer it to the blog, make any formatting changes that are needed because the wiki and blog work differently... and if that process doesn't tire me out, I'll publish it.

So, any changes you make before Monday will easily get incorporated into the blog article. After that I'll only make changes that fix actual errors.

(If it turns out you want to post lots of blog articles, I can give you the ability to post them yourself, which means less work for me, more formatting work for you, but also the ability for you to keep fiddling with them after they're published, as I do with mine. But we don't need to decide this now; in fact it's better if we wait a bit.)

Comment Source:David wrote: > John, if it’s not too late, would you consider adding this section to the blog. Sure! On Monday I will take what's on the wiki, transfer it to the blog, make any formatting changes that are needed because the wiki and blog work differently... and if that process doesn't tire me out, I'll publish it. So, any changes you make before Monday will easily get incorporated into the blog article. After that I'll only make changes that fix actual errors. (If it turns out you want to post _lots_ of blog articles, I can give you the ability to post them yourself, which means less work for me, more formatting work for you, but also the ability for you to keep fiddling with them after they're published, as I do with mine. But we don't need to decide this now; in fact it's better if we wait a bit.)
• Options
31.

Learning a bit about programming and objects and methods seems great to me. About the language choice, I heard that Python is all the rage in scientific programming these days, replacing a lot of the other languages and all that. I heard it's even used as the standard at CERN. I've been using Matlab and Mathematica to program simple things, but if Python could do some of this stuff, it would be worth having something more powerful on hand, provided it's not overly complicated to use. So far, from what I've seen, it seems like a great choice!

I'm also interested to see how you program the stochastic Petri nets stuff -

When I return to the office tomorrow morning, I'll make that picture first thing (of course, there is nothing wrong with the one you found, it just does not match, but we can replace it with a matching one at any time). I'll then see about getting Python to work on my linux system, so I can try your programs and see if I'm able to do the exercises.

Comment Source:Learning a bit about programming and objects and methods seems great to me. About the language choice, I heard that Python is all the rage in scientific programming these days, replacing a lot of the other languages and all that. I heard it's even used as the standard at CERN. I've been using Matlab and Mathematica to program simple things, but if Python could do some of this stuff, it would be worth having something more powerful on hand, provided it's not overly complicated to use. So far, from what I've seen, it seems like a great choice! I'm also interested to see how you program the stochastic Petri nets stuff - When I return to the office tomorrow morning, I'll make that picture first thing (of course, there is nothing wrong with the one you found, it just does not match, but we can replace it with a matching one at any time). I'll then see about getting Python to work on my linux system, so I can try your programs and see if I'm able to do the exercises.
• Options
32.
edited September 2012

Jacob wrote

Learning a bit about programming and objects and methods seems great to me. About the language choice, I heard that Python is all the rage in scientific programming these days, replacing a lot of the other languages and all that. I heard it’s even used as the standard at CERN. I’ve been using Matlab and Mathematica to program simple things, but if Python could do some of this stuff, it would be worth having something more powerful on hand, provided it’s not overly complicated to use.

Programming languages are a lot like "motor vehicles": a family car has different trade-offs to a sports car to a small van to a big truck to a motorbike to .... Each of these has their own niche where they make the most sense to use.

I think a big part of Python's use comes from an the way that a lot of scientific programming is as much about "management" -- parsing files of prexisting structured data, iterating over data, controlling network connections, calling C code, launching subprograms, etc -- as much as "numeric computation". This is where Python is particularly good, and it's now acquired the NumPy & SciPy extensions to speed up the numerical programming elements, but it's primarily the higher level elements that make it attractive in science.

BTW: on a linux machine you almost certainly already have Python, since most package management stuff is written in python. Open a terminal, type python and see what happens.

Comment Source:Jacob wrote > Learning a bit about programming and objects and methods seems great to me. About the language choice, I heard that Python is all the rage in scientific programming these days, replacing a lot of the other languages and all that. I heard it’s even used as the standard at CERN. I’ve been using Matlab and Mathematica to program simple things, but if Python could do some of this stuff, it would be worth having something more powerful on hand, provided it’s not overly complicated to use. Programming languages are a lot like "motor vehicles": a family car has different trade-offs to a sports car to a small van to a big truck to a motorbike to .... Each of these has their own niche where they make the most sense to use. I think a big part of Python's use comes from an the way that a lot of scientific programming is as much about "management" -- parsing files of prexisting structured data, iterating over data, controlling network connections, calling C code, launching subprograms, etc -- as much as "numeric computation". This is where Python is particularly good, and it's now acquired the NumPy & SciPy extensions to speed up the numerical programming elements, but it's primarily the higher level elements that make it attractive in science. BTW: on a linux machine you almost certainly already have Python, since most package management stuff is written in python. Open a terminal, type python and see what happens.
• Options
33.

Thanks! That beats trying to install it! It looks like I also have it on my Mac!

Comment Source:Thanks! That beats trying to install it! It looks like I also have it on my Mac!
• Options
34.

I've created an experiment page to discuss four of the Petri nets that I've implemented. For each of the four I'm including a link to the original XML used by my Xholon Java-based software, and an equivalent version using David's Python syntax that's been automatically generated by Xholon. I also include line charts showing the results from running these models in the two tools. I'll be adding more content to the experiment page to explore the differences between the two, which I think partly has to do with the way each tool deals with probabilities.

Comment Source:I've [created an experiment page](http://www.azimuthproject.org/azimuth/show/Experiments+in+Petri+nets+-+Results+from+two+different+tools) to discuss four of the Petri nets that I've implemented. For each of the four I'm including a link to the original XML used by my Xholon Java-based software, and an equivalent version using David's Python syntax that's been automatically generated by Xholon. I also include line charts showing the results from running these models in the two tools. I'll be adding more content to the experiment page to explore the differences between the two, which I think partly has to do with the way each tool deals with probabilities.
• Options
35.

This is smashing stuff. Literate code and great graphics. It'll be great when they're interactive in the cloud. Ken, your bigraphs page has gone all [Math Processing Error].

Comment Source:This is smashing stuff. Literate code and great graphics. It'll be great when they're interactive in the cloud. Ken, your bigraphs page has gone all [Math Processing Error].
• Options
36.

Ken, this is exciting stuff. I'm glad that you were able to build on what I wrote. I will look more into it, when it is not 3 am :)

Jim, thanks for the Thumbs up.

Jacob, I really appreciate the energy and enthusiasm that you have for learning about the programming ideas in the article. Feel free to contact me if you have any question or issues, whether large or small. I am at gmail, my name there is dave.tanzer.

Tonight, I made the following edits:

• Reworked the second that I wrote in response to Jacob's comment. Now it is split into two sections: (1) Software constructs used in the program, and (2) Python as a language for pedagogical and scientific programming. I quoted David Tweed's insightful comments about Python in scientific programming, and about the general comparisons between languages.

• Tweaked the Acknowledgments.

I am done with this. John it's all yours. Thanks for all your efforts and encouragement.

Comment Source:Ken, this is exciting stuff. I'm glad that you were able to build on what I wrote. I will look more into it, when it is not 3 am :) Jim, thanks for the Thumbs up. Jacob, I really appreciate the energy and enthusiasm that you have for learning about the programming ideas in the article. Feel free to contact me if you have any question or issues, whether large or small. I am at gmail, my name there is dave.tanzer. Tonight, I made the following edits: * Reworked the second that I wrote in response to Jacob's comment. Now it is split into two sections: (1) Software constructs used in the program, and (2) Python as a language for pedagogical and scientific programming. I quoted David Tweed's insightful comments about Python in scientific programming, and about the general comparisons between languages. * Tweaked the Acknowledgments. I am done with this. John it's all yours. Thanks for all your efforts and encouragement.
• Options
37.
edited October 2012

Hi! I posted the article and announced it on G+:

If Allan Erskine or anyone else could point to it on Hacker News or similar places, that'd be great. In a minute I'll post a question to kick off the discussion.

By the way, David, you accidentally slipped and included some new links using

[this syntax](http://www.crud.com)

instead of

<a href = "http://www.crud.com">this one</a>

No big deal... but for people reading this who are interested in writing blog articles for Azimuth, please remember that the blog uses html instead of markdown language. More details are here:

Comment Source:Hi! I posted the article and announced it on G+: * David Tanzer, [Petri net programming](http://johncarlosbaez.wordpress.com/2012/10/01/petri-net-programming/), Azimuth Blog. If Allan Erskine or anyone else could point to it on Hacker News or similar places, that'd be great. In a minute I'll post a question to kick off the discussion. By the way, David, you accidentally slipped and included some new links using [this syntax](http://www.crud.com) instead of <a href = "http://www.crud.com">this one</a> No big deal... but for people reading this who are interested in writing blog articles for Azimuth, please remember that the blog uses html instead of markdown language. More details are here: * [How to write a blog entry](http://www.azimuthproject.org/azimuth/show/How+to#blog).
• Options
38.

Fantastic!

Comment Source:Fantastic!
• Options
39.

Nicely prepared, and the printout looks great.

Can you check on a formatting issue in one line of the code. It is in the section called Class PetriNet, line 23.

The full line reads like this:

def FireOneRule(this):
this.SelectRandom(this.EnabledTransitions()).Fire(this.labelling)


This is a key line of the program.

Now, in internet explorer, all the text shows up, because the line is wrapping. But for some reason, when I view it in FireFox the line cuts off without wrapping, so it reads:

def FireOneRule(this):
this.SelectRandom(this.EnabledTransitions()).Fire(this.labe


Do you get this same behavior?

I suspect that it may have to do with the fact that there is not a blank line between the methods FireOneRule and SelectRandom. All of the other methods have blanks between them, and the lines don't cut off.

Thanks!

p.s. Sorry about the links in the wrong format, I got a little too comfortable with Markdown, and also was rushing. Cheers

Comment Source:Nicely prepared, and the printout looks great. Can you check on a formatting issue in one line of the code. It is in the section called Class PetriNet, line 23. The full line reads like this: def FireOneRule(this): this.SelectRandom(this.EnabledTransitions()).Fire(this.labelling) This is a key line of the program. Now, in internet explorer, all the text shows up, because the line is wrapping. But for some reason, when I view it in FireFox the line cuts off without wrapping, so it reads: def FireOneRule(this): this.SelectRandom(this.EnabledTransitions()).Fire(this.labe Do you get this same behavior? I suspect that it may have to do with the fact that there is not a blank line between the methods FireOneRule and SelectRandom. All of the other methods have blanks between them, and the lines don't cut off. Thanks! p.s. Sorry about the links in the wrong format, I got a little too comfortable with Markdown, and also was rushing. Cheers
• Options
40.
edited October 2012

The same thing happens in chromium browser, but I think it's because there' s no space characters within the expression on that line once it starts; all the other line breaks happen at spaces in the line. Python is perfectly happy with spaces after opening ('s, so a quick fix would be to just

Fire(this


into

Fire( this


in the embedded listing.

Comment Source:The same thing happens in chromium browser, but I think it's because there' s no space characters within the expression on that line once it starts; all the other line breaks happen at spaces in the line. Python is perfectly happy with spaces after opening ('s, so a quick fix would be to just Fire(this into Fire( this in the embedded listing.
• Options
41.

I think I fixed it using David Tweed's hack - it shows up okay on my Firefox now. There's also a way to enable wrapping, but I'm really busy today...

Comment Source:I think I fixed it using David Tweed's hack - it shows up okay on my Firefox now. There's also a way to enable wrapping, but I'm really busy today...
• Options
42.

Great, that did the job, thanks. Good luck with your conference proposal and course preparations.

Comment Source:Great, that did the job, thanks. Good luck with your conference proposal and course preparations.
• Options
43.
edited October 2012

David Tanzer: I posted a long answer to your questions about my comment on your blog article here.

Thanks for your comment in which you urge other people to join the fun!

Comment Source:David Tanzer: I posted a long answer to your questions about my comment on your blog article <a href = "http://johncarlosbaez.wordpress.com/2012/10/01/petri-net-programming/#comment-20505">here</a>. Thanks for your comment in which you urge other people to join the fun!
• Options
44.
edited October 2012

Hello, Would this be of interest on the topics of choosing a programming language and applying Petri nets to manufacturing?--

I recall a Dr. Dobb's Journal cover-picture with a baby duck standing on the keyboard looking at the screen. The idea :-- just as a baby duck "imprints" the very first creature it sees into its mother, so might a programmer imprint the very first programming language he or she uses. A person's rationale for any specific programming language may be human behavior similar to "imprinting." For example, a strong belief causes a person to ignore facts and knowledge contradicting the strong belief. (Daniel Kahneman is a starting reference into that literature, of which there is far too much to say here.)

To help me remember some of the details, I wrote a paper on using the programming language Smalltalk80 to simulate manufacturing systems. Despite the much-anticipated dominance of an "imprinting" phenomenon against it, Smalltalk80 has since that day survived. The re-incarnation serving best the meaning of the attached paper is the Seaside web server written in Pharo

Offloading the Petri net onto the server by using Seaside would offload a requirement for massive computing power from the desktop to the server. While for ease of mind and reduction of pain for the programmer, in Smalltalk80 architecture-- developing a web application on Seaside is like developing a desktop application.

Unfortunately, due to the then-current "imprinting" effect of non-object-oriented code on the community, I did not expect Smalltalk80 to survive. I lost the code I'd written-- during a corporate re-shufflle involving the (at the time) highly desired Mac2 on which I had written the simulations. And then-- when it appeared that Smalltalk80 had been firmly buried 12 feet underground for some time-- I threw away the floppy disks.

Only the paper remains.

Today I can only note that -- between the approach described in my paper and the approach described so far in the Azimuth project -- there are differences perhaps of interest.

There are different ways of simulating time. I used a time queue supplied to me by the author of SimTalk. There may be different ways to simulate time.

The processes of drawing the Petri net diagram and writing the code are different.

In the Smalltalk80 system I would first draw the Petri Net diagram. The simulation would run. But then, to add some code for a transition (for example, if the transition involved different welding times for different size parts), I would right-click on the transition, and then write the code I wanted that particular transition to perform. Transitions could have very different code from each other.

And since in Smalltalk80, parallel threads are supported, a parallel instance of the transition code has the potential to be fired. In order to simulate a piece of technology such as a welding machine, I had to prevent these parallel threads of code because the actual technology could perform only one thing at a time. In order to model this, in almost every case in the diagramming tool I drew a special place for each transition that was both an input place and an output place just for that transition. Transitons drawn like this could only fire if they had already finished firing. No parallel threads were allowed for transitions drawn like this.

Further, if a transition is to be modeled, itself, as yet another Petri net, there is another difference. The triggering of such a "sub-net" in the paper would be to start with places and finish with places. That is, if a transition in the Petri net is to have its very own sub-net, then the first step in the code for that transition must be to fill in the input place for the sub-net. Automatically, as soon as that input place is filled by the code for the transition holding the sub-net, the sub-net will run.

And when the sub-net finishes, it must fill a designated output place, which signals to the code of the calling transition that the sub-net has finished running. In order to run, transitions in this simulation cannot be without an input place. A place may exist in the simulation without an upstream transition. But a transition cannot exist without an input place. In the Azimuth project, transitions are drawn that have no input place. It's another difference, perhaps of interest.

Years later I participated in a workshop at Stanford's Center for the Study of Language and Information called "the business applications of situation theory." As an industrial researcher, one of my interests when representing the company was a mathematical model of "information" that I could use in a Petri net simulation.

But instead of a stream of metal parts, I was looking for new mathematical models that I could use to model streams of information within an organzation. Keith Devlin had coined the term "infon," and Jon Barwise was then developing something he called "channel theory," which involved the category of Chu spaces. I suspected that Petri nets could be used to model information flow in organzations and ideally provide comparisons of value to, say, analysts and regulators-- for example if the capital budgeting process in one bank is closer to optimal than that of another bank.

However that depended on having a Petri net model of optimal capital budgeting which could be used to compare both organizations' against the same "golden inch" (the measurement standard held by NIST. The idea was a formal optimal model defensible through use of theorems and theorem provers). Then the bubble burst.

Could the stochastic Petri net model that's of interest in the Azimuth project also be used as a diagramming tool compatible with and extending NIST's "Process Specification Language"? (http://www.mel.nist.gov/psl/)

Comment Source:Hello, Would this be of interest on the topics of choosing a programming language and applying Petri nets to manufacturing?-- I recall a Dr. Dobb's Journal cover-picture with a baby duck standing on the keyboard looking at the screen. The idea :-- just as a baby duck "imprints" the very first creature it sees into its mother, so might a programmer imprint the very first programming language he or she uses. A person's rationale for any specific programming language may be human behavior similar to "imprinting." For example, a strong belief causes a person to ignore facts and knowledge contradicting the strong belief. (Daniel Kahneman is a starting reference into that literature, of which there is far too much to say here.) To help me remember some of the details, I wrote a paper on using the programming language Smalltalk80 to simulate manufacturing systems. Despite the much-anticipated dominance of an "imprinting" phenomenon against it, Smalltalk80 has since that day survived. The re-incarnation serving best the meaning of the attached paper is the [Seaside web server](http://www.seaside.st/) written in Pharo Offloading the Petri net onto the server by using Seaside would offload a requirement for massive computing power from the desktop to the server. While for ease of mind and reduction of pain for the programmer, in Smalltalk80 architecture-- developing a web application on Seaside is like developing a desktop application. Unfortunately, due to the then-current "imprinting" effect of non-object-oriented code on the community, I did not expect Smalltalk80 to survive. I lost the code I'd written-- during a corporate re-shufflle involving the (at the time) highly desired Mac2 on which I had written the simulations. And then-- when it appeared that Smalltalk80 had been firmly buried 12 feet underground for some time-- I threw away the floppy disks. Only [the paper](https://docs.google.com/file/d/0B9LMgeIAqlIET3B2NEE2MmxDOWM/edit) remains. Today I can only note that -- between the approach described in my paper and the approach described so far in the Azimuth project -- there are differences perhaps of interest. There are different ways of simulating time. I used a time queue supplied to me by the author of SimTalk. There may be different ways to simulate time. The processes of drawing the Petri net diagram and writing the code are different. In the Smalltalk80 system I would first draw the Petri Net diagram. The simulation would run. But then, to add some code for a transition (for example, if the transition involved different welding times for different size parts), I would right-click on the transition, and then write the code I wanted that particular transition to perform. Transitions could have very different code from each other. And since in Smalltalk80, parallel threads are supported, a parallel instance of the transition code has the potential to be fired. In order to simulate a piece of technology such as a welding machine, I had to prevent these parallel threads of code because the actual technology could perform only one thing at a time. In order to model this, in almost every case in the diagramming tool I drew a special place for each transition that was both an input place and an output place just for that transition. Transitons drawn like this could only fire if they had already finished firing. No parallel threads were allowed for transitions drawn like this. Further, if a transition is to be modeled, itself, as yet another Petri net, there is another difference. The triggering of such a "sub-net" in the paper would be to start with places and finish with places. That is, if a transition in the Petri net is to have its very own sub-net, then the first step in the code for that transition must be to fill in the input place for the sub-net. Automatically, as soon as that input place is filled by the code for the transition holding the sub-net, the sub-net will run. And when the sub-net finishes, it must fill a designated output place, which signals to the code of the calling transition that the sub-net has finished running. In order to run, transitions in this simulation cannot be without an input place. A place may exist in the simulation without an upstream transition. But a transition cannot exist without an input place. In the Azimuth project, transitions are drawn that have no input place. It's another difference, perhaps of interest. Years later I participated in a workshop at Stanford's Center for the Study of Language and Information called "the business applications of situation theory." As an industrial researcher, one of my interests when representing the company was a mathematical model of "information" that I could use in a Petri net simulation. But instead of a stream of metal parts, I was looking for new mathematical models that I could use to model streams of information within an organzation. Keith Devlin had coined the term "infon," and Jon Barwise was then developing something he called "channel theory," which involved the category of Chu spaces. I suspected that Petri nets could be used to model information flow in organzations and ideally provide comparisons of value to, say, analysts and regulators-- for example if the capital budgeting process in one bank is closer to optimal than that of another bank. However that depended on having a Petri net model of optimal capital budgeting which could be used to compare both organizations' against the same "golden inch" (the measurement standard held by NIST. The idea was a formal optimal model defensible through use of theorems and theorem provers). Then the bubble burst. Could the stochastic Petri net model that's of interest in the Azimuth project also be used as a diagramming tool compatible with and extending NIST's "Process Specification Language"? (http://www.mel.nist.gov/psl/)
• Options
45.

If Allan Erskine or anyone else could point to it on Hacker News or similar places

Sorry for being less-than-engaged here! In a bit of a busy period (lifewise). Did anyone do this? It was an awesome article! Looking forwards to poking through the code when I get a chance. On the subject of language "wars" and Python, this recent talk I noticed on hackernews was a fun read:

https://speakerd.s3.amazonaws.com/presentations/506e9e694f4e120002045eca/didntknow.pdf

Comment Source:> If Allan Erskine or anyone else could point to it on Hacker News or similar places Sorry for being less-than-engaged here! In a bit of a busy period (lifewise). Did anyone do this? It was an awesome article! Looking forwards to poking through the code when I get a chance. On the subject of language "wars" and Python, this recent talk I noticed on hackernews was a fun read: https://speakerd.s3.amazonaws.com/presentations/506e9e694f4e120002045eca/didntknow.pdf
• Options
46.

Allan, thanks for the good word.

I just posted to FreeCode (formerly Freshmeat). It should qualify, since I gave it a GPL licence. Here is the blurb I gave:

Petri nets are well-known formalism for concurrency, with a wide range of applications including chemical reaction networks, predator-prey networks, and manufacturing processes. This code is presented as part of a blog article that introduces Petri nets from the ground up, and then proceeds to give a "literate programming" exposition of a simulator for Petri nets, which is implemented in a couple of pages of Python logic. It is applied to a highly simplistic model of a chemical reaction network that involves two transitions: synthesis of water molecules from hydrogen and oxygen, and dissociation of water molecules into hydrogen and oxygen. The blog is for the Azimuth Project, which is an open volunteer group of scientists, engineers and programmers who are working to understand the computational, scientific and mathematical challenges that are raised by the environmental crisis.

I gave links to the article, the code, and the Azimuth page.

It is pending review, which they say takes under 24 hours.

Allan, if nobody else covered it, can you post to HackerWorld, I'm not familiar with that context.

Thanks.

Comment Source:Allan, thanks for the good word. I just posted to FreeCode (formerly Freshmeat). It should qualify, since I gave it a GPL licence. Here is the blurb I gave: > Petri nets are well-known formalism for concurrency, with a wide range of applications including chemical reaction networks, predator-prey networks, and manufacturing processes. This code is presented as part of a blog article that introduces Petri nets from the ground up, and then proceeds to give a "literate programming" exposition of a simulator for Petri nets, which is implemented in a couple of pages of Python logic. It is applied to a highly simplistic model of a chemical reaction network that involves two transitions: synthesis of water molecules from hydrogen and oxygen, and dissociation of water molecules into hydrogen and oxygen. The blog is for the Azimuth Project, which is an open volunteer group of scientists, engineers and programmers who are working to understand the computational, scientific and mathematical challenges that are raised by the environmental crisis. I gave links to the article, the code, and the Azimuth page. It is pending review, which they say takes under 24 hours. Allan, if nobody else covered it, can you post to HackerWorld, I'm not familiar with that context. Thanks.
• Options
47.

Well I tried. Here's the reply:

Freecode avoids announcing apps that are only written to demonstrate a concept; we announce downloadable software utilities that people can use. Your contribution has been respectfully declined.

Comment Source:Well I tried. Here's the reply: > Freecode avoids announcing apps that are only written to demonstrate a concept; we announce downloadable software utilities that people can use. Your contribution has been respectfully declined.
• Options
48.

...which is understandable. But it suggests if anyone here gets to the point of a having a downloadable utility, the code could help us to get on the radar with the Linux folks. Here is their summary:

Freecode maintains the Web's largest index of Linux, Unix and cross-platform software, and mobile applications. Thousands of applications, which are preferably released under an open source license, are meticulously cataloged in the Freecode database, and links to new applications are added daily. Each entry provides a description of the software, links to download it and to obtain more information, and a history of the project's releases, so readers can keep up-to-date on the latest developments.

I'm wondering if we could put together a good storyline for a slashdot article. Something about the Azimuth project itself, combined with development of free software. To it's more interesting than many the posts there. We'd have about 100 words to work with.

Here are the submission guidelines.

Here's a first crack at it:

The Azimuth Project is an open volunteer group of scientists, engineers and programmers who are working to understand the computational, scientific and mathematical challenges that are raised by the environmental crisis. In particular we are working on climate models and their theoretical underpinnings, and are seeking to develop free software to implement them. [Then announce some latest breaking news, like: hot off the press, climate model simulator runs in your browser. And new ideas being contributed back from from quantum mechanics to stochastic mechanics, as per a new book on the arXiv by Baez and Biamonte.]

Call for second drafts...

Comment Source:...which is understandable. But it suggests if anyone here gets to the point of a having a downloadable utility, the code could help us to get on the radar with the Linux folks. Here is their summary: > Freecode maintains the Web's largest index of Linux, Unix and cross-platform software, and mobile applications. Thousands of applications, which are preferably released under an open source license, are meticulously cataloged in the Freecode database, and links to new applications are added daily. Each entry provides a description of the software, links to download it and to obtain more information, and a history of the project's releases, so readers can keep up-to-date on the latest developments. I'm wondering if we could put together a good storyline for a slashdot article. Something about the Azimuth project itself, combined with development of free software. To it's more interesting than many the posts there. We'd have about 100 words to work with. Here are the [submission guidelines](http://slashdot.org/faq/submissions.shtml). Here's a first crack at it: The Azimuth Project is an open volunteer group of scientists, engineers and programmers who are working to understand the computational, scientific and mathematical challenges that are raised by the environmental crisis. In particular we are working on climate models and their theoretical underpinnings, and are seeking to develop free software to implement them. [Then announce some latest breaking news, like: hot off the press, climate model simulator runs in your browser. And new ideas being contributed back from from quantum mechanics to stochastic mechanics, as per a new book on the arXiv by Baez and Biamonte.] Call for second drafts...
• Options
49.

I just posted to FreeCode (formerly Freshmeat).

OK -- I just emerged from my slumber to post to hackernews. It will only become prominent if people either discuss or upvote the article.

Comment Source:> I just posted to FreeCode (formerly Freshmeat). OK -- I just emerged from my slumber to post to [hackernews](http://news.ycombinator.com/newest). It will only become prominent if people either [discuss](http://news.ycombinator.com/item?id=4647623) or [upvote](http://news.ycombinator.com/vote?for=4647623&dir=up) the article.
• Options
50.

I just emerged from my slumber to post to hackernews.

eventually it could make sense to rename "Petri net programming (part 1)" into "Dark Petri Net Programming (part I)" in order to get a higher rank on hackernews.

Comment Source:>I just emerged from my slumber to post to hackernews. eventually it could make sense to rename "Petri net programming (part 1)" into "Dark Petri Net Programming (part I)" in order to get a higher rank on hackernews.
Sign In or Register to comment.