{"id":2643,"date":"2011-09-23T12:28:27","date_gmt":"2011-09-23T16:28:27","guid":{"rendered":"http:\/\/www.easterbrook.ca\/steve\/?p=2643"},"modified":"2011-09-29T14:19:03","modified_gmt":"2011-09-29T18:19:03","slug":"formal-verification-for-climate-models","status":"publish","type":"post","link":"http:\/\/www.easterbrook.ca\/steve\/2011\/09\/formal-verification-for-climate-models\/","title":{"rendered":"Formal Verification for Climate Models?"},"content":{"rendered":"<p>Valdivino, who is working on a PhD in Brazil, on formal software verification techniques, is inspired by my <a title=\"About Steve\" href=\"http:\/\/www.easterbrook.ca\/steve\/?page_id=2\" target=\"_blank\">suggestion<\/a> to find ways to apply our current software research skills to climate science. But he asks some hard questions:<\/p>\n<blockquote><p>1.) If I want to Validate and Verify climate models should I forget all the things that I have learned so far in the V&amp;V discipline? (e.g.\u00a0Model-Based Testing (Finite State Machine, Statecharts, Z, B), structural testing, code inspection, static analysis, model checking)<br \/>\n2.) Among all V&amp;V techniques, what can really be reused \/ adapted for climate models?<\/p><\/blockquote>\n<p>Well, I wish I had some good answers.\u00a0When I started looking at the software development processes for climate models, I expected to be able to apply many of the [<span style=\"color: #008000;\">edit<\/span>] <em><span style=\"color: #008000;\">formal<\/span><\/em> techniques I&#8217;ve worked on in the past in Verification and Validation (V&amp;V) and Requirements Engineering (RE). It turns out almost none of it seems to apply, at least in any obvious way.<\/p>\n<p>Climate models are built through a long, slow process of trial and error, continually seeking to improve the quality of the simulations (<a title=\"Verification and Validation of Earth System Models\" href=\"http:\/\/www.easterbrook.ca\/steve\/?p=1917\" target=\"_blank\">See here for an overview of how they&#8217;re tested<\/a>). As this is scientific research, it&#8217;s unknown, <em>a priori<\/em>, what will work, what&#8217;s computationally feasible, etc. Worse still, the complexity of the earth systems being studied means its often hard to know which processes in the model most need work, because the relationship between particular earth system processes and the overall behaviour of the climate system is exactly what the researchers are working to understand.<\/p>\n<p>Which means that model development looks most like an <a title=\"If you're not familiar, wikipedia offers a good intro\" href=\"http:\/\/en.wikipedia.org\/wiki\/Agile_software_development\" target=\"_blank\">agile software development process<\/a>, where the both the requirements and the set of techniques needed to implement them are unknown (and unknowable) up-front. So they build a little, and then explore how well it works. The closest they come to a formal specification is a set of hypotheses along the lines of:<\/p>\n<blockquote><p>&#8220;if I change &lt;piece of code&gt; in &lt;routine&gt;, I expect it to have &lt;specific impact on model error&gt; in &lt;output variable&gt; by &lt;expected margin&gt; because of &lt;tentative theory about climactic processes and how they&#8217;re represented in the model&gt;&#8221;<\/p><\/blockquote>\n<p>This hypothesis can then be tested by a formal experiment in which runs of the model with and without the altered code become two treatments, assessed against the observational data for some relevant period in the past. The expected improvement might be a reduction in the root mean squared error for some variable of interest, or just as importantly, an improvement in the variability (e.g. the seasonal or diurnal spread).<\/p>\n<p>The whole process looks a bit like this (although, see <a title=\"Jakob C. Accelerating Progress in Global Atmospheric Model Development through Improved Parameterizations: Challenges, Opportunities, and Strategies. Bulletin of the American Meteorological Society. 2010;91(7):869-875.\" href=\"http:\/\/journals.ametsoc.org\/doi\/abs\/10.1175\/2009BAMS2898.1\" target=\"_blank\">Jakob&#8217;s 2010 paper<\/a> for a more sophisticated view of the process):<\/p>\n<p><a href=\"http:\/\/www.easterbrook.ca\/steve\/wp-content\/model-development-cycle1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-2645\" title=\"model-development-cycle\" src=\"http:\/\/www.easterbrook.ca\/steve\/wp-content\/model-development-cycle1.jpg\" alt=\"\" width=\"550\" height=\"363\" srcset=\"http:\/\/www.easterbrook.ca\/steve\/wp-content\/model-development-cycle1.jpg 550w, http:\/\/www.easterbrook.ca\/steve\/wp-content\/model-development-cycle1-300x197.jpg 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a>And of course, the central V&amp;V technique here is full integration testing. The scientists build and run the full model to conduct the end-to-end tests that constitute the experiments.<\/p>\n<p>So the closest thing they have to a specification would be a chart such as the following (courtesy of Tim Johns at the UK Met Office):<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/www.easterbrook.ca\/steve\/wp-content\/skill-gain.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-2648\" title=\"skill-gain\" src=\"http:\/\/www.easterbrook.ca\/steve\/wp-content\/skill-gain.jpg\" alt=\"\" width=\"569\" height=\"404\" srcset=\"http:\/\/www.easterbrook.ca\/steve\/wp-content\/skill-gain.jpg 948w, http:\/\/www.easterbrook.ca\/steve\/wp-content\/skill-gain-300x212.jpg 300w\" sizes=\"(max-width: 569px) 100vw, 569px\" \/><\/a>This chart shows how well the model is doing on 34 selected output variables (click the graph to see a bigger version, to get a sense of what the variables are). The scores for the previous model version have been normalized to 1.0, so you can quickly see whether the new model version did better or worse for each output variable &#8211; the previous model version is the line at &#8220;1.0&#8221; and the new model version is shown as the coloured dots above and below the line. The whiskers show the <em>target<\/em> skill level for each variable. If the coloured dots are within the whisker for a given variable, then the model is considered to be within the variability range for the observational data for that variable. Colour-coded dots then show how well the current version did: green dots mean it&#8217;s within the target skill range, yellow mean it&#8217;s outside the target range, but did better than the previous model version, and red means it&#8217;s outside the target and did worse than the previous model version.<\/p>\n<p>Now, as we know, agile software practices aren&#8217;t really amenable to any kind of formal verification technique. If you don&#8217;t know what&#8217;s possible before you write the code, then you can&#8217;t write down a formal specification (the &#8216;target skill levels&#8217; in the chart above don&#8217;t count &#8211; these aspirational goals rather than specifications). And if you can&#8217;t write down a formal specification for the expected software behaviour, then you can&#8217;t apply formal reasoning techniques to determine if the specification was met.<\/p>\n<p>So does this really mean, as Valdivino suggests, that we can&#8217;t apply any of our toolbox of formal verification methods? I think attempting to answer this would make a great research project. I have some ideas for places to look where such techniques might be applicable. For example:<\/p>\n<ul>\n<li>One important built-in check in a climate model is &#8216;conservation of mass&#8217;. Some fluxes move mass between the different components of the model. Water is an obvious one &#8211; it&#8217;s evaporated from the oceans, to become part of the atmosphere, and is then passed to the land component as rain, thence to the rivers module, and finally back to the ocean. All the while, the total mass of water across all components must not change. Similar checks apply to salt, carbon (actually this does change due to emissions), and various trace elements. At present, such checks are this is built in to the models as code assertions. In some cases, flux corrections were necessary because of imperfections in the numerical routines or the geometry of the grid, although in most cases, the models have improved enough that most flux corrections have been removed. But I think you could automatically extract from the code an abstracted model capturing just the ways in which these quantities change, and then use a model checker to track down and reason about such problems.<\/li>\n<li>A more general version of the previous idea: In some sense, a climate model is a giant state-machine, but the scientists don&#8217;t ever build abstracted versions of it &#8211; they only work at the code level. If we build more abstracted models of the major state changes in each component of the model, and then do compositional verification over a combination of these models, it *might* offer useful insights into how the model works and how to improve it. At the very least, it would be an interesting teaching tool for people who want to learn about how a climate model works.<\/li>\n<li>Climate modellers generally don&#8217;t use unit testing. The challenge here is that they find it hard to write down correctness properties for individual code units. I&#8217;m not entirely clear how formal methods could help here, but it seems like someone with experience of patterns for temporal logic properties might be able to help here. Clune and Rood have a forthcoming paper on this in November&#8217;s IEEE Software. I suspect this is one of the easiest places to get started for software people new to climate models.<\/li>\n<li>There&#8217;s one other kind of verification test that is currently done by inspection, but might be amenable to some kind of formalization: the check that the code correctly implements a given mathematical formula. I don&#8217;t think this will be a high value tool, as the fortran code is close enough to the mathematics that simple inspection is already very effective. But occasionally a subtle bug slips through &#8211; for example, I came across an example where the modellers discovered they had used the wrong logarithm (log<sub>e<\/sub> in place of log<sub>10<\/sub>), although this was more due to lack of clarity in the original published paper, rather than a coding error.<\/li>\n<\/ul>\n<p>Feel free to suggest more ideas in the comments!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Valdivino, who is working on a PhD in Brazil, on formal software verification techniques, is inspired by my suggestion to find ways to apply our current software research skills to climate science. But he asks some hard questions: 1.) If I want to Validate and Verify climate models should I forget all the things that [&hellip;]<\/p>\n","protected":false},"author":393,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,52],"tags":[],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/posts\/2643"}],"collection":[{"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/users\/393"}],"replies":[{"embeddable":true,"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/comments?post=2643"}],"version-history":[{"count":11,"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/posts\/2643\/revisions"}],"predecessor-version":[{"id":2661,"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/posts\/2643\/revisions\/2661"}],"wp:attachment":[{"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/media?parent=2643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/categories?post=2643"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.easterbrook.ca\/steve\/wp-json\/wp\/v2\/tags?post=2643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}