Software EwngiEneeriEng E Practces Efor...

36
Soſtware wngneerng Practces for Python

Transcript of Software EwngiEneeriEng E Practces Efor...

Page 1: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Software EwngiEneeriEng EPractces Efor EPython

Page 2: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

CodiEng EwxperiEences

● Good Edevelopment Epractces Ehelp EwiEth Ethe EfollowiEng EsiEtuatonss

– You swear that the code worked perfectly 6 months ago, Ebut Etoday EiEt Edoesn't, Eand Eyou Ecan't Efgure Eout Ewhat Echanged

– Your research group is all working on the same code, Eand Eyou Eneed Eto Esync Eup EwiEth Eeveryone's Echanges, Eand Emake Esure Eno Eone Ebreaks Ethe Ecode

– Your code always worked fne on machine X, Ebut Enow Eyou EswiEtch Eto Ea Enew Esystem/archiEtecture, Eand Eyou Ecode EgiEves Eerrors, Ecrashes, E...

– Your code tes together lots of codes Elegacy Ecode Efrom Eyour EadviEsor's EadviEsor, Enew Estuf Eyou Ewrote, Eall Eted Etogether Eby Ea EdriEver. E EThe Ecode EiEs EgiEviEng Efunny EbehaviEor Esometme—how Edo Eyou Ego Eabout EdebuggiEng Esuch Ea Ebeast?

Page 3: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Software EwngiEneeriEng EPractces

● We'll Elook Eat Esome EbasiEc Epython Estyle EguiEdeliEnes Eand Esome Etools Ethat Ehelp EwiEth Ethe Edevelopment Eprocess

– Also Ehelps EreproduciEbiEliEty Eof Eyour EsciEence Eresults

– You Ecan Egoogle Earound Efor EspeciEfc EdetaiEls, Emore EiEn-depth EtutoriEals, Eetc.

Page 4: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Software EwngiEneeriEng EPractces

● Some EbasiEc Epractces Ethat Ecan Egreatly enhance Eyour EabiEliEty Eto EwriEte EmaiEntaiEnable Ecode

– VersiEon Econtrol

– Documentaton

– Testng Eprocedures

– For EcompiEled Elanguages, EI Ewould Eadd EMakefles, Eproflers, Ecode EanalysiEs Etools E(liEke EvalgriEnd)

● Already EdiEscusseds EPwP E8 E(codiEng Estandards)

– Helps Eyou EiEnteract EwiEth Ea EdiEstriEbuted Egroup Eof Edevelopers—everyone EwriEtes Ecode EwiEth Ethe Esame Econventon

Page 5: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Python EStyle

● The Erecommended Epython Estyle EiEs EdescriEbed EiEn Ea E“Python Ewnhancement EProposal”, EPwP-8

– htps//legacy.python.org/dev/peps/pep-sss8/

– Based Eon Ethe EiEdea Ethat E“code is read much more ofen than it is writen”

● Some EhiEghliEghtss

– Indentaton Eshould Euse E4 Espaces E(no Etabs)

– LiEnes Eshould Ebe Eless Ethan E79 Echaracters

● Contnuaton EviEa E'\' Eor E()

– Classes Eshould Ebe EcapiEtaliEzed Eof Eform EMyClass

– Functon Enames, Eobjects, EvariEables, Eshould Ebe Elower Ecase, EwiEth E_ Eseparatng Ewords EiEn Ethe Ename

– Constants EiEn EALL_CAPS

Page 6: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

CodiEng EStyle

● Don't Emake Eassumptons

– For Eif Eclauses, Ehave Ea Edefault Eblock E(else) Eto Ecatch EcondiEtons EoutsiEde Eof Ewhat Eyou Emay Ehave Eexpected

– Use Etry/except Eto Ecatch Eerrors● Use Efunctons/subroutnes Efor Erepettve Etasks

– Check Ereturn Evalues Efor Eerrors

– Use Ewell-tested EliEbrariEes EiEnstead Eof ErolliEng Eyour Eown Ewhen EpossiEble

Page 7: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

VersiEon EControl

● Old Edayss Ecreate Ea Etar Efle EwiEth Ethe Ecurrent Esource, EmaiEl EiEt Earound, Emanually Emerge EdiEferent Epeople's Echanges...

● VersiEon Econtrol Esystems Ekeep Etrack Eof Ethe EhiEstory Eof Echanges Eto Esource Ecode

