dexy for scientific computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · dexy open...
TRANSCRIPT
![Page 1: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/1.jpg)
Dexy for Scientific Computing
Ana Nelson
dexy.it
July 14, 2011
![Page 2: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/2.jpg)
For all source code check out: http://bit.ly/ruN6yx
This document’s source: http://bit.ly/n82NGO
![Page 3: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/3.jpg)
Writing About Code
• Software Documentation
• Computational Workflows
• Dependency Management• File Provenance
• Reproducible Research
• Total Automation
![Page 4: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/4.jpg)
Writing About Code
• Software Documentation
• Computational Workflows
• Dependency Management• File Provenance
• Reproducible Research
• Total Automation
![Page 5: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/5.jpg)
Writing About Code
• Software Documentation
• Computational Workflows
• Dependency Management• File Provenance
• Reproducible Research
• Total Automation
![Page 6: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/6.jpg)
The Big Idea
No Dead Code
• Any code you show comes from a live, runnable file.
• Any images or output you show comes from running live code.
![Page 7: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/7.jpg)
Tool for the job
Dexy
• Open Source (mostly MIT, some AGPL)
• Written in Python
• Command Line, Text Based
• * Agnostic
• My Day Job and my Mission in Life
![Page 8: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/8.jpg)
Demo
• Simulation in Python (GarlicSim)
• Data Analysis in R
![Page 9: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/9.jpg)
Demo
from garlicsim_lib.simpacks import prisoner
import csv
import garlicsim
import json
NUMBER_OF_PLAYERS = 100
NUMBER_OF_STEPS = 500
![Page 10: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/10.jpg)
Demo
csv_filename = " dexy--sim-output.csv "
csv_file = open(csv_filename, " w " )
data_writer = csv.writer(csv_file)
data_writer.writerow([ " step " , " agent " , " points " , " strategy " ])
![Page 11: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/11.jpg)
Demo
state = prisoner.State.create_messy_root(NUMBER_OF_PLAYERS)
i = -1
![Page 12: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/12.jpg)
Demo
def collect_data():
for j, agent in enumerate(state.players):
strategy = agent.__class__.__name__
data_writer.writerow([i, j, agent.points, strategy])
![Page 13: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/13.jpg)
Demo
collect_data()
for i in range(NUMBER_OF_STEPS):
state = garlicsim.simulate(state)
collect_data()
![Page 14: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/14.jpg)
Demo
csv_file.close()
json_filename = " dexy--sim-params.json "
json_file = open(json_filename, " w " )
json.dump({
’ number_of_players ’ : NUMBER_OF_PLAYERS,
’ number_of_steps ’ : NUMBER_OF_STEPS
}, json_file)
json_file.close()
![Page 15: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/15.jpg)
Demo
> library(rjson)
![Page 16: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/16.jpg)
Demo
> data = read.csv( " 095ac033-eda6-4a5d-ac65-f1ddddfee1cb.csv" , sep= " ," )
> strategy.counts <- table(list(strategy=data$strategy, step=data$step))
> last.period = subset(data, data$step==max(data$step))
![Page 17: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/17.jpg)
Demo
> pdf(file= " 9b3b9647-917e-4dc7-9ec3-e844005fac75.pdf" , width=10, height=6)
> barplot(
+ strategy.counts,
+ legend.text = TRUE,
+ border=NA,
+ args.legend = pairlist(bty= ’ n’ ),
+ col=terrain.colors(3)
+ )
> dev.off()
null device
1
![Page 18: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/18.jpg)
Demo
−1 20 41 62 83 106 132 158 184 210 236 262 288 314 340 366 392 418 444 470 496
TitForTatDevilAngel
020
4060
8010
0
![Page 19: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/19.jpg)
Demo
> pdf(file= " cce2816d-01ac-432e-ab94-593e694c2071.pdf" , width=10, height=6)
> hist(last.period$points, main= " " ,
+ ylab= " Number of Agents" ,
+ xlab= " Final Score" ,
+ col= " purple"
+ )
> dev.off()
null device
1
![Page 20: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/20.jpg)
Demo
Final Score
Num
ber
of A
gent
s
−150 −100 −50 0 50 100 150 200
05
1015
2025
30
![Page 21: Dexy for Scientific Computingconference.scipy.org/scipy2011/slides/nelson_dexy.pdf · Dexy Open Source (mostly MIT, some AGPL) Written in Python Command Line, Text Based * Agnostic](https://reader036.vdocuments.mx/reader036/viewer/2022081402/5f19239cdb4c442f7438b1bc/html5/thumbnails/21.jpg)
Demo
> sim.results <- list( max_points_in_last_period = max(last.period$points))
> sim.results
$max_points_in_last_period
[1] 155
>
> json.filename = " 1d45a798-0e29-4cc8-afde-5c9927dcfe35.json"
> write(toJSON(sim.results), json.filename)
The maximum number of points in the last period was 155.