SlideShare a Scribd company logo
Σ   YSTEMS


Optimal control of coupled PDE networks
    with automated code generation

            Dimitrios Papadopoulos
         Delta Pi Systems, Thessaloniki



          ICNAAM 2012, Kos, Greece




                                          1 / 23
Overview
  ◮   Application of PDE Networks
  ◮   Representation of PDE Networks as a Graph
  ◮   Optimal Control of PDEs
        ◮   Adjoint Equations and Gradient
        ◮   Continuous vs. Discrete Adjoint Approach
        ◮   Discretization of the control variables
  ◮   Flowchart
  ◮   Tools of the Trade
        ◮   DOT Language and PyDot
        ◮   SymPy
        ◮   Cog
        ◮   SfePy
        ◮   SciPy (and NumPy)
  ◮   Conclusions



                                                       Dimitris Papadopoulos — Delta Pi Systems


                                                                                        2 / 23
Application of PDE Networks




                              Dimitris Papadopoulos — Delta Pi Systems


                                                               3 / 23
Representation of PDE Networks as a Graph

                                       3



                              1                  2

         ∂y1
             + ∇ · (a · y1 ) − ∇ · (D∇yi ) = f (y1 , y2 , y3 ; u)
         ∂t
         ∂y2
             + ∇ · (a · y2 ) − ∇ · (D∇yi ) = f (y2 , y1 , y3 ; u)
         ∂t
            ∂y3
                + ∇ · (a · y3 ) − ∇ · (D∇yi ) = g(y3 , y1 ; u)
             ∂t



                                                             Dimitris Papadopoulos — Delta Pi Systems


                                                                                              4 / 23
Optimal Control of PDEs
Problem formulation
                                          t1
                  min J(y, u) =                        φ(y, u) dxdt subject to:
                    u                 0            Ω
           ∂yi
                + ∇ · (a · yi ) − ∇ · (D∇yi ) = fi , for i = 1, . . . , nn ,
            ∂t
where yi are the state variables, and y the state vector,
ui are the control variables, and u the control vector,
fi is a function of some yj and u,
nn is the number of nodes.

Lagrange function

                             nn       t1
                                                       ∂yi
min L(y, u, p) = J(y, u)+                          (       −fi )pi +(ayi −D∇yi )·∇pi dxdt+BC
 y,u
                            i=1   0            Ω       ∂t

where pi are the Lagrange multipiers or adjoint variables                  Dimitris Papadopoulos — Delta Pi Systems


                                                                                                            5 / 23
Optimal Control of PDEs (cont.)
Adjoint Equations

                                                       n   n
    ∂pi                                                  ∂fj
−       − ∇ · (a · pi ) − ∇ · (D∇pi ) = φyi (y, u) +         pi ,         for i = 1, . . . , nn ,
    ∂t                                               j=1
                                                         ∂yi


Gradient
                                   n    n        t1
                         ∂L   ∂J                          ∂fi
                            =    +                            pi dxdt
                         ∂u   ∂u i=1         0        Ω   ∂u




                                                                        Dimitris Papadopoulos — Delta Pi Systems


                                                                                                         6 / 23
Continuous vs. Discrete Adjoint
            nonlinear       linear     adjoint


   PDE




discrete
equations




                                     Dimitris Papadopoulos — Delta Pi Systems


                                                                      7 / 23
Back to the basics
                          ∂L        ∂L
How do you calculate      ∂u
                               or   ∂y
                                       ?
  ◮   Calculate analytical derivatives and implement them by hand (too time
      consuming and error prone)
  ◮   Symbolic differentiation (you have to add some code generation magic)
  ◮   Automatic (or algorithmic) differentiation (for each new problem you have
      to pass your code through your AD-tool)




                                                           Dimitris Papadopoulos — Delta Pi Systems


                                                                                            8 / 23