– Logs EdescriEbe Ethe Echanges Eto Eeach Efle Eover Etme

– Allow Eyou Eto Erequest Ethe Esource Eas EiEt Ewas Eat Eany Etme EiEn Ethe Epast

– Multple Edevelopers Ecan Eshare Eand EsynchroniEze Echanges

● Merges Echanges Eby EdiEferent Edevelopers Eto Ethe Esame Efle● ProviEde EmechaniEsms Eto Eresolve EconfiEctng Echanges Eto Efles

– ProviEde EmechaniEsms Eto Ecreate Ea Ebranch Eto Edevelop Enew Efeatures Eand Ethen Emerge EiEt Eback EiEnto Ethe EmaiEn Esource.

Page 8: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

VersiEon EControl

● wven Efor Ea EsiEngle Edeveloper EversiEon Econtrol EiEs Ea Egreat Easset

– Common Etasks Eyou Enotce Ethat Eyour Ecode EiEs EgiEviEng EdiEferent Eanswers/behaviEor Ethan Eyou've Eseen EiEn Ethe Epast

● Check Eout Ean Eold Ecopy Ewhere Eyou Eknow EiEt Ewas EworkiEng● BiEsect Ethe EhiEstory Ebetween Ethe EworkiEng Eand Ebroken Edates Eto EpiEn Edown Ethe Echange

● Can Ealso Euse EiEt Efor Epapers Eand Eproposals—all Ethe Eauthors Ecan Ework Eon Ethe Esame ELaTeX Esource Eand Eshare Echages

● All Eof Ethese EsliEdes Eare Estored EiEn EversiEon Econtrol—let's Eme Ework Eon Ethem Efrom Eanywhere EeasiEly

– Fun EtriEcks ELiEbreOfce Efles Eare EziEpped EXML, Ebut Eyou Ecan Ehave EiEt Estore Ethe Eoutput Eas Euncompressed E“fat” EXML Efles E(.fodp EiEnstead Eof E.odp)

Page 9: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

CentraliEzed Evs. EDiEstriEbuted EVersiEon EControl

● CentraliEzed E(e.g. ECVS, EsubversiEon)

– Server Eholds Ethe Emaster Ecopy Eof Ethe Esource, Estores EhiEstory, Echanges

– User EcommuniEcates EwiEth Eserver

● Checkout Esource

● CommiEt Echanges Eback Eto Ethe Esource

● Request Ethe Elog E(hiEstory) Eof Ea Efle Efrom Ethe Eserver

● DiEf Eyour Elocal EversiEon EwiEth Ethe EversiEon EiEn Ethe Eserver

– Doesn't Escale Ewell Efor Every Elarge Eprojects

– “Older” Estyle Eof EversiEon Econtrol

● DiEstriEbuted E(e.g. EgiEt, EmercuriEal)

– wveryone Ehas Ea Efull-fedged EreposiEtory

– You Eclone Eanother Eperson's Erepo

– CommiEts, EhiEstory, EdiEf, Elogs Eare Eall Elocal Eoperatons E(these Eoperatons Eare Efaster)

– You Epush Eyour Echanges Eback Eto Eothers.

– wach Ecopy EiEs Ea Ebackup Eof Ethe Ewhole EhiEstory Eof Ethe Eproject

– wasiEer Eto Efork—just Eclone Eand Ego

Any version control system is beter than none!

Page 10: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

DiEstriEbuted EVersiEon EControl

WorkiEng Ecopy

Add, EcommiEt

checkout,log

group Eserveror EgiEthub

push

pull

group Emember

WorkiEng Ecopy

Add, EcommiEt

checkout,log

pull

push

external Ecollaborator

WorkiEng Ecopy

Add, EcommiEt

checkout,log

pull

pull

Page 11: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

DiEstriEbuted EVersiEon EControl

● In Ean EiEdeal Eworld, Epeople Eonly Epull Efrom Eothers, Enever Epush.

– See, Ee.g. Ehtps//biE:lop.com/document/111 E

● GiEthub/biEtbucket EproviEde Ea EcentraliEzed Erepo EbuiElt Earound Epull requests

Page 12: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

VersiEon EControl

● Note Ethat EwiEth EgiEt, Eevery Echange Egenerates Ea Enew E“hash” Ethat EiEdentfes Ethe Eentre Ecollecton Eof Esource.

– You Ecannot Eupdate Ejust Ea EsiEngle Esub-diErectory—iEt's Eall Eor EnothiEng. E E

