From theory to practice: Standard tools Software carpentry, Part II. Pietro Berkes, Brandeis University

Similar documents
Agile development. Agile development work cycle. Reacting to bugs

Software carpentry From theory to practice: Standard tools. Pietro Berkes, Enthought UK

Software Carpentry. Nicola Chiapolini. Physik-Institut University of Zurich. June 16, 2015

Software carpentry From theory to practice: Python tools. Pietro Berkes, Enthought UK

Version control CSE 403

Version control CSE 403

Revision control systems (RCS) and. Subversion

Version control CSE 403

2/9/2013 LAB OUTLINE INTRODUCTION TO VCS WHY VERSION CONTROL SYSTEM(VCS)? II SENG 371 SOFTWARE EVOLUTION VERSION CONTROL SYSTEMS

Revision Control. Software Engineering SS 2007

CSC 2700: Scientific Computing

What is Subversion and what does it do?

Branches in Subversion, Debugging, scmbug

AMath 483/583 Lecture 2

A Short Introduction to Subversion

Subversion Repository Layout

AMath 483/583 Lecture 2. Notes: Notes: Homework #1. Class Virtual Machine. Notes: Outline:

12/7/09. How is a programming language processed? Picasso Design. Collaborating with Subversion Discussion of Preparation Analyses.

Source Control. Comp-206 : Introduction to Software Systems Lecture 21. Alexandre Denault Computer Science McGill University Fall 2006

CS 320 Introduction to Software Engineering Spring February 06, 2017

Review Version Control Concepts

Version Control Systems (VCS)

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Subversion (and Git) Winter 2019

Tools to efficiently build scientific code Mostly testing, some profiling, a little debugging. Pietro Berkes, Twitter #aspp2016

Introduction to Revision Control

2/8/18. Overview. Project Management. The First Law. What is Project Management? What Are These Changes? Software Configuration Management (SCM)

Common Configuration Management Tasks: How to Do Them with Subversion

Project Management. Overview

Department of Computer Science College of Engineering Boise State University

Source control with Subversion A user perspective

Section 2: Developer tools and you. Alex Mariakakis (staff-wide)

CSE 374 Programming Concepts & Tools. Hal Perkins Winter 2012 Lecture 16 Version control and svn

Software Development I

Software Tools Subversion

VSO. Configuration Management

Introduction to distributed version control with git

SECTION 1: CODE REASONING + VERSION CONTROL + ECLIPSE

Using Git to Manage Source RTL

Source Code Management

Introduction to version control. David Rey DREAM

Version Control. CSC207 Fall 2014

Subversion. CS 490MT/5555, Fall 2015, Yongjie Zheng

Manage quality processes with Bugzilla

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Version Control Systems

Version Control Systems (Part 1)

Revision control. INF5750/ Lecture 2 (Part I)

CVS. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 21

SVN_Eclipse_at_home. 1. Download Eclipse. a. Go to: and select Eclipse IDE for Java Developers

Revision Control II. - svn

Push up your code next generation version control with (E)Git

Practical Unit Testing junit. Atul Prakash

CS480. Compilers Eclipse, SVN, Makefile examples

Basic git. Interactive.

CS108, Stanford Handout #37. Source Control CVS

An Introduction to Subversion

Development tools: Version control, build tools, and integrated development environments 1

Version Control System. -- base on Subversion 1.4

Git for Subversion users

TDDC88 Lab 4 Software Configuration Management

Version Control Systems

Revision Control. How can 4. Slides #4 CMPT 276 Dr. B. Fraser. Local Topology Simplified. Git Basics. Revision Control:

Version Control Systems: Overview

Git tutorial. Katie Osterried C2SM. October 22, 2015

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

Chapter 3. Revision Control

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

Workshop: High-performance computing for economists

A BASIC UNDERSTANDING OF VERSION CONTROL

Submitting your Work using GIT

... Fisheye Crucible Bamboo

Ingegneria del Software Corso di Laurea in Informatica per il Management (D)VCS. Davide Rossi Dipartimento di Informatica Università di Bologna

Using Subversion with LeMANS and MONACO

Bazaar VCS. Concepts and Workflows

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 11, 2017

Introduction to Version Control

[Software Development] Development Tools. Davide Balzarotti. Eurecom Sophia Antipolis, France

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

Laboratorio di Programmazione. Prof. Marco Bertini