Discretization of the control variables
  ◮   B-spline basis functions

                       1 if τi−1 ≤ t < τi
           Ni0 (t) =                      ,
                       0 else
            n          t − τj−1      n−1     τj+n − t n−1
           Nj (t) =               Nj (t) +           N    (t),             n>1
                    τj+n−1 − τj−1           τj+n − τj j+1
  ◮   B-spline curve formed by control points ci
                                          L
                                                    n
                                 u(t) =         cj Nj (t)
                                          j=0




                                                            Dimitris Papadopoulos — Delta Pi Systems


                                                                                             9 / 23
Parametrization - Finding a knot sequence
  ◮   uniform or equidistant

                               (ti − ti−1 )/(ti+1 − ti ) = 1

  ◮   chord length
                                    ∆ti      ||∆di ||
                                         =
                                   ∆ti+1   ||∆di+1 ||
  ◮   cetripetal
                                                        1/2
                                 ∆ti      ||∆di ||
                                      =
                                ∆ti+1   ||∆di+1 ||
  ◮   Natural end conditions

                                ¨
                                u(t0 ) = 0,   ¨
                                              u(tm ) = 0




                                                               Dimitris Papadopoulos — Delta Pi Systems


                                                                                               10 / 23
Tensor Product Patches
  ◮   B-spline surface
                                         m   n
                         um,n (t, x) =             ci,j Nim (t)Nj (x)
                                                                n

                                         i=0 j=0

      where ci,j is a matrix representing all the control points of the (t, x) plane.
  ◮   A surface with the topology of a sphere is not representable as a tensor
      product surface, without degeneracies (but we don’t really care)




                                                                   Dimitris Papadopoulos — Delta Pi Systems


                                                                                                   11 / 23
Flowchart
   parse DOT graph


   build symbolic PDEs

                                                       initialize control points
   build symbolic adjoint PDEs
                                                        k    1                      k     k+1

    build symbolic gradient
                                                       solve direct problem

    generate source code for solution of PDEs
                                                       objective function                compute gradient
   generate source code for solution of adjoint PDEs

                                                                          no
                                                                  k
   generate source code for gradient                          J <ε                      solve adjoint problem

                                                            yes

                                                             solution




                                                                                   Dimitris Papadopoulos — Delta Pi Systems


                                                                                                                   12 / 23
Tools of the Trade

                       Extended DOT Language


                     Direct              Adjoint




                                        SymPy




                      Cog                 Cog




                     SfePy               SfePy




                               SciPy

                                                   Dimitris Papadopoulos — Delta Pi Systems


                                                                                   13 / 23
DOT Language
A DSL for graph representation

   digraph network {
     3->1 [type=1];
     3->2 [type=1];
     1->2 [style=dashed, type=2];
     2->1 [style=dashed, type=2];
     1->3 [style=dotted, type=3];
     3 [shape=box];}


                                 3



                          1          2
                                         Dimitris Papadopoulos — Delta Pi Systems


                                                                         14 / 23
Why Python?
 ◮   programmer’s time vs. computing time
 ◮   need for manipulation of the objects at runtime
 ◮   need for source code generation at runtime
 ◮   lisp, smalltalk, perl, python, ruby, javascript vs. C, C++, java
 ◮   Paul Graham’s classical closure example of the accumulator:
     def foo(n):
       s = [n]
       def bar(i):
          s[0] += i
          return s[0]
       return bar

 ◮   many tools and numerical libraries available




                                                             Dimitris Papadopoulos — Delta Pi Systems


                                                                                             15 / 23
PyDot
A Python library for the DOT language

   import pydot
   graph = pydot.graph_from_dot_file(’test.dot’)
   shape_dict = {}
   function_dict = {}
   for node in graph.get_nodes():
       my_name = node.get_name()
       shape_dict[my_name] = node.get(’shape’)
       function_dict[my_name] = node.get(’function’)
   type_dict = {}
   style_dict = {}
   for edge in graph.get_edges():
       my_edge = (edge.get_source(), edge.get_destination())
       type_dict[my_edge] = edge.get(’type’)
       style_dict[my_edge] = print edge.get(’style’)

                                               Dimitris Papadopoulos — Delta Pi Systems


                                                                               16 / 23