● Branches EiEn Ea Erepo Eallow Eyou Eto Ework Eon Echanges EiEn Ea Eseparate Eare Efrom Ethe EmaiEn Esource. E E

– You Ecan Eperfect Ethem, Ethen Emerge Eback Eto Ethe EmaiEn Ebranch, Eand Ethen Epush Eback Eto Ethe Eremote.

● LOTS Eof Eresources Eon Ethe Eweb.

● Best Eway Eto Elearn EiEs Eto Epractce.

● There EiEs Emore Ethan Eone Eway Eto Edo Emost EthiEngs

● Free E(for Eopen Esource), EonliEne, Eweb-based Ehostng EsiEtes EexiEst E(e.g. EGiEthub, EBiEtBucket, E...)

Page 13: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

GiEt

(xkcd)

Page 14: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Some EgiEt Ewxamples

● We Ecan EiEmagiEne Ea Emany EdiEferent Eworkfows, EliEkes

– SiEngle Euser EiEnteractng EwiEth Ea EgiEt Erepo Eon Ea EsiEngle EmachiEne

● ThiEs Ecan Ebe, Efor Eexample, Ea Ecode Ethat Eonly Eyou Edevelop● You Ewant Eto Etake Eadvantage Eof EloggiEng/hiEstory Eas Ewell Eas EbranchiEng

– Research Egroup EdevelopiEng Ea EsiEngle Ecode Ebase, EwiEth EcentraliEzed Eserver

● wach Eof Eyou Ehas Ea Eclone Eof Ethe Egroup’s Erepo Eand Epush Eto/pull Efrom Ethe EcentraliEzed Eserver Eto Eshare Ework

– Research Egroup EusiEng EgiEthub Eto EcentraliEze Ethe Edevelopment

● ThiEs EiEs EliEke Ethe EpreviEous Eexample, Ebut EgiEthub Eflls EiEn Efor Ethe Egroup’s Eserver● BuiElt Earound Ethe EiEdea Eof Epull Erequests

● We’ll Elook Eat Ethe Efrst Eand Elast Eof Ethese Enow

Page 15: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

QuiEck EgiEt Ewxample EI

● WorkiEng EwiEth Eyour Eown EreposiEtory

– Here’s Ea EscriEpt Eto Efollow Ealong EwiEths Ehtpss//giEthub.com/sbu-python-class/python-sciEence/blob/master/lectures/s3-practces/giEt-siEngle.md E

– We’ll Elook Eat Ethe Ecommandss● git init● git add● git commit● git log● git checkout● git merge

Page 16: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

CommuniEty

● GiEthub E/ EbiEtbucket EproviEde Etools Eto Eengage EwiEth Eyour EcommuniEty

● Issue EtrackiEng

● Pull Erequests

(xkcd)

Page 17: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

GiEthub Eexample

● Don't Ewant Eto Euse Eyour Eown Eserver, Euse EgiEthub Eor EbiEtbucket

– Free Efor EpubliEc E(open Esource) Eprojects

– Pay Efor EpriEvate Eprojects

● Create Ea EgiEthub Eaccount E(free)

● These Eclass Enotes Eare Eon EgiEthubs

– git clone https://github.com/sbu-python-class/python-science

● GiEthub EiEs Egreat Efor EmanagiEng Ea EcommuniEty Eof Edevelopers EoutsiEde Eyour EorganiEzaton

– You Edon’t Ehave Eto EgiEve Eeveryone EwriEte EpermiEssiEon

– Normal EiEnteracton EiEs Ethrough Epull request Eand Eissues

Page 18: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

GiEthub Eexample

● Our Eclass Etest Erepos Ehtpss//giEthub.com/sbu-python-class/test-repo-2-s18 E E

– Fork Ethe Eproject EiEnto Eyour Eown Eaccount

– Use EgiEt Eto Eclone Eyour Efork Eand EiEnteract EwiEth EiEt—you own it, so you can push changes back to your fork

– Issue Ea Epull-request Eto Ethe EmaiEn E(upstream) Eproject EaskiEng Efor Eyour Echanges Eto Ebe EiEncorporated

– Feel Efree Eto Etry EthiEs Eworkfow Eout EwiEth Ethe Eclass Erepo!

Page 19: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Slack EIntegraton

● You Ecan EiEntegrate Eyour Eresearch Egroup’s EgiEthub EiEnto Eyour Eslack

