advanced practical programming - zuse institute berlin · pdf fileexperiment an experimentis a...
TRANSCRIPT
AdvancedpracticalProgrammingforScientists
SS2017
Thorsten KochZuse Institute Berlin
TU Berlin
TheZenof Python,by TimPeters(Part2)
Thereshouldbeone-- andpreferablyonlyone--obviouswaytodoit.Althoughthatwaymaynotbeobviousatfirstunlessyou'reDutch.Nowisbetterthannever.Althoughneverisoftenbetterthan*right*now.Iftheimplementationishardtoexplain,it'sabadidea.Iftheimplementationiseasytoexplain,itmaybeagoodidea.
AdvancedProgramming 116
AdvancedProgramming 117
AdvancedProgramming 118
AdvancedProgramming 119
AdvancedProgramming 120
AdvancedProgramming 121
GB
]
seconds
AdvancedProgramming 122
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
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
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
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
1;1;179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858369.000000
AdvancedProgramming 127
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
AdvancedProgramming 129
Errorsshould never passsilently(unless explicitly silenced)
AdvancedProgramming 130
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
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
Ariane5
AdvancedProgramming 133
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
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