SymPy
A Python library for symbolic mathematics

   from sympy import Eq, Function, Symbol
   from sympy import Derivative as D, Integral
   from sympy.abc import x, t, a

   y_list = [] # same for u_list
   for node in graph.get_nodes():
       my_name = node.get_name()
       y_list.append(’y_’+str(my_name)) # same for u_list
   y = map(Function, y_list) # same for u_list
   f = y[1]+u # for example
   eq = Eq(D(y[1](x,t),t)+a*D(y[1](x,t),x)-D(D(y[1](x,t),x),x),f)




                                                 Dimitris Papadopoulos — Delta Pi Systems


                                                                                 17 / 23
SymPy (cont.)
Derivative of the Lagrangian
 1. Build list of symbols for functions,
 2. build a list of substitutions for the functions and the reverse,
 3. substitute for the functions,
 4. run derivatives with respect to the symbols,
 5. substitute functions for the symbols,
 6. take any derivatives with respect to the function variables.

Integral(Derivative(F.subs(u(x),foo),foo).doit().subs(foo,←֓
                                                   u(x))*v(x),x)




                                                              Dimitris Papadopoulos — Delta Pi Systems


                                                                                              18 / 23
Cog
A code generation tool

      ...
      # [[[cog
      # import cog
      # functions = [direct, adjoint, gradient]
      # for func in functions:
      #     cog.outl("def %s():" % func)
      #     cog.outl("    pass")
      # ]]]
      # [[[end]]]
      ...




                                                  Dimitris Papadopoulos — Delta Pi Systems


                                                                                  19 / 23
SfePy
A software for solving systems of coupled PDEs by the FEM
  ◮   SfePy: Simple finite element in python
  ◮   Other alternatives: FENICS or your favorite FE solver (needs to be general
      enough)
  ◮   Future work: bring metaprogramming to the next level, i.e.,
  ◮   use FENICS, which generates C++ at runtime from the problem
      formulation which can also be run parallel




          graph           symbolic      intermediated    parallel
      representation   representation    python code    C++ code




                                                            Dimitris Papadopoulos — Delta Pi Systems


                                                                                            20 / 23
SciPy (and NumPy)
A library for doing everything else

import numpy as np
from scipy.optimize import fmin_bfgs

from newly_created_file import objective, gradient

c0 = np.array([0.0, 0.0, 0.0, 0.0])
res = fmin_bfgs(objective, c0, gradient, args, gtol, norm, ...)


and the rest is a piece of cake!




                                               Dimitris Papadopoulos — Delta Pi Systems


                                                                               21 / 23
Conclusions
Summary
  ◮   Framework for optimal control of coupled PDE networks
  ◮   Automated code generation
  ◮   Graph representation of coupled PDEs
  ◮   Symbolic differentiation for the adjoint equations and the gradient
  ◮   Solution with the finite element method

Outlook
  ◮   Extention to more general equations,
  ◮   with 2D or 3D geometries,
  ◮   and constraints on the state or control variables.
  ◮   Adaptive refinement of the control variables.



                                                            Dimitris Papadopoulos — Delta Pi Systems


                                                                                            22 / 23
Thank you for your attention!




Delta Pi Systems
Thessaloniki, Greece
http://www.delta-pi-systems.eu




                                 Dimitris Papadopoulos — Delta Pi Systems


                                                                 23 / 23

More Related Content

PDF
Ada boost brown boost performance with noisy data
PDF
Label propagation - Semisupervised Learning with Applications to NLP
PDF
Rousseau
ODP
Derivative Free Optimization
PDF
The multilayer perceptron
PDF
Optimalpolicyhandout
PDF
Case Study (All)
PDF
On estimating the integrated co volatility using
Ada boost brown boost performance with noisy data
Label propagation - Semisupervised Learning with Applications to NLP
Rousseau
Derivative Free Optimization
The multilayer perceptron
Optimalpolicyhandout
Case Study (All)
On estimating the integrated co volatility using