– ThiEs EiEs Edone EiEn Eour EgiEt Echannel

– Any Echanges, EPRs, EiEssues, Eetc. EwiEll Ebe Ereported

Page 20: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

VersiEon EControl

● There's Eno Ereason Enot Eto Euse EversiEon Econtrol

– PiEck Eone E(giEt Eor Ehg) Eand Euse EiEt

● wven EiEf Eyou Eare EworkiEng Ealone

– wach Eclone Ehas Eall Ethe EhiEstory Eof Ethe Eproject

– CloniEng Eon EdiEferent EmachiEnes Emeans Eyou Ehave Ebackups

– Allows Eyou Eto Esync Eup Eyour Ework Ebetween Ehome Eand Ethe Eofce

Page 21: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

UniEt ETestng

● When EwriEtng Ea Ecomplex Eprogram E(e.g. Ea EsiEmulaton Ecode), Ethere Ecan Ebe Emany Eseparate Esteps E/ Esolvers EiEnvolved EiEn Egetng Eyour Eanswer.

– FiEndiEng Eout Ethe Esource Eof Eerrors EiEn Esuch Ea EcompliEcated Ecode Ecan Ebe Etough.

● UniEt Etestng EiEs Ethe Epractce EiEn EwhiEch Eeach Esmallest, Eself-contaiEned EuniEt Eof Ethe Ecode EiEs Etested EiEndependently Eof Ethe Eothers.

– You Ecould, Efor Eexample, Estart Eby EwriEtng Etests Efor Eeach Eof Ethe Emajor EphysiEcs EuniEts, Eand Ethen Eworry Eabout Elower Elevels

● Implementatons

– wiEther EwriEte Eyour Eown EsiEmple EdriEver Efor Eeach Eroutne Eto Ebe Etested

– UniEt Etestng Eframeworks Eautomate Esome Etasks E

● pytest EiEs Ea Every Epopular Eone—we'll Esee Esome Eexamples Eof EthiEs Eat Ethe Eend Eof Ethe Esemester

Page 22: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

UniEt ETestng

● SiEmple Eexamples EmatriEx EiEnversiEon

– Your Ecode Ehave Ea EmatriEx EiEnversiEon Eroutne Ethat Ecomputes EA-1

– A EuniEt Etest Efor EthiEs Eroutne Ecan Ebes

● PiEck Ea Evector Ex● Compute Eb = A x● Compute Ex = A-1 b● Does Ethe Ex Eyou Eget Ematch E(to EmachiEne Etol) Ethe EoriEgiEnal Ex?

● More EcompliEcated Eexamples Ea Ehydro Eprogram Emay EconsiEst Eof

– Advecton Eroutnes, EwOS Ecalls E(and EiEnvertng Ethe EwOS), EPartcles, EDiEfusiEon, EReactons

– wach Eof Ethese Ecan Ebe Etested Ealone

● There EiEs Ea Epython EuniEt Etestng Eframework Ecalled Enose—we Ecan Eexplore Ethat EiEn Ethe EdiEscussiEon Eforum EiEf Ethere EiEs EiEnterest.

Page 23: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

UniEt ETestng

Test Eof Epartcle Eadvecton EiEn Eour Elow EMach Ehydro Ecode, EMaestro

Test Eof EdiEfusiEon EiEn Eour Elow EMach Ehydro Ecode, EMaestro(Malone Eet Eal. E2-s11)

Page 24: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

UniEt ETestng

● Whenever Eyou EiEmportant Esome Elegacy Ecode EiEnto Eyour Eproject, EwriEte Ea EuniEt Etest

– VeriEfes Ethat EiEt Eperforms Eas Ethe Eauthors EiEntend

– Allows Efor Etests Eto EiEnterface Echanges Eyou Emake Eto Ethe Ecode

Page 25: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

RegressiEon ETestng

● ImagiEne Eyou've E“perfected” Eyour Eprogram

– You Eare Econfdent Ethat Ethe Eanswer EiEt EgiEves EiEs E“riEght”

– You Ewant Eto Emake Esure Ethat Eany Echanges Eyou Edo EiEn Ethe Efuture Edo Enot Echange Ethe Eoutput

– RegressiEon Etestng Etests Ewhether Echanges Eto Ethe Ecode Echange Ethe Esoluton

● RegressiEon Etestngs

– Store Ea Ecopy Eof Ethe Ecurrent Eoutput E(a Ebenchmark)

