34
Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML workshop 2012

Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Embed Size (px)

Citation preview

Page 1: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Description Language of Calculation Scheme for Automatic Simulation Code Generation

Akira Amano

College of Lifescience, Ritsumeikan University

1CellML workshop

2012

Page 2: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

CellML workshop 2012 2

HD Physiology Project

Project Leader: Prof. Y. Kurachi (Osaka Univ.)2010-2015http://hd-physiology.jp/

Page 3: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

HD Physiology Project

• Japanese title of this project“Integrative Multi-level Systems Biology for …”

• target– Multiscale in Biology– construct comprehensive simulation model of

drug induced heart arrhythmia

CellML workshop 2012 3

Page 4: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

HD Physiology Project

• groups– platform (Kitano (SBML), Asai (isML PHML))– cardiac biology– pharmacokinetics

• integrate models of ...– whole heart excitation propagation– cell model including drug effect– circulation model– pharmacokinetics / pharmacodynamics

CellML workshop 2012 4

Page 5: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Biological function simulations are different from conventional models in:

• The complexity of the models• Multiple scale and physics (nano-sec, hour, Chemistry, dynamics, fluid ...)

Characteristics ofBiological Function Models (from IT view)

5CellML workshop 2012

Page 6: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

• The complexity of the model• Multiple scale and physics

cardiac cell modelion channels

energy metabolism

ion transporters

contractionmechanism

latest model    number of equations :        more than 400    number of variables :        more than 400

Characteristics ofBiological Function Models (from IT view)

6CellML workshop 2012

Page 7: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

• The complexity of the model• Multiple scale and physics

Characteristics ofBiological Function Models

Coupling Calculation Scheme is usually built in in the simulation tools.

fluid mechanicsstructural mechanics

chemical reactionelectrophysiology

Coupling Calculation

Simulation of the heart beat

7CellML workshop 2012

Page 8: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Software Crisis!

CellML workshop 2012 8

Merlin Dorfman”Software Engineering”IEEE, 1997.

in 1970s: Software size increased exponentially. Large scale software project failed.

Software Engineering Structured Programming Languages Integrated Software Tools

Page 9: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Efficient handling of complex models⇒ use of Markup Languages

Software Engineering Tools for Complex Biological Models

9CellML workshop 2012

CellML FieldML

PHML

SBML

Cell physiological model description

Field (Organ) modeldescription

Systems Biology modeldescription

Declarative Description Models

Page 10: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Declarative description: every equation is true at any time

• High flexibility from mathematical description

combination of models, boundary cond.• Avoiding bugs by automatic processing of models

Software Engineering Tools for Complex Biological Models

10CellML workshop 2012

not declarative declarative

dtdxxx