What's hot (20)

PDF
Learning Sparse Representation
PDF
Signal Processing Course : Sparse Regularization of Inverse Problems
PPTX
PDF
11.solution of linear and nonlinear partial differential equations using mixt...
PDF
Solution of linear and nonlinear partial differential equations using mixture...
PDF
Andreas Eberle
PDF
Digital Signal Processing[ECEG-3171]-Ch1_L02
PDF
Lecture on nk [compatibility mode]
PDF
Estimation of the score vector and observed information matrix in intractable...
PDF
Geodesic Method in Computer Vision and Graphics
PDF
Signal Processing Course : Inverse Problems Regularization
PDF
EM algorithm and its application in probabilistic latent semantic analysis
PDF
Discrete Models in Computer Vision
PDF
Biomathematics
PDF
Neural Processes
PDF
Tele4653 l4
PDF
Spectral Learning Methods for Finite State Machines with Applications to Na...
PDF
Mesh Processing Course : Active Contours
PDF
Paris2012 session1
PDF
Olivier Cappé's talk at BigMC March 2011
Learning Sparse Representation
Signal Processing Course : Sparse Regularization of Inverse Problems
11.solution of linear and nonlinear partial differential equations using mixt...
Solution of linear and nonlinear partial differential equations using mixture...
Andreas Eberle
Digital Signal Processing[ECEG-3171]-Ch1_L02
Lecture on nk [compatibility mode]
Estimation of the score vector and observed information matrix in intractable...
Geodesic Method in Computer Vision and Graphics
Signal Processing Course : Inverse Problems Regularization
EM algorithm and its application in probabilistic latent semantic analysis
Discrete Models in Computer Vision
Biomathematics
Neural Processes
Tele4653 l4
Spectral Learning Methods for Finite State Machines with Applications to Na...
Mesh Processing Course : Active Contours
Paris2012 session1
Olivier Cappé's talk at BigMC March 2011
Ad

Viewers also liked (15)

PPTX
Doing math with python.ch04
PDF
Manual del modulo Sympy
PDF
Meekins Resume 2016
PDF
Rondônia – Senador Ivo Cassol pode passar o final de ano com bens bloqueados
PPSX
4t B SG-Barcelona
PDF
Alfa Equipments, Chennai, Liquid Paint Coating Equipment
PDF
R A J Recipe Book
PDF
Optimization and control of processes and systems
PPTX
Derechos humanos diego alejandro gonzalez.pptx
PPTX
Vida de brinquedo
DOCX
Resumo de pratica simulada penal iii
PPT
DAELIBS for Security Service Providers
PDF
Provident Providers
PDF
Conclusiones sobre el plagio en internet
PDF
Amit Electricals, Delhi, Lamp Holders
Doing math with python.ch04
Manual del modulo Sympy
Meekins Resume 2016
Rondônia – Senador Ivo Cassol pode passar o final de ano com bens bloqueados
4t B SG-Barcelona
Alfa Equipments, Chennai, Liquid Paint Coating Equipment
R A J Recipe Book
Optimization and control of processes and systems
Derechos humanos diego alejandro gonzalez.pptx
Vida de brinquedo
Resumo de pratica simulada penal iii
DAELIBS for Security Service Providers
Provident Providers
Conclusiones sobre el plagio en internet
Amit Electricals, Delhi, Lamp Holders
Ad

Similar to Optimal control of coupled PDE networks with automated code generation (20)

