Creating Shareable Models By: Eric Hutton CSDMS is the Community Surface Dynamics Modeling System (pronounced ˈ s ɪ stəms) Image by Flickr user Let There.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
P5, M1, D1.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
The Web Warrior Guide to Web Design Technologies
R Mohammed Wahaj. What is R R is a programming language which is geared towards using a statistical approach and graphics Statisticians and data miners.
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
Programming Creating programs that run on your PC
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Contributing source code to CSDMS Albert Kettner.
Creating Shareable Models By: Eric Hutton CSDMS - Community Surface Dynamics Modeling System (pronounced ˈ s ɪ stəms) Image by Flickr user Let There Be.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Programming Part 1 Armond R. Smith Zhenying Wu. Overview of this Class ● Transition from FTC -> FRC ● Using Your Resources ● Java Keywords o Data Types.
Language Issues Misunderstimated? Sublimable? Hopefuller? "I know how hard it is for you to put food on your family.” "I know the human being and fish.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Struts 2.0 an Overview ( )
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
A First Program Using C#
Writing your own Madagascar applications Sergey Fomel University of Texas at Austin August 30, 2006 Vancouver, BC.
CCA Port, Component & Application Build Skeleton Templates “A new script toolkit for generating CCA build skeletons” Torsten Wilde and James Kohl Oak Ridge.
Nachos Phase 1 Code -Hints and Comments
Lecture 61 CS110 Lecture 6 Thursday, February 12, 2004 Announcements –hw2 due today Agenda –questions –testing –modeling text files –declarations (classes,
CMPD 434 MULTIMEDIA AUTHORING Chapter 06 Multimedia Authoring Process IV.
JavaDoc1 JavaDoc DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY July 24, 2006 by Emil Vassev & Joey Paquet revision 1.2 –
Classes CS 21a: Introduction to Computing I First Semester,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Robert Crawford, MBA West Middle School.  Explain how the binary system is used by computers.  Describe how software is written and translated  Summarize.
Intermediate 2 Software Development Process. Software You should already know that any computer system is made up of hardware and software. The term hardware.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
240-Current Research Easily Extensible Systems, Octave, Input Formats, SOA.
Documentation. Your documentation must fit the needs of your audience. It’s always better to say one thing that is useful, as opposed to many things that.
JavaDoc and Contracts Spring Documenting Contracts with JavaDoc Contract model for methods Preconditions Postconditions JavaDoc Industry standard.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
July Doxygen A Code Documentation System Doxygen generates documentation directly from the structure and comments in the code –Browsable HTML documentation.
CS 261 Fall 2009 Dynamic Array Introduction (aka Vector, ArrayList)
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CS 177 Recitation Week 1 – Intro to Java. Questions?
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
CSCE 240 – Intro to Software Engineering Lecture 3.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Development Environment
Learning to Program D is for Digital.
Lecture 1 Introduction Richard Gesick.
Introduction to Python
Eclipse Navigation & Usage.
Testing and Debugging.
Choice of Programming Language
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
SVTRAININGS. SVTRAININGS Python Overview  Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed.
TRANSLATORS AND IDEs Key Revision Points.
Some Tips for Using Eclipse
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
Topic 1: Problem Solving
Type & Typeclass Syntax in function
Classes CS 21a: Introduction to Computing I
Selection Statements Chapter 3.
ENERGY 211 / CME 211 Lecture 27 November 21, 2008.
Continuous Integration
Contributing source code to CSDMS
Presentation transcript:

Creating Shareable Models By: Eric Hutton CSDMS is the Community Surface Dynamics Modeling System (pronounced ˈ s ɪ stəms) Image by Flickr user Let There Be More Light

A model can more easily be used by others if it is readable and has an API Readable Application Programming Interface (API) Someone new to your code should be able to give it a quick read and know what’s going on. The interface will allow someone to use it without worrying about implementation details.

But before all that though, choose a license and a language The GNU General Public License is a good choice. But there lots more. For example, MIT Apache LGPL GPLv3 OSL As far as languages, C is a good choice.

Writing readable code mostly means sticking to a standard The code should speak for itself. That doesn’t just mean adding more comments. Super simple things help: Spaces instead of tabs Useful variable names – especially for global variables and function names Underscores in names – water_density is better than iCantReadThis In the end though, just be consistent.

Makefiles and configure scripts help to make code portable Software distributions on UNIX are usually compiled with, >./configure > make Creates a make file specific to your system Compiles the code Easy, right? Well… the magic that goes on behind the scenes to make this tick is complicated. Uses “programming languages” such as: automake, autoconf, m4, make, sh

A better alternative to configure/make is cmake Cmake is free, open-source software that replaces autotools/make. Simple syntax Much easier to learn than autotools Supports nearly every Unix, Windows, Mac OSX Features a testing framework Features a packaging framework am2cmake script to convert automake files Random compile tip: compile with –Wall compile flag and pay attention to the warnings.

If your code comes with documentation, it is more likely to be used by others There are tools that help with this javadoc (Java) doctest (Python) Doxygen (C, C++, Java, Python, Fortran, and kinda/sorta Matlab) These all generate documentation from comments within your code.

For example, a C function can be documented directly above it’s definition/declaration. /** Calculate the area of a r Radius of the The circle’s area */ double area_of_circle ( double r ); This is similar to annotations in Java. We’ll come back to this later.

It would be nice if there existed a set of standard annotations for our modeling community. Some examples of annotation that would be useful to someone wanting to use @unit Your source code could then be parsed for these annotations. Since they are ignored by the compiler, they inject very little of the framework into your code.

Annotations could be used to describe three categories of meta data (this list comes from @finalize Others?

Example annotation for a component that calculates the area of a Public class @in public double public double public void runme() { area = Math.PI * r * r; }

Our models are difficult to couple because of implementation details Some reasons that models are difficult to link or share: Languages Time steps Numerical schemes Complexity These are all implementation details. The user shouldn’t have to worry about these details. Design an interface!

A modeling interface hides implementation details from the application developer Lots of crazy, hard-to- understand code A coastal evolution model, sayYou

A Blue Box A modeling interface hides implementation details from the application developer A coastal evolution model, sayYou That’s more like it

For our models a useful interface is IRF I is for Initialize R is for Run F is for Finalize int main() { initialize_stuff(); run_until_stop_time(); print_output(); return SUCCESS; }

When designing interfaces it is often easiest to start at the end Setup the model run Run the model for 25 years Get the water depths Run the model for an additional 75 years and get water depths Do whatever needs to be done before quitting int main() { cem_state *s = cem_init (); double *d0, *d1; cem_run_until (s, 25.); d0 = cem_get_water_depth (s); cem_run_until (s, 25.); d1 = cem_get_water_depth (s); cem_finalize (s); return EXIT_SUCCESS; }

The initialize step sets up a new model run (instance) Things that might be done within the initialize method: Create a new state for the model Allocate memory Set initial conditions Pretty much anything that is done before the time looping begins

The initialize step shouldn’t interfere with another program’s initialize step Things that probably shouldn’t be done within the initialize method: Gather input from the command line (argc, argv) Most any user interface Anything that might interfere with another component

The finalize step destroys an existing model run (instance) Things that might be done within the finalize method: Free resources Close files Print final output Pretty much anything that is done after the time looping ends

The run step advances the current state of the model forward in time The run method advances the model from its current state to a future state. run_until( t1 ); run_until( t2 ); t1t2

Oftentimes it is useful to create a data type that holds the current state of the model This is the hard part. Identify all of the variables that need to be remembered to advance the model forward in time. Collect these variables (I generally wrap them in a struct or class). I suppose a common block or a set of global variables would do. This data structure can then be passed to the various methods of the API.

Getters and setters are used to interact with the model’s state The state structure should be opaque to the user – that is implementation stuff Instead, use get and set functions. For instance, get_water_depth( ); set_input_file( “input” ); It is up to the API designer to decide what variables are allowed to be get/set.

Refactoring your code in this way should not change model output …unless you find (and fix) a bug. To make sure that you don’t add bugs when refactoring, Make lots of tests Run these tests often Keep in mind that output may not be byte-for-byte comparable to your benchmarks

In conclusion, there are really only two “rules” Questions? Write code that someone else can understand. Pick a standard and stick to it. Create an API. Leave implementation details to the experts. Worry about your own model.