advanced practical programming - zuse institute berlin · pdf fileexperiment an experimentis a...

21
Advanced practical Programming for Scientists SS2017 Thorsten Koch Zuse Institute Berlin TU Berlin

Upload: leque

Post on 17-Mar-2018

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedpracticalProgrammingforScientists

SS2017

Thorsten KochZuse Institute Berlin

TU Berlin

Page 2: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

TheZenof Python,by TimPeters(Part2)

Thereshouldbeone-- andpreferablyonlyone--obviouswaytodoit.Althoughthatwaymaynotbeobviousatfirstunlessyou'reDutch.Nowisbetterthannever.Althoughneverisoftenbetterthan*right*now.Iftheimplementationishardtoexplain,it'sabadidea.Iftheimplementationiseasytoexplain,itmaybeagoodidea.

AdvancedProgramming 116

Page 3: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 117

Page 4: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 118

Page 5: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 119

Page 6: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 120

Page 7: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 121

GB

]

seconds

Page 8: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 122

Page 9: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Experiment

Anexperiment isaprocedurecarriedouttosupport,refute,orvalidateahypothesis.Experimentsprovideinsightintocause-and-effect bydemonstratingwhatoutcomeoccurswhenaparticularfactorismanipulated.Experimentsvarygreatlyingoalandscale,butalwaysrelyonrepeatableprocedureandlogicalanalysisoftheresults.

Anexperimentusuallytestsahypothesis,whichisanexpectationabouthowaparticularprocessorphenomenonworks.However,anexperimentmayalsoaimtoanswera“what-if”question,withoutaspecificexpectationaboutwhattheexperimentreveals,ortoconfirmpriorresults.Ifanexperimentiscarefullyconducted,theresultsusuallyeithersupportordisprovethehypothesis.[…] Anexperimentmustalsocontrolthepossibleconfoundingfactors—anyfactorsthatwouldmartheaccuracyorrepeatabilityoftheexperimentortheabilitytointerprettheresults.Confoundingiscommonlyeliminatedthroughscientificcontrols and/or,inrandomizedexperiments,throughrandomassignment.

https://en.wikipedia.org/w/index.php?title=Experiment&oldid=781092819

AdvancedProgramming 123

Page 10: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Automatize!

• Youhavetocomputationalresultsagain,anyway.• Trytoautomatizethemasmuchaspossible.• Checkwhethertheresultsofsuccessiverunsfit.• Sampleifneccessary