PDF
Introduction to inverse problems
PDF
Numerical solution of spatiotemporal models from ecology
PDF
211 738-1-pb
PDF
Assignment6
PDF
Introduction to Calculus of Variations
PDF
Emat 213 study guide
PDF
SOLVING BVPs OF SINGULARLY PERTURBED DISCRETE SYSTEMS
PDF
An applied two dimensional b-spline model for
PDF
An applied two dimensional b-spline model for interpolation of data
PDF
MATHEON Center Days: Index determination and structural analysis using Algori...
PPT
Robust adaptive integral backstepping control and its implementation on
PDF
Two dimensional Pool Boiling
DOCX
1 d wave equation
PDF
IROS 2011 talk 2 (Filippo's file)
DOC
Chapter 3 (maths 3)
PDF
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
PDF
Gaussseidelsor
 
PDF
Solved problems
PDF
Index Determination in DAEs using the Library indexdet and the ADOL-C Package...
PPTX
Systems Of Differential Equations
Introduction to inverse problems
Numerical solution of spatiotemporal models from ecology
211 738-1-pb
Assignment6
Introduction to Calculus of Variations
Emat 213 study guide
SOLVING BVPs OF SINGULARLY PERTURBED DISCRETE SYSTEMS
An applied two dimensional b-spline model for
An applied two dimensional b-spline model for interpolation of data
MATHEON Center Days: Index determination and structural analysis using Algori...
Robust adaptive integral backstepping control and its implementation on
Two dimensional Pool Boiling
1 d wave equation
IROS 2011 talk 2 (Filippo's file)
Chapter 3 (maths 3)
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
Gaussseidelsor
 
Solved problems
Index Determination in DAEs using the Library indexdet and the ADOL-C Package...
Systems Of Differential Equations

More from Delta Pi Systems (6)

PDF
Introduction to CAGD for Inverse Problems
PDF
Introduction to the theory of optimization
PDF
Introduction to Grid Generation
PDF
Οικονομικά οφέλη από προγράμματα διαχείρισης
PDF
Agile development of processes and systems
PDF
Outsourcing in Greece
Introduction to CAGD for Inverse Problems
Introduction to the theory of optimization
Introduction to Grid Generation
Οικονομικά οφέλη από προγράμματα διαχείρισης
Agile development of processes and systems
Outsourcing in Greece

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
Electronic commerce courselecture one. Pdf
cuic standard and advanced reporting.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
MIND Revenue Release Quarter 2 2025 Press Release
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document

Optimal control of coupled PDE networks with automated code generation

  • 1. Σ YSTEMS Optimal control of coupled PDE networks with automated code generation Dimitrios Papadopoulos Delta Pi Systems, Thessaloniki ICNAAM 2012, Kos, Greece 1 / 23
  • 2. Overview ◮ Application of PDE Networks ◮ Representation of PDE Networks as a Graph ◮ Optimal Control of PDEs ◮ Adjoint Equations and Gradient ◮ Continuous vs. Discrete Adjoint Approach ◮ Discretization of the control variables ◮ Flowchart ◮ Tools of the Trade ◮ DOT Language and PyDot ◮ SymPy ◮ Cog ◮ SfePy ◮ SciPy (and NumPy) ◮ Conclusions Dimitris Papadopoulos — Delta Pi Systems 2 / 23
  • 3. Application of PDE Networks Dimitris Papadopoulos — Delta Pi Systems 3 / 23
  • 4. Representation of PDE Networks as a Graph 3 1 2 ∂y1 + ∇ · (a · y1 ) − ∇ · (D∇yi ) = f (y1 , y2 , y3 ; u) ∂t ∂y2 + ∇ · (a · y2 ) − ∇ · (D∇yi ) = f (y2 , y1 , y3 ; u) ∂t ∂y3 + ∇ · (a · y3 ) − ∇ · (D∇yi ) = g(y3 , y1 ; u) ∂t Dimitris Papadopoulos — Delta Pi Systems 4 / 23
  • 5. Optimal Control of PDEs Problem formulation t1 min J(y, u) = φ(y, u) dxdt subject to: u 0 Ω ∂yi + ∇ · (a · yi ) − ∇ · (D∇yi ) = fi , for i = 1, . . . , nn , ∂t where yi are the state variables, and y the state vector, ui are the control variables, and u the control vector, fi is a function of some yj and u, nn is the number of nodes. Lagrange function nn t1 ∂yi min L(y, u, p) = J(y, u)+ ( −fi )pi +(ayi −D∇yi )·∇pi dxdt+BC y,u i=1 0 Ω ∂t where pi are the Lagrange multipiers or adjoint variables Dimitris Papadopoulos — Delta Pi Systems 5 / 23
  • 6. Optimal Control of PDEs (cont.) Adjoint Equations n n ∂pi ∂fj − − ∇ · (a · pi ) − ∇ · (D∇pi ) = φyi (y, u) + pi , for i = 1, . . . , nn , ∂t j=1 ∂yi Gradient n n t1 ∂L ∂J ∂fi = + pi dxdt ∂u ∂u i=1 0 Ω ∂u Dimitris Papadopoulos — Delta Pi Systems 6 / 23
  • 7. Continuous vs. Discrete Adjoint nonlinear linear adjoint PDE discrete equations Dimitris Papadopoulos — Delta Pi Systems 7 / 23
  • 8. Back to the basics ∂L ∂L How do you calculate ∂u or ∂y ? ◮ Calculate analytical derivatives and implement them by hand (too time consuming and error prone) ◮ Symbolic differentiation (you have to add some code generation magic) ◮ Automatic (or algorithmic) differentiation (for each new problem you have to pass your code through your AD-tool) Dimitris Papadopoulos — Delta Pi Systems 8 / 23
  • 9. Discretization of the control variables ◮ B-spline basis functions 1 if τi−1 ≤ t < τi Ni0 (t) = , 0 else n t − τj−1 n−1 τj+n − t n−1 Nj (t) = Nj (t) + N (t), n>1 τj+n−1 − τj−1 τj+n − τj j+1 ◮ B-spline curve formed by control points ci L n u(t) = cj Nj (t) j=0 Dimitris Papadopoulos — Delta Pi Systems 9 / 23
  • 10. Parametrization - Finding a knot sequence ◮ uniform or equidistant (ti − ti−1 )/(ti+1 − ti ) = 1 ◮ chord length ∆ti ||∆di || = ∆ti+1 ||∆di+1 || ◮ cetripetal 1/2 ∆ti ||∆di || = ∆ti+1 ||∆di+1 || ◮ Natural end conditions ¨ u(t0 ) = 0, ¨ u(tm ) = 0 Dimitris Papadopoulos — Delta Pi Systems 10 / 23
  • 11. Tensor Product Patches ◮ B-spline surface m n um,n (t, x) = ci,j Nim (t)Nj (x) n i=0 j=0 where ci,j is a matrix representing all the control points of the (t, x) plane. ◮ A surface with the topology of a sphere is not representable as a tensor product surface, without degeneracies (but we don’t really care) Dimitris Papadopoulos — Delta Pi Systems 11 / 23
  • 12. Flowchart parse DOT graph build symbolic PDEs initialize control points build symbolic adjoint PDEs k 1 k k+1 build symbolic gradient solve direct problem generate source code for solution of PDEs objective function compute gradient generate source code for solution of adjoint PDEs no k generate source code for gradient J <ε solve adjoint problem yes solution Dimitris Papadopoulos — Delta Pi Systems 12 / 23
  • 13. Tools of the Trade Extended DOT Language Direct Adjoint SymPy Cog Cog SfePy SfePy SciPy Dimitris Papadopoulos — Delta Pi Systems 13 / 23
  • 14. DOT Language A DSL for graph representation digraph network { 3->1 [type=1]; 3->2 [type=1]; 1->2 [style=dashed, type=2]; 2->1 [style=dashed, type=2]; 1->3 [style=dotted, type=3]; 3 [shape=box];} 3 1 2 Dimitris Papadopoulos — Delta Pi Systems 14 / 23
  • 15. Why Python? ◮ programmer’s time vs. computing time ◮ need for manipulation of the objects at runtime ◮ need for source code generation at runtime ◮ lisp, smalltalk, perl, python, ruby, javascript vs. C, C++, java ◮ Paul Graham’s classical closure example of the accumulator: def foo(n): s = [n] def bar(i): s[0] += i return s[0] return bar ◮ many tools and numerical libraries available Dimitris Papadopoulos — Delta Pi Systems 15 / 23
  • 16. PyDot A Python library for the DOT language import pydot graph = pydot.graph_from_dot_file(’test.dot’) shape_dict = {} function_dict = {} for node in graph.get_nodes(): my_name = node.get_name() shape_dict[my_name] = node.get(’shape’) function_dict[my_name] = node.get(’function’) type_dict = {} style_dict = {} for edge in graph.get_edges(): my_edge = (edge.get_source(), edge.get_destination()) type_dict[my_edge] = edge.get(’type’) style_dict[my_edge] = print edge.get(’style’) Dimitris Papadopoulos — Delta Pi Systems 16 / 23
  • 17. SymPy A Python library for symbolic mathematics from sympy import Eq, Function, Symbol from sympy import Derivative as D, Integral from sympy.abc import x, t, a y_list = [] # same for u_list for node in graph.get_nodes(): my_name = node.get_name() y_list.append(’y_’+str(my_name)) # same for u_list y = map(Function, y_list) # same for u_list f = y[1]+u # for example eq = Eq(D(y[1](x,t),t)+a*D(y[1](x,t),x)-D(D(y[1](x,t),x),x),f) Dimitris Papadopoulos — Delta Pi Systems 17 / 23
  • 18. SymPy (cont.) Derivative of the Lagrangian 1. Build list of symbols for functions, 2. build a list of substitutions for the functions and the reverse, 3. substitute for the functions, 4. run derivatives with respect to the symbols, 5. substitute functions for the symbols, 6. take any derivatives with respect to the function variables. Integral(Derivative(F.subs(u(x),foo),foo).doit().subs(foo,←֓ u(x))*v(x),x) Dimitris Papadopoulos — Delta Pi Systems 18 / 23
  • 19. Cog A code generation tool ... # [[[cog # import cog # functions = [direct, adjoint, gradient] # for func in functions: # cog.outl("def %s():" % func) # cog.outl(" pass") # ]]] # [[[end]]] ... Dimitris Papadopoulos — Delta Pi Systems 19 / 23
  • 20. SfePy A software for solving systems of coupled PDEs by the FEM ◮ SfePy: Simple finite element in python ◮ Other alternatives: FENICS or your favorite FE solver (needs to be general enough) ◮ Future work: bring metaprogramming to the next level, i.e., ◮ use FENICS, which generates C++ at runtime from the problem formulation which can also be run parallel graph symbolic intermediated parallel representation representation python code C++ code Dimitris Papadopoulos — Delta Pi Systems 20 / 23
  • 21. SciPy (and NumPy) A library for doing everything else import numpy as np from scipy.optimize import fmin_bfgs from newly_created_file import objective, gradient c0 = np.array([0.0, 0.0, 0.0, 0.0]) res = fmin_bfgs(objective, c0, gradient, args, gtol, norm, ...) and the rest is a piece of cake! Dimitris Papadopoulos — Delta Pi Systems 21 / 23
  • 22. Conclusions Summary ◮ Framework for optimal control of coupled PDE networks ◮ Automated code generation ◮ Graph representation of coupled PDEs ◮ Symbolic differentiation for the adjoint equations and the gradient ◮ Solution with the finite element method Outlook ◮ Extention to more general equations, ◮ with 2D or 3D geometries, ◮ and constraints on the state or control variables. ◮ Adaptive refinement of the control variables. Dimitris Papadopoulos — Delta Pi Systems 22 / 23
  • 23. Thank you for your attention! Delta Pi Systems Thessaloniki, Greece http://www.delta-pi-systems.eu Dimitris Papadopoulos — Delta Pi Systems 23 / 23