Working in Teams CS 520 Theory and Practice of Software Engineering Fall 2018

SECTION 2: HW3 Setup.

Introduction to Version Control using Git

Tools for software development:

6 Git & Modularization

Apache Subversion Tutorial

Distributed Version Control

Warmup. A programmer s wife tells him, Would you mind going to the store and picking up a loaf of bread? Also, if they have eggs, get a dozen.

Version control. Michael Tsai 2012/4/10

Essentials of Embedded Software Engineering

Software Systems Design. Version control systems and documentation

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

Part I Part 1 Version Control Systems (VCSs)

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

CS314 Software Engineering Configuration Management

Part I Part 1 Version Control Systems (VCSs)

CSE 390 Lecture 9. Version control and Subversion (svn)

Version Control Systems

Managing your code: version control

Programming for Data Science Syllabus

I m an egotistical bastard, and I name all my projects after myself. First Linux, now git. Linus Torvalds, creator of Linux and Git

Transcription:

From theory to practice: Standard tools Software carpentry, Part II Pietro Berkes, Brandeis University

Outline Collaborating: SVN Profiling: timeit, cprofile Debugging: pdb Documentation, code clarity: pydoc, pylint 2 Software carpentry - Part II

Python tools for agile programming I ll present: Python standard batteries included tools no graphical interface necessary magic commands for ipython Many tools, based on command line or graphical interface Alternatives and cheat sheets are on the Wiki 3 Software carpentry - Part II

Version Control Systems Central repository of files and directories on a server The repository keeps track of changes in the files Manipulate versions (compare, revert, merge, ) Revision 109 Local copy Central repository... Revision 107 Revision 108 Revision 109 4 Software carpentry - Part II

VCS for the lone scientist Store source code, data, papers, and presentations about a project Backup Reversible changes Multiple synchronized copies of your project: now you can work from home, too! Home Work 5 Software carpentry - Part II

VCS for a team of scientists Multiple people working at the same time on the same project (software libraries, papers) Handle simultaneous changes to the same files and merge them or handle conflicts Look at recent changes, who is responsible for newest versions, and much more Tiziano Niko Pietro 6 Software carpentry - Part II

Subversion (SVN) Create a new repository svnadmin create PATH requires security decisions about access to repository, have a look at the SVN book Get a local copy of a repository svn co URL [PATH] Checkout a copy of the course SVN repository svn co https://portal.bccn-berlin.de/svn/python-summerschool/public 7 Software carpentry - Part II

Basic SVN cycle Update your working copy Make changes svn update svn add svn delete svn copy svn move Examine your changes svn status svn revert svn diff Merge others changes svn update resolve conflicts then svn resolved Commit your changes svn commit m meaningful message 8 Software carpentry - Part II

DEMO 9 Software carpentry - Part II

SVN notes SVN cannot merge binary files => don t commit large binary files that change often (e.g., results files) At each milestone, commit the whole project with a clear message marking the event svn commit m submission to Nature There s more to it: Branches, tags, repository administration Graphical interfaces: subclipse for Eclipse, Distributed VCS: Mercurial, git, Bazaar 10 Software carpentry - Part II

Test Suites in python: unittest Automated tests are a fundamental part of modern programming practices unittest: standard Python testing library 11 Software carpentry - Part II

Anatomy of a TestCase import unittest class FirstTestCase(unittest.TestCase): def testtruisms(self): """All methods beginning with test are executed""" self.asserttrue(true) self.assertfalse(false) def testequality(self): """Docstrings are printed during executions of the tests in the Eclipse IDE""" self.assertequal(1, 1) if name == ' main ': unittest.main() 12 Software carpentry - Part II

TestCase.assertSomething asserttrue('hi'.islower()) assertfalse('hi'.islower()) assertequal([2, 3], [2, 3]) assertalmostequal(1.125, 1.12, 2) assertalmostequal(1.125, 1.12, 3) => fail => pass => pass => pass => fail assertraises(exceptions.ioerror, file, 'inexistent', 'r') => pass asserttrue('hi'.islower(), 'One of the letters is not lowercase') 13 Software carpentry - Part II

