1
Cupid A Domain Specific Language
for Coupled ESMs
Rocky DunlapCoupling Workshop 2013
Second Workshop on Coupling Technologies for Earth System ModelingNCAR, Boulder, Colorado, February 20-22, 2013
2
Outline
• Motivation and Goals of Cupid• Overview and Current Status• Example Application• Evaluation and Challenges• Future Work
3
Motivation and Goals• Earth System Modeling software is highly
complex• Much effort is spent dealing with accidental
details of parallel programming, array manipulations, etc.
• Goal of Cupid:
Provide significant increases in modeler productivity by raising the level of abstraction of
the coupling aspects of ESMs.
4
Different Kinds of Performance
# of nodes
days simulatedper hour
paperspublished
hours of effort
model scalabilitymodeler productivity
5
Form of Reuse Programming Tasks Example TechnologiesSoftware Libraries
Instantiate library types; call library subroutines
MCT, PSMILe (OASIS), OASIS-MCT
Component Technologies
Write explicit interfaces; implementation via traditional programming; composition via interface “wiring”
CCA
Frameworks Same as library + implement fine-grained, pre-defined interfaces (due to inversion of control)
ESMF, CSDMS, OpenPALM
Generative/ Domain-specific languages
Programs written in a custom language with domain-specific concepts; textual or visual notations
BFG XML, PrePALM (OpenPALM), Cupid
How does the form of code reuse affect developer productivity?
6
General Purpose Language (Fortran 90)
programmodule
if, then, else, endifdo, do while
callinteger, real, double precision
dimensionopen, read
continue, stop
Domain Specific Language
gridded componentcoupler component
driverstate
decompositiongrid, mesh
fieldredist, regrid
clock
7
Cupid Overview
Coupling Specification(Cupid DSL)
Black box
Generated Application(Fortran 90)
ExecutableCupid
CompilerFortran
Compiler
White box
Maintenance Maintenance
ESMF
link
Black boxBlack boxBlack box
8
Domain Model and Constraints class Superstructure
ESMFCouplerComponentESMFSimpleCouplerComponentESMFGriddedComponent
ESMFScope
ESMFNamedEntityESMFComponent
Infrastructure::ESMFScopedItem
Infrastructure::ESMFField
Infrastructure::ESMFStateItem
ESMFFieldConnection«invariant»{srcField must be contained in srcComponent;dstField must be contained in dstComponent}
dstComponent
1
srcComponent
1
*
children
*
1..*
srcField dstField
self.fieldConnection->forAll(srcField.scope = self.srcComponent and dstField.scope = self.dstComponent)
9
Cupid Compiler[template public genESMFInitMethod(c : ESMFGriddedComponent)]subroutine init_(comp, istate, ostate, clock, rc)type(ESMF_GridComp) :: comptype(ESMF_State) :: istatetype(ESMF_State) :: ostatetype(ESMF_Clock) :: clockinteger, intent(out) :: rc
...[for (field : ESMFField | c.item->filter(ESMFField))][field.name/] = ESMF_FieldCreate(grid=[field.grid.name/], arrayspec=[field.arraySpec.name/], & indexflag=[field.index/], & totalLWidth=[toFortranArrayConstructor(field.totalLWidth)/], & totalUWidth=[toFortranArrayConstructor(field.totalUWidth)/], & name="[field.name/]", rc=rc)[/for]...[/template] MOF Model to Text
Transformation Language (OMG)http://www.omg.org/spec/MOFM2T/1.0/
10
Eclipse-based ImplementationEclipse Modeling Framework
Ecore Metamodel
Acceleo Model to Text
Photran Editor
11
Current StatusESMF Type Public API Methods DSL Generated Calls
ESMF_Array 22 2
ESMF_ArraySpec 4 1
ESMF_Clock 20 2
ESMF_CplComp 24 5
ESMF_DistGrid 10 1
ESMF_Field 27 9
ESMF_Grid 18 3
ESMF_GridComp 24 6
ESMF_State 18 4
ESMF_Time 16 1
ESMF_TimeInterval 18 2
(Framework level) 25 2
(12 Unsupported types) 161 0
387 38
Calls can be generated to ~10% of API
methods.
11 of 23 ESMF types
represented in DSL.
12
CFlowDriv
er
CoupledFlowMod
FlowSolverM
od
InjectorM
od
CouplerMod
0
100
200
300
400500
600
700
800
900
1000
Lines of CodeGenerated and Hand Coded
Generated Skeleton
Complete (Generated + Hand Coded)
Line
s of C
ode
CFlowDriver
CoupledFlow
FlowSolver Coupler Injector
Case Study:ESMF Coupled
Flow Demo
13
Caution: Some coding required!
Un-touched, 487, 35%
Inserted, 865, 63%
Modified, 31, 2%
Lines of Code
Inserted Code• reading namelists,
setting parameters• set up initial conditions
and boundary conditions
• field updates for each timestep
• calls to halo operations
Generated Code• static superstructure• instantiation of
components, states, and fields
• populating import and export states
• calls to child components
• coupler component (redist or regrid)
• freeing memory
Modified Code• grid coordinates• grid inheritance
14
Challenge: DSL Integration• How to integrate with scientific code?• Possible solutions:
– Skeleton approach• Developer fills in science implementation
– Model interface approach• A set of Fortran subroutines with model fields as
subroutine arguments (à la BFG)• Define interfaces using Scientific Interface Description
Language (SIDL)• Self-describing models (à la CSDMS BMI)
15
Challenge: Representing Behavior
• Static structural aspects are fairly easy to model– Parent-child relationship of components
• Behavioral (dynamic) aspects are more difficult– Populating an ESMF State object with different fields
during different points of model execution• Possible solutions
– make behaviors implicit (e.g., all fields added during init, remain unchanged during run, removed during finalize)
– introduce a behavioral modeling language (adds complexity!)
16
Conclusion
SuperstructureComponents and their composition; driving
ScienceField updates based on discrete form of PDEs
InfrastructureBuilding blocks: grids, distributed fields, clocks,
regrid, redistribution, I/O, configuration, etc.
Different approaches and different tools are required to
raise the abstraction level of each of these
parts.
DSL approach is viable for specifying some parts of the coupling infrastructure.
17
Future Work• Cupid: An IDE for Model Development and Modeler
TrainingNASA Computational Modeling Algorithms and Cyberinfrastructure (CMAC) Program
• Team– Georgia Institute of Technology (Dunlap/Mark/Rugaber)– University of Colorado/CIRES (DeLuca)– NASA Software Systems Support Office (Clune)– NASA GISS (Schmidt)
• Extend and harden existing DSL+generator into a student training environment for rapidly developing ESMF-based applications
• Incorporate more IDE features, including linking with an execution environment
• Modularize Model E and demonstrate in IDE
18
Thanks!
19
20
Domain Specific LanguagesIncrease Productivity
• Nokia [1] mobile phone app development – 1000% increase in productivity– “shift focus from code to design”– “In many cases, we can generate 100% of the required code.”
• US Air Force Military Command and Control Systems [2]– 300% increase in productivity
• Lucent Product Family development [3]– initial productivity factor 3x-5x; 10x productivity increase for
experts– graphical DSLs more successful than textual
21
Reuse Techniques
System Specification
Generator
Compositional(library, components, frameworks)
Generative(domain-specific languages)
2222
CouplingSpecification
Generator
Hybrid Approach
23
Challenge: Domain Model
• There is no universal domain model for coupling– SQL came about after a formal definition of
relational databases– Common Information Model (CIM) currently
defined as retrospective metadata– Jay Larson’s theory of coupling [4]
24
Domain Model
Analysis
Strembeck, Mark, and Uwe Zdun. "An approach for the systematic development of domain‐specific languages." Software: Practice and Experience 39.15 (2009): 1253-1292.
Earth System Modeling
Framework(ESMF)
Core Language Model
Language Model Constraints
Behavioral Model
Approach: Extract DSL from an existing system
25
You Have Already Used DSLsDSL Use
SQL Query and manipulate relational databases
Make, Ant Building software systems
Matlab Scientific data analysis
HTML Markup for web pages
YACC, ANTLR Parser generators
LATEX Typesetting
LabVIEW Design of measurement and control systems
26
What kinds of domains benefit from DSLs?
Sprinkle, Jonathan, et al. "Guest Editors' Introduction: What Kinds of Nails Need a Domain-Specific Hammer?." IEEE Software 26.4 (2009): 15-18.
The domain is well-defined 40+ years of building coupled models
The domain has repetitive elements or patterns, such as multiple products, features, or targets
Emergence of reusable coupling software evidences common coupling requirements, designs, implementations
Accuracy; expert involvement; and flexibility of the specification, verification, and validation of design are important
Correct and verifiable coupling infrastructure is essential for scientific validity of model output
The implementation or specification must serve as documentation
Many ESMs are under-documented and often the code itself is the documentation.
Amortization of effort justifies investment in DSL creation.
Payoffs in terms of productivity increases when implementing new couplings
Domain characteristic Evidence in ESM domain
27
Core Language Model pkg Superstructure
ESMFComponent
ESMFCouplerComponentESMFGriddedComponent
ESMFWorkspace
ESMFNamedEntity
ESMFScope
ESMFSimpleCouplerComponent
ESMFDriv er
ESMFFieldConnection
Infrastructure::ESMFScopedItem
*
*
children
srcComponent
1
dstComponent
1
1..*
*
28
Core Language Model pkg Infrastructure
ESMFGrid
ESMFStateItem
ESMFField ESMFArray
ESMFDistGrid
ESMFState
ESMFScopedItem
ESMFClock
ESMFArraySpec ESMFRouteHandle ESMFTimeESMFTimeInterval
Superstructure::ESMFScope
*
*1
*
*
1
1 1* 1
29
Object Constraint Language class Superstructure
ESMFCouplerComponentESMFSimpleCouplerComponentESMFGriddedComponent
ESMFScope
ESMFNamedEntityESMFComponent
Infrastructure::ESMFScopedItem
Infrastructure::ESMFField
Infrastructure::ESMFStateItem
ESMFFieldConnection«invariant»{srcField must be contained in srcComponent;dstField must be contained in dstComponent}
dstComponent
1
srcComponent
1
*
children
*
1..*
srcField dstField
self.fieldConnection->forAll(srcField.scope = self.srcComponent and dstField.scope = self.dstComponent)
30
Implementation – Language Model
• Language model using Eclipse-based tools– classes, generalization/
specialization, abstract classes– type system– object references,
containment– OCL constraints via
annotations– automatic generation of
model editor GUI
31
References1. Kelly, Steven, and Juha-Pekka Tolvanen. "Visual domain-specific modeling: Benefits
and experiences of using metaCASE tools." International workshop on Model Engineering, European Conference on Object-Oriented Programming (ECOOP) ed. J. Bezivin, J. Ernst. 2000.
2. Kieburtz, Richard B., et al. "A software engineering experiment in software component generation." Proceedings of the 18th international conference on Software engineering. IEEE Computer Society, 1996.
3. Weiss, D. M., and C. T. R. Lai. "Software product line engineering: a family based software engineering process." (1999).
4. J. Walter Larson, "Ten organising principles for coupling in multiphysics and multiscale models," ANZIAM J., 48, C1090-C1111 (2009).