Presentation by Akira Amano

advertisement
Description Language of Calculation Scheme
for Automatic Simulation Code Generation
Akira Amano
College of Lifescience, Ritsumeikan University
CellML workshop
2012
1
HD Physiology Project
Project Leader: Prof. Y. Kurachi (Osaka Univ.)
2010-2015
http://hd-physiology.jp/
CellML workshop 2012
2
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
HD Physiology Project
• groups
– platform (Kitano (SBML), Asai (isML
– cardiac biology
– pharmacokinetics
PHML))
• integrate models of ...
– whole heart excitation propagation
– cell model including drug effect
– circulation model
– pharmacokinetics / pharmacodynamics
CellML workshop 2012
4
Characteristics of
Biological Function Models (from IT view)
Biological function simulations are different from
conventional models in:
• The complexity of the models
• Multiple scale and physics
(nano-sec, hour, Chemistry, dynamics, fluid ...)
CellML workshop 2012
5
Characteristics of
Biological Function Models (from IT view)
• The complexity of the model
• Multiple scale and physics
latest model
number of equations:
more than 400
number of variables:
more than 400
cardiac cell model
ion channels
ion transporters
contraction
mechanism
energy metabolism
CellML workshop 2012
6
Characteristics of
Biological Function Models
• The complexity of the model
• Multiple scale and physics
Simulation of the heart beat
fluid mechanics
structural mechanics
Coupling
Calculation
electrophysiology
chemical reaction
Coupling Calculation Scheme is usually built in in
the simulation tools. CellML workshop 2012
7
Software Crisis!
in 1970s:
Software size increased exponentially.
Large scale software project failed.
Merlin Dorfman
”Software Engineering”
IEEE, 1997.
Software Engineering
Structured Programming Languages
Integrated Software Tools
CellML workshop 2012
8
Software Engineering Tools for Complex
Biological Models
Efficient handling of complex models
⇒ use of Markup Languages
Cell physiological model
description
CellML
PHML
Field (Organ) model
description
FieldML
Systems Biology model
description
SBML
Declarative Description Models
CellML workshop 2012
9
Software Engineering Tools for Complex
Biological Models
Declarative description:
every equation is true at any time
not declarative
dx  f ( x)
x  x  dx  dt
declarative
dxt  f ( xt )
xt 1  xt  dxt  dt
• High flexibility
from mathematical description
combination of models, boundary cond.
• Avoiding bugs
by automatic processing of models
CellML workshop 2012
10
What to be supported
• 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 models
simulation software are developed manually
Our approach:
propose description language for
calculation methods
CellML workshop 2012
11
What to be supported
Method:
Designing declarative description of
coupling calculation schemes.
use recurrence relations
1. start from single model discretization
2. next consider coupling calculation
CellML workshop 2012
12
Single Model Input Equations
Lumped parameter models (ODE)
discretize in time
dx
x(t   )  x(t ) 

dt t t
Euler, Runge Kutta, ...
Distributed parameter models (PDE)
discretize in space (and time)
 xj 
2
x j 1  x j 1  2  x j
(x) 2
center difference, upwind difference, ...
CellML workshop 2012
13
Discretization
FTCS (forward time center space)
original model equation
dx
  2 x
dt
discretized equation
dx
x(t   )  x(t ) 

dt t t
x j 1 (t )  x j 1 (t )  2  x j (t )
dx
2
  x j (t )  
dt t t
(x) 2
CellML workshop 2012
14
Discretization
Crank-Nicolson
original model equation
dx
  2 x
dt
• we can separate discretization
scheme from calculation
method
discretized equation
2
x j (t   )  x j (t )
• calculation method becomes
complex


x j 1 (t   )  x j 1 (t   )  2  x j (t   )

(x) 2
x j 1 (t )  x j 1 (t )  2  x j (t )
(x) 2
CellML workshop 2012
15
Process of combining Model Equation with
Calculation Scheme
Model
Equations
Calculation
Scheme
CellML Compiler
CellML/
PHML
available at sourceforge
equation to program
easy! Recurrence
Executable
Relation
CPU, GPU
code
Equations
PC cluster, super computer (K?)
low efficiency but
high and safe productivity
TecML
Relation
(RelML)
1st step
2nd step
Variable Correspondence information between two files
CellML workshop 2012
16
Declarative Description of
Calculation Schemes
Single Model Calculation schemes:
1. mathematical relation between discretized
variables
2. 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, ...
CellML workshop 2012
17
Concept of Calculation Scheme Description
by Recurrence Relation
model equations
r  x3
dx/dt  k  -r
relation
  {x}
  {r}
time discretization
 0   init
TecML
n  ( n ,n )
 n   ( n ,n )
 n 1   n   n  
 end   n if (n  1000)
Recurrence relation
x[0]  xinit
RelML
  {k }