Multiple TestCases import unittest class FirstTestCase(unittest.TestCase): def testtruisms(self): self.asserttrue(true) self.assertfalse(false) class SecondTestCase(unittest.TestCase): def testapproximation(self): self.assertalmostequal(1.1, 1.15, 1) if name == ' main ': # execute all TestCases in the module unittest.main() 14 Software carpentry - Part II

setup and teardown import unittest class FirstTestCase(unittest.TestCase): def setup(self): """setup is called before every test""" pass def teardown(self): """teardown is called at the end of every test""" pass #... all tests here... if name == ' main ': unittest.main() 15 Software carpentry - Part II

DEMO 16 Software carpentry - Part II

Python code optimization Python is slower than C, but not prohibitively so In scientific applications, this difference is even less noticeable (numpy, scipy,...) for basic tasks, as fast as Matlab, sometimes faster as Matlab, it can easily be extended with C or Fortran code Profiler = Tool that measures where the code spends time 17 Software carpentry - Part II

timeit precise timing of a function/expression test different versions of a small amount of code, often used in interactive Python shell from timeit import Timer # execute 1 million times, return elapsed time(sec) Timer("module.function(arg1, arg2)", "import module").timeit() # more detailed control of timing t = Timer("module.function(arg1, arg2)", "import module") # make three measurements of timing, repeat 2 million times t.repeat(3, 2000000) in ipython, you can use the %timeit magic command 18 Software carpentry - Part II

DEMO 19 Software carpentry - Part II

cprofile standard Python module to profile an entire application (profile is an old, slow profiling module) Running the profiler from command line: python -m cprofile myscript.py options -o output_file -s sort_mode (calls, cumulative, name, ) from interactive shell/code: import cprofile cprofile.run(expression[,"filename.profile"]) 20 Software carpentry - Part II

cprofile, analyzing profiling results From interactive shell/code: import pstat p = pstat.stats("filename.profile") p.sort_stats(sort_order) p.print_stats() Simple graphical description with RunSnakeRun 21 Software carpentry - Part II

DEMO 22 Software carpentry - Part II

cprofile, analyzing profiling results Look for a small number of functions that consume most of the time, those are the only parts that you should optimize High number of calls per functions => bad algorithm? High time per call => consider caching High times, but valid => consider using libraries like numpy or rewriting in C 23 Software carpentry - Part II

Debugging The best way to debug is to avoid it Your test cases should already exclude a big portion of the possible causes Don t start littering your code with print statements Core idea in debugging: you can stop the execution of your application at the bug, look at the state of the variables, and execute the code step by step 24 Software carpentry - Part II

pdb, the Python debugger Command-line based debugger pdb opens an interactive shell, in which one can interact with the code examine and change value of variables execute code line by line set up breakpoints examine calls stack 25 Software carpentry - Part II

Entering the debugger Enter at the start of a program, from command line: python m pdb mycode.py Enter in a statement or function: import pdb # your code here if name == ' main ': pdb.runcall(function[, argument,...]) pdb.run(expression) Enter at a specific point in the code: import pdb # some code here # the debugger starts here pdb.set_trace() # rest of the code 26 Software carpentry - Part II

DEMO 27 Software carpentry - Part II

Entering the debugger From ipython: %pdb - preventive %debug post-mortem 28 Software carpentry - Part II

Two more useful tools pydoc: creating documentation from your docstrings pydoc [-w] module_name pylint: check that your code respects standards 29 Software carpentry - Part II

DEMO 30 Software carpentry - Part II

The End Exercises after the tea break... 31 Software carpentry - Part II

32 Software carpentry - Part II

TestCase.assertSomething TestCase methods assert_(expr[, msg) asserttrue(expr[, msg]) assertfalse(expr[, msg]) assertequal(first, second[, msg]) assertnotequal(first, second[, msg]) Examples asserttrue(isinstance([1,2], list) => pass asserttrue('hi'.islower()) => fail assertequal([2, 3], [2, 3]) => pass assertequal(1.2, 1.3) => fail assertalmostequal(first, second [, places[, msg]]) assertnotalmostequal(first, second [, places[, msg]]) assertraises(exception, callable,...) fail([msg]) assertalmostequal(1.125, 1.12, 2) => pass assertalmostequal(1.125, 1.12, 3) => fail assertraises(exceptions.ioerror, file, 'inexistent', 'r') => pass assertraises(exceptions.syntaxerror, file, 'inexistent', 'r ) => fail fail() => fail 33 Software carpentry - Part II