xfdx

)(

dtdxxx

xfdx

ttt

tt

1

)(

Page 11: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

• Lumped parameter models (ODE)simulation tools and markup languages

CellML, ...

calculation methods are simple (usually builtin)

• Distributed parameter models (PDE)simulation tools and markup languages (complex)

FieldML?, ...

calculation methods are complex

no general simulation software?

• Coupling simulation modelssimulation software are developed manually

Our approach: propose description language for calculation methods

What to be supported

CellML workshop 2012 11

Page 12: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Method: Designing declarative description of coupling calculation schemes.

use recurrence relations

1. start from single model discretization2. next consider coupling calculation

What to be supported

12CellML workshop 2012

Page 13: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Lumped parameter models (ODE)discretize in time

Euler, Runge Kutta, ...

Distributed parameter models (PDE)discretize in space (and time)

center difference, upwind difference, ...

Single Model Input Equations

13CellML workshop 2012

ttdt

dxtxtx )()(

2

112

)(

2

x

xxxx jjj

j

Page 14: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

FTCS (forward time center space) original model equation

discretized equation

Discretization

14CellML workshop 2012

xdt

dx 2

2

112

)(

)(2)()()(

)()(

x

txtxtxtx

dt

dx

dt

dxtxtx

jjjj

tt

tt

Page 15: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Crank-Nicolson original model equation

discretized equation

Discretization

15CellML workshop 2012

xdt

dx 2

2

11

2

11

)(

)(2)()(

)(

)(2)()(

)()(2

x

txtxtx

x

txtxtx

txtx

jjj

jjj

jj

• calculation method becomes complex

• we can separate discretization scheme from calculation method

Page 16: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

CellML/PHML

TecML

Relation(RelML)

Process of combining Model Equation with Calculation Scheme

Recurrence RelationEquations

CalculationScheme

ModelEquations

Variable Correspondence  information between two files

Executable code

1st step 2nd step

16CellML workshop 2012

CellML Compileravailable at sourceforge

equation to programeasy! CPU, GPU PC cluster, super computer (K?)low efficiency buthigh and safe productivity

Page 17: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Single Model Calculation schemes:1. mathematical relation between discretized

variables2. calculation method of unknown variables

TecML(Time Evolution Calculation Markup Language): Description language to describe

• time evolution calculation method Euler, RungeKutta …

• spatial difference scheme center difference, upwind difference, ...

Declarative Description of Calculation Schemes

17CellML workshop 2012

Page 18: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

model equations

time discretization

-rkdx/dt

xr

3

Concept of Calculation Scheme Description by Recurrence Relation

18CellML workshop 2012

1000) (n  if  

     

),(

),( 

 

nend

n1n

n

n

0

n

nn

nn

init

11

}{

}{

}{

n

n

tn

tn

k

r

x

relation Recurrence relation

)1000(if][

][][][

][][

][][

]0[

1

3

nnend

nnn

nn

nn

init

t txx

δtktxtx

t -rtk

txtr

xx

(declarative description)

1st step: generate recurrence relation from model equations

TecML

RelML

Page 19: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Recurrence relation Executable code

2nd step: generate program to calculate recurrence relations

x[0] = xinit;tn=0;do{ r[tn] = x[tn]*x[tn]*x[tn]; k[tn] = - r[tn]; x[tn+1] = x[tn] + k[tn] * delta; tn = tn + 1;} while(!((tn-1) == 1000));xend = x[tn-1];

Concept of Calculation Scheme Description by Recurrence Relation

19CellML workshop 2012

(declarative description)

)1000(if][

][][][

][][

][][

]0[

1

3

nnend

nnn

nn

nn

init

t txx

δtktxtx

t -rtk

txtr

xx

Page 20: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

CellML workshop 2012 20

Experiments on FHN, LR-I

Page 21: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Coupling Calculation Schemes

21CellML workshop 2012

Coupling calculation schemes:1. also mathematical relation between discretized

variables in several models2. calculation method of unknown variables

TecML Description language to describe

• coupling calculation scheme cell model + mechanical model convergence calculation different time step models

Page 22: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Example: Double Time LoopPhysiologically based Pharmacokinetic model calculation

22

time order: hour

time order: millisec

CellML workshop 2012

Page 23: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

do { dose concentration calculate whole body model with large time step

do { concentration cell state calculate each cell model with small time step

} while ( !time1end() ); } while ( !time2end() );

Example: Double Time Loop

CellML workshop 2012 23

Page 24: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Recurrence relation Executable code

1000)  (t if]c[t  c

)  ][t(k   ]c[t  ]c[t

])s[t ],(c[tf  ][tk

1.0  c[0]

nnend

1ncn1n

nn1nc

c[0] = 1.0;tn=0;do { s[tn][0] = s[tn-1]; tm = 0; do { ks[tn][tm] = f2(c[tn],s[tn][tm]); s[tn][tm+1] = s[tn][tm] + ks[tn][tm]*delta1; tm++; } while (!(tm-1)==1000); s[tn] = s[tn][tm]; kc[tn] = f1(c[tn],s[tn]); c[tn+1] = c[tn] + kc[tn]*delta2; tn = tn + 1;} while(!((tn-1) == 1000));cend = c[tn-1];

Example: Double Time Loop

24

1000)  (t if]][ts[t]s[t

)δ  ]][t[t(k   ]][ts[t  ]][ts[t

])][ts[t ],(c[tf  ]][t[tk

 ]s[t  ][0]s[t

mmnn

2mnsmnmn

mnn2mns

1nn

outer while loopouter while loop

inner while loopinner while loop

CellML workshop 2012

Page 25: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

CellML1:Cardiac Cell ModelCellML2:Blood Circulation ModelCellML3:Heart Finite Element (FE) Model

Example: Convergence Calculation

The dynamic model of the simple heart

25CellML workshop 2012

Page 26: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

CellML1:Cardiac Cell Model

Example: Convergence Calculation

26CellML workshop 2012

CellML1: Cardiac Cell ModeldT/dt = kT = f1 (L, T)

CellML2:Blood Circulation ModelCellML2: Blood Circulation Model

dV/dt = kV = f3 (P)

Page 27: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Example: Convergence Calculation

27CellML workshop 2012

CellML3:Heart Finite Element (FE) ModelCellML3: Heart FE ModelV= f4 (P, T)L = f5 (V)nP = fPnext (P, V, Vtarget, P1, P2)nP1 = PnP2 = P1

e = |V – Vtarget|

FE model can only calculate volume from pressure.PLV is calculated by searching.

P1P2fpnext(P1,P2)

V1Vnext Vtarget

Page 28: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

)1000(][

)1000(][

)][(][][

)][(][][

])[(][

])[],[(][

]0[

]0[

]0[

1

1

3

1

nnend

nnend

nVnn

nTnn

nnV

nnnT

init

init

init

tiftVV

tiftTT

tktVtV

tktTtT

tPftk

tTtLftk

PP

VV

TT

)]][[(]][[][

)]][[(]][[][

]][[]][[

]][[]][[

]][[]][[

][]][[]][[

]][[]][[

]][[]][[

])][[],][[],[

],][[],][[(]][[

])][[(]][[

])[],][[(]][[

][]0][[

][]0][[

][]0][[

1

1

212

111

1

12

1

21

5

4

2

1

mnrmnrn

mnrmnrn

mnmnr

mnmnr

mnmnr

nmnrmnr

mnrmn

mnrmn

mnrmnrn

mnrmnrPnextmn

mnrmnr

nmnrmnr

nnr

nnr

nnr

tteifttLtL

tteifttPtP

ttnPttP

ttnPttP

ttnPttP

tVttVtte

ttPttnP

ttPttnP

ttPttPtV

ttVttPfttnP

ttVfttL

tTttPfttV

tPtP

tPtP

tPtP

           

28CellML workshop 2012

Recurrence relation

Page 29: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Executable code

T[0]=Tinit;V[0]=Vinit;P[0]=Pinit;tn = 0;do{ Pr[tn][0]=P[tn]; P1r[tn][0]=P[tn]; P2r[tn][0]=P[tn]; tm = 0; do{ Vr[tn][tm]=f4(Pr[tn][tm],T[tn]); Lr[tn][tm]=f5(Vr[tn][tm]); nPr1[tn][tm]=fPnext((Pr[tn][tm],Vr[tn][tm],

V[tn],P1r[tn][tm],P2r[tn][tm]); nP1r1[tn][tm]=Pr[tn][tm]; nP2r1[tn][tm]=P1r[tn][tm]; er[tn][tm]=|Vr[tn][tm]-V[tn]|; Pr[tn][tm+1]=nPr1; P1r[tn][tm+1]=nP1r1; P2r[tn][tm+1]=nP2r1; tm = tm + 1; }while(!((er[tn][tm-1])<epsilon)); P[tn]=Pr[tn][tm-1]; L[tn]=L[rtn][tm-1]; dTdt0[tn]=f1(L[tn],T[tn]); dVdt0[tn]=f3(P[tn]); T[tn+1]=T[tn]+(dTdt0[tn]*delta); V[tn+1]=V[tn]+(dVdt0[tn]*delta); tn = tn + 1;}while(!((tn-1)==1000));Tend=T[tn-1];Vend=V[tn-1]:

29CellML workshop 2012

Page 30: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

2nd step: calculation method

30CellML workshop 2012

Coupling calculation schemes:1. also mathematical relation between discretized

variables of several models2. calculation method of unknown variables

current status:• order of calculating eqns are analyzed• partly DAE calculation is supported (numerical differential method)• simple GPU support

Page 31: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

advantages of our approach

31CellML workshop 2012

1. use of declarative description is flexible in ...combination of various modelscombining with boundary conditions

2. two step approachvarious target language / hardwares / libraries language: C, C++, Java, Java BigDecimal hardware: GPU, super computers library: various math library

Page 32: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Example: parallel code (GPGPU)

32

2D excitation propagation (LR1)

GPU was 60 times faster than single CPUWe can use any cell model to generate GPGPU 2D excitation propagation program.

CellMLSimulationProgram

Generator

C languageC language

CUDA CCUDA C

Single CPU

GPU

CPU (core i7 880)GPU (Tesla C2050)

The 1st HD Physiology International Symposium 20th

Jan, 2012

Page 33: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

CellML workshop 2012 33

available at sourceforge (http://sourceforge.net/projects/cellmlcompiler/)• only single model time discretization available

• Euler, Runge Kutta (explicit method only)• fixed geometry excitation propagation with GPU

current project webpage

Page 34: Description Language of Calculation Scheme for Automatic Simulation Code Generation Akira Amano College of Lifescience, Ritsumeikan University 1 CellML

Summary

• Declarative description models are useful for simulation with complex models.– CellML, SBML, FieldML, PHML, ...

• Declarative description of coupling calculation scheme– proposed: TecML

• With declarative description coupling calculation scheme, simulation program can be generated with high flexibility.– various boundary conditions– parallel code for super computers

CellML workshop 2012 34