n  tn
n  1  t n 1
r[t n ]  x[t n ]
3
k[t n ]  -r[t n ]
x[t n 1 ]  x[t n ]  k[t n ]  δ
xend  x[t n ] if (t n  1000)
(declarative description)
1st step: generate recurrence relation from model equations
CellML workshop 2012
18
Concept of Calculation Scheme Description
by Recurrence Relation
Recurrence relation
x[0]  xinit
r[t n ]  x[t n ]
3
k[t n ]  -r[t n ]
x[t n 1 ]  x[t n ]  k[t n ]  δ
xend  x[t n ] if (t n  1000)
(declarative description)
Executable code
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];
2nd step: generate program to calculate recurrence relations
CellML workshop 2012
19
Experiments on FHN, LR-I
CellML workshop 2012
20
Coupling Calculation Schemes
Coupling calculation schemes:
1. also mathematical relation between discretized
variables in several models
2. calculation method of unknown variables
TecML
Description language to describe
•
coupling calculation scheme
cell model + mechanical model
convergence calculation
different time step models
CellML workshop 2012
21
Example: Double Time Loop
Physiologically based
Pharmacokinetic model calculation
time order: hour
time order: millisec
CellML workshop 2012
22
Example: Double Time Loop
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() );
CellML workshop 2012
23
Example: Double Time Loop
Recurrence relation
c[0] 1.0
Executable code
k c [t n ]  f1 (c[tn ], s[t n ])
c[tn 1 ]  c[tn ]  (kc [t n ]  1 )
cend  c[tn ] if (t n  1000)
s[t n ][0] s[t n 1 ]
while
loop
k s [t n ][tm ]  f 2 (c[tn ],inner
s[t n ][t
])
m
s[t n ][tm ]  s[t n ][tm ]  (ks [t n ][tm ]  δ 2 )
s[t n ]  s[t n ][tm ] if (t m  1000)
outer while loop
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];
CellML workshop 2012
24
Example: Convergence Calculation
The dynamic model of the simple heart
CellML1:Cardiac Cell Model
CellML2:Blood Circulation Model
CellML3:Heart Finite Element (FE) Model
CellML workshop 2012
25
Example: Convergence Calculation
CellML1:Cardiac Cell Model
CellML1: Cardiac Cell Model
dT/dt = kT = f1 (L, T)
CellML2:Blood Circulation Model
CellML2: Blood Circulation Model
dV/dt = kV = f3 (P)
CellML workshop 2012
26
Example: Convergence Calculation
CellML3:Heart Finite Element (FE) Model
CellML3: Heart FE Model
V= f4 (P, T)
L = f5 (V)
nP = fPnext (P, V, Vtarget, P1, P2)
nP1 = P
nP2 = P1
e = |V – Vtarget|
FE model can only calculate volume from pressure.
PLV is calculated by searching.
P2
fpnext(P1,P2)
V
V
CellML workshop
next 2012
target
P1
V1
27
T [0]  Tinit
Pr [t n ][0]  P[t n ]
V [0]  Vinit
P1r [t n ][0]  P[t n ]
P[0]  Pinit
kT [t n ]  f1 ( L[t n ],T [t n ])
kV [t n ]  f 3 ( P[t n ])
T [t n 1 ]  T [t n ]  (kT [t n ]   )
V [t n 1 ]  V [t n ]  (kV [t n ]   )
Tend  T [t n ] if (t n  1000)
Vend  V [t n ] if (t n  1000)
Recurrence relation
P2 r [t n ][0]  P[t n ]
Vr [t n ][t m ]  f 4 ( Pr [t n ][t m ],T [t n ])
Lr [t n ][t m ]  f 5 (Vr [t n ][t m ])
nP[t n ][t m ]  f Pnext ( Pr [t n ][t m ],Vr [t n ][t m ],
V [t n ], P1r [t n ][t m ], P2 r [t n ][t m ])
nP1[t n ][t m ]  Pr [t n ][t m ]
nP2 [t n ][t m ]  P1r [t n ][t m ]
er [t n ][t m ]  Vr [t n ][t m ]  V [t n ]
Pr [t n ][t m 1 ]  nP[t n ][t m ]
P1r [t n ][t m 1 ]  nP1[t n ][t m ]
P2 r [t n ][t m 1 ]  nP2 [t n ][t m ]
P[t n 1 ]  Pr [t n ][t m ] if (er [t n ][t m ]   )
L[t n 1 ]  Lr [t n ][t m ] if (er [t n ][t m ]   )
CellML workshop 2012
28
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));CellML workshop 2012
Tend=T[tn-1];
Vend=V[tn-1]:
Executable code
29
2nd step: calculation method
Coupling calculation schemes:
1. also mathematical relation between discretized
variables of several models
2. calculation method of unknown variables
current status:
•
order of calculating eqns are analyzed
•
partly DAE calculation is supported
(numerical differential method)
•
simple GPU support
CellML workshop 2012
30
advantages of our approach
1. use of declarative description is flexible in ...
combination of various models
combining with boundary conditions
2. two step approach
various target language / hardwares / libraries
language: C, C++, Java, Java BigDecimal
hardware: GPU, super computers
library: various math library
CellML workshop 2012
31
Example: parallel code (GPGPU)
Single CPU
CellML
Simulation
Program
Generator
C language
GPU
CUDA C
2D excitation propagation
(LR1)
CPU (core i7 880)
GPU (Tesla C2050)
GPU was 60 times faster than
single CPU
We can use any cell model to
generate GPGPU 2D excitation
propagation
program.
The 1st HD Physiology
International Symposium 20th Jan,
32
current project webpage
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
CellML workshop 2012
33
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
Download