residentsetsize (RSS)istheportionofmemoryoccupiedbyaprocess thatisheldinmainmemory (RAM).Therestoftheoccupiedmemoryexistsintheswapspace orfilesystem,eitherbecausesomepartsoftheoccupiedmemorywerepagedout,orbecausesomepartsoftheexecutablewereneverloaded.[

https://en.wikipedia.org/w/index.php?title=Resident_set_size&oldid=767184487

AdvancedProgramming 124

Page 11: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

1;1;179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000002;1;1.797693e+3083;1;0.0000004;1;21474836475;1;92233720368547758076;1;0.00000000000000017;1;1e-3078;1;1e-3089;1;0.9e-30710;1;0.3e-30711;1;0.2e-307

AdvancedProgramming 125

Page 12: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Line 3: Invalid valueLine 8: Invalid valueLine 11: Invalid valueFile: test4.dat with 11 linesValid values Loc0: 8 with GeoMean: 0.000000Valid values Loc1: 0 with GeoMean: 1.000000

AdvancedProgramming 126

Page 13: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

1;1;179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858369.000000

AdvancedProgramming 127

Page 14: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

File: test5.dat with 1 linesValid values Loc0: 1 with GeoMean: 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000Valid values Loc1: 0 with GeoMean: 1.000000

File: test5.dat with 1 linesex1b: ex1b.c:68: geom_mean_log: Assertion `!fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW)' failed.Aborted (core dumped)

AdvancedProgramming 128

Page 15: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

AdvancedProgramming 129

Page 16: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Errorsshould never passsilently(unless explicitly silenced)

AdvancedProgramming 130

Page 17: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Ariane5

On4June1996themaidenflightoftheAriane 5launcherendedinafailure,about40secondsafterinitiationoftheflightsequence.Atanaltitudeofabout3700m,thelauncherveeredoffitsflightpath,brokeupandexploded.Thefailurewascausedby"completelossofguidanceandattitudeinformation"30secondsafterliftoff.Theproblemwascausedbyan`OperandError'inconvertingdatainasubroutinefrom64-bitfloatingpointto16-bitsignedinteger.Onevaluewastoolargetobeconverted,creatingtheOperandError.Thiswasnotexplicitlyhandledintheprogram(althoughotherpotentialOperandErrorswere)andsothecomputer,theInertialReferenceSystem(SRI)halted,asspecifiedinotherrequirements.TherearetwoSRIs,one`active',one`hotback-up'andtheactiveonehaltedjustafterthebackup,fromthesameproblem.Sincenoinertialguidancewasnowavailable,andthecontrolsystemdependsonit,wecansaythatthedestructiveconsequencewastheresultof`Garbagein,garbageout'(GIGO).TheconversionerroroccurredinaroutinewhichhadbeenreusedfromtheAriane 4vehicle,whoselaunchtrajectorywasdifferentfromthatoftheAriane 5.ThevariablecontainingthecalculationofHorizontalBias(BH),aquantityrelatedtothehorizontalvelocity,thuswentoutof`planned'bounds(`planned'fortheAriane 4)andcausedtheOperandError.

AdvancedProgramming 131

Page 18: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Requirements and Testing

a) Theoperandrangeinthemodulewasdeliberatelynotprotected;b) thiswasbecauseengineeringanalysisforitsuseinAriane 4hadshownthe

operandwouldnevergooutofbounds;c) therangerequirementstemmingfromthisanalysiswasnottransferredtothe

requirementsfortheAriane 5;d) testingwasdoneagainstrequirements

thisismoreproperlyclassifiedasarequirementserrorratherthanaprogrammingerror.TheprogramwaswrittenagainstAriane 4requirements;theserequirementswerenottransferredtotheAriane 5requirementsspec;theAriane 5requirementsthereforedidnotstatetherangerequirement;the(implicitinAriane 5)rangerequirementwasinconflictwiththebehaviorofAriane 5(asinfactexplicatedinotherAriane 5requirements);requirementscameupagainstbehaviorandtherocketwasdestroyed.(Itisnotsurprisingthatitwasarequirementserror- over90%ofsafety-criticalsystemsfailuresarerequirementserrors,accordingtoaJPLstudythathasbecomefolklore)

AdvancedProgramming 132

Page 19: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Ariane5

AdvancedProgramming 133

Page 20: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Static SoftwareAnalysis

C/C++http://cppcheck.sourceforge.net/https://clang.llvm.org/docs/index.htmlhttp://valgrind.org/http://www.gimpel.com/html/flex.htm (commercial)https://www.grammatech.com/products/codesonar (commercial)http://ltp.sourceforge.net/coverage/lcov.php

Pythonhttps://coverage.readthedocs.io/en/coverage-4.4.1/https://www.pylint.org/https://blog.codacy.com/review-of-python-static-analysis-tools-ff8e7e27f972

C/C++,Java,Python,etc.https://scan.coverity.com/ (commercial,free use)

Adahttp://www.adacore.com/codepeer

AdvancedProgramming 134

Page 21: Advanced practical Programming - Zuse Institute Berlin · PDF fileExperiment An experimentis a procedure carried out to support, refute, or validate a hypothesis. Experiments provide

Exercise

Readhttp://matt.might.net/articles/intro-to-make/ andhavealookathttp://berrendorf.inf.h-brs.de/sonstiges/make.html

1. Ex1:a. checkforconsecutivesequencenumbersb. checkboundaryvalues

2. Ex1,Ex2:a. documentusingdoxygen orsimilarb. writemakefile togeneratedocumentationwith:make docc. Writemakefile togeneratecoveragewith:make coveraged. Writemakefile torunstaticchecks:make check

3. Ex3:WewillwriteaprogramtopredictatimeseriesyouwillfinddataonMondayongithub.Writeaprogramthatreadsinthedataandpredictsthenext24values.

AdvancedProgramming 137