– Make Esome Echanges Eto Ethe Ecode

– Compare Ethe Enew Esoluton Eto Ethe EpreviEous Esoluton

– If Ethe Eanswers EdiEfer, EeiEthers

● You've EiEntroduced Ea Ebug E→ Efx EiEt● You've Efxed Ea Ebug E→ Eupdate Eyour Ebenchmark

Page 26: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

RegressiEon ETestng

● SiEmplest ErequiErementss

– You Ejust Eneed Ea Etool Eto Ecompare Ethe Ecurrent Eoutput Eto Ebenchmark

– You Ecan EbuiEld Eup Ea Emore Ecomplex Esystem Efrom Ehere EwiEth EsiEmple EscriEptng

● BiEg Ecodes Eneed Ea Ebunch Eof Etests Eto EexerciEse Eall EpossiEble Eoptons Efor Ethe Ecode

– If Eyou Espend Ea Elot Eof Etme Ehuntng Edown Ea Ebug, Eonce Eyou Efx EiEt, Eput Ea Etest Ecase EiEn Eyour EsuiEte Eto Echeck Ethat Ecase

– You'll Enever Ehave Ecomplete Ecoverage, Ebut Eyour Enumber Eof Etests EwiEll Egrow EwiEth Etme, EexperiEence, Eand Ecode EcomplexiEty

● SiEmple Eexample EwiEth Emy Epython Ehydro Ecode

– ./pyro.py --compare_benchmark advection smooth inputs.smooth

Page 27: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

RegressiEon ETestng

● Maestro E(automated EregressiEon Etestng)

Page 29: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

General ERules

● When Eyou EwriEte Ecode, EthiEnk Eto Eyourselfs E“iEf EI Ecome Eback Eto EthiEs E6 Emonths Efrom Enow, EwhiEle EI Eunderstand Ewhat EI've Edone?”

– If Enot, Etake Ethe Etme Enow Eto Emake EthiEngs Eclearer, Edocument E(even Ea EsiEmple ERwADMw) Ewhat Eyou've Edone, Ewhere Ethe Eequatons Ecome Efrom, Eetc.

– You'll Ebe EsurpriEsed Eand Ehow Elong Eyour Ecode EliEves Eon!

● Some Elanguages Elet Eyou Edo Ecute EtriEcks. E E

– wven EiEf Ethey EmiEght Eofer Ea Esmall Espeed Ebump, EiEf Ethey EcompliEcate Ethe Ecode Ea Elot Eto Ethe EpoiEnt Ethat EiEt EiEs Ehard Eto Efollow, Ethen Ethey're Eprobably Enot Eworth EiEt.

● Get EthiEngs EworkiEng Ebefore EobsessiEng Eon Eperformance

Page 30: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Automatng EReproduciEbiEliEty

● Store Emeta-data EiEn Eyour Eoutput Efles Ethat Etell Eyou Ewhere, Ewhen, Ewhat, Eand Ehow Ethe Edata Ewas Eproduced.

– Already Esaw Ethe Eexample Eof Ethe EgiEt Ehash EiEn Ethe Emakefle Eexamples

– Maestro Eexample...

Page 31: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

=============================================================================== Job Information===============================================================================job name: inputs file: inputs_2d number of MPI processes 1number of threads 1 CPU time used since start of simulation (CPU-hours) 0.1473997255E-01 =============================================================================== Plotfile Information===============================================================================output date: 2013-05-08output time: 11:39:43output dir: /home/zingale/development/MAESTRO/Exec/TEST_PROBLEMS/test2time to write plotfile (s) 0.5483140945 =============================================================================== Build Information===============================================================================build date: 2013-05-08 11:38:04.553714build machine: Linux nan.astro.sunysb.edu 3.8.9-200.fc18.x86_64 #1 SMP Fri Apr 26 12:50:07 UTC 2013 x86_64 x86_64 x86_64 GNU/Linuxbuild dir: /home/zingale/development/MAESTRO/Exec/TEST_PROBLEMS/test2BoxLib dir: /home/zingale/development/BoxLib/ MAESTRO git hash: bad8ea8d66871a2172dcb276643edce53f739695BoxLib git hash: febf34dba7cc701a78c73e16a543f062cf36d587AstroDev git hash: 5316edb829577f80977fd2db8a113ccc4da42e02 modules used: Util/model_parser Util/random Util/VODE Util/BLAS Source ../../../Microphysics/EOS ../../../Microphysics/EOS/helmeos ../../../Microphysics/networks/ignition_simple ../../../Microphysics/conductivity/timmes_stellar

Page 32: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

FCOMP: gfortranFCOMP version: gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC) F90 compile line: mpif90 -Jt/Linux.gfortran.debug.mpi/m -It/Linux.gfortran.debug.mpi/m -g -fno-range-check -O1 -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid -finit-real=nan -I../../../Microphysics/EOS/helmeos -c F77 compile line: gfortran -Jt/Linux.gfortran.debug.mpi/m -It/Linux.gfortran.debug.mpi/m -g -fno-range-check -O1 -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid -finit-real=nan -I../../../Microphysics/EOS/helmeos -c C compile line: gcc -std=c99 -Wall -g -O1 -DBL_Linux -DBL_FORT_USE_UNDERSCORE -c linker line: mpif90 -Jt/Linux.gfortran.debug.mpi/m -It/Linux.gfortran.debug.mpi/m -g -fno-range-check -O1 -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid -finit-real=nan -I../../../Microphysics/EOS/helmeos =============================================================================== Grid Information=============================================================================== level: 1 number of boxes = 60 maximum zones = 384 640 Boundary Conditions -x: periodic +x: periodic -y: slip wall +y: outlet =============================================================================== Species Information===============================================================================index name short name A Z------------------------------------------------------------------------------- 1 carbon-12 C12 12.00 6.00 2 oxygen-16 O16 16.00 8.00 3 magnesium-24 Mg24 24.00 12.00

+ Evalues Eof Eall Eruntme Eparameters...

Page 33: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Debuggers

● SiEmplest EdebuggiEngs Elots Eof EpriEnts!

● Interactve Edebuggers Elet Eyou Estep Ethrough Eyour Ecode EliEne-by-liEne, EiEnspect Ethe Evalues Eof EvariEables Eas Ethey Eare Eset, Eetc.

● pdb EiEs Ethe Epython Edebugger● If Eyou Ejust Ewant Eto Eknow Ehow Ethe Ecode Egets Eto Ea EcertaiEn Efunctons

import traceback

traceback.print_stack()

Page 34: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Commentng Eand EDocumentaton

● The Eonly EthiEng Eworse Ethan Eno Ecomments Eare Ewrong Ecomments

– Comments Ecan EeasiEly Eget Eout Eof Edate Eas Ecode Eevolves

● Comments Eshould Econvey Eto Ethe Ereader Ethe EbasiEc EiEdea Eof Ewhat Ethe Enext Eset Eof EliEnes EwiEll EaccompliEsh. E E

– AvoiEd Ecommentng EobviEous Esteps EiEf Eyou've Ealready EdescriEbed Ethe EbasiEc EiEdea

● Many Epackages Eallow Efor Eautomatc Edocumentaton Eof Eroutnes/iEnterfaces EusiEng Epragmas Eput EiEnto Ethe Ecode Eas Ecomments.

Page 35: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Source ECode ELiEbrariEes

● There Eare Emany Esources Efor Eopen, Ewell-tested, EpubliEshed Ecodes Ethat Emay Ealready Edo Ewhat Eyou Ewant.

– ThiEs Emakes EiEt EeasiEer Eto Eget EgoiEng, Emay Eofer Ebeter EalgoriEthms Ethan Eyou Ewere Eprepared Eto Ecode.

– Benefts Efrom Ea EcommuniEty Eof Edevelopers Eand EmaturiEty

– Stll Eneed Eto Etest, EexamiEne Ereturn Ecodes, Eetc.

● Many Eof Ethese Emature Ecodes Eare Ealready Ewrapped Efor Eyou EiEn ESciEPy.

● For Eother Ecodes, Ewe'll Elook Enext Eat Ehow Eto Eextend Epython EiEn EFortran Eand EC

Page 36: Software EwngiEneeriEng E Practces Efor EPythonbender.astro.sunysb.edu/classes/python-science/lectures/python... · Python EStyle The Erecommended Epython Estyle EiEs EdescriEbed

Summary

● Some EbasiEc EcodiEng Epractces Ecan Egreatly EiEmprove Ethe EreliEabiEliEty Eof Eyour Ecode

– Frees Eyou Eto Edo EsciEence

● Small ElearniEng Ecurve EiEs Egreatly Eofset Eby Ethe EiEmproved EproductviEty Eand EstabiEliEty