Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PyConZA 2014: "Challenges and Prospects of the ...

Pycon ZA
October 03, 2014

PyConZA 2014: "Challenges and Prospects of the Python African Computational Science and Engineering Tour Project" by Godfrey Akpojotor

Computer and computer based activities have pervaded our teaching/learning process as well as research so much so that the 21st century academic activities in science and engineering (S & E) cannot be fully engaged without some level of computation. An important choice of a programming language especially in a developing country is the ease to learn it and its accessibility.

Python's unique features and the possibility that any user connected to the internet can download the entire packages into any platform, install it and immediately begin to use it makes it a preferred environment for introducing students and new beginners to elegant and all purpose programming. Therefore in Africa, the Python African Tour project has been launched and I am coordinating its use in computational Science and Engineering (S & E) code-named Python African Computational Science and Engineering Tour (PACSET).

We present here an overview of the three projects currently under the PACSET using captivating Python demonstrations from our growing compendia of demonstrations for each project:

1. teaching Python to students, new beginners as well as expert programmers in S & E
2. using Python to model, simulate and visualize concepts, laws and phenomena in S & E to compliment the teaching of theory and experiment
3. using Python to model, simulate and visualize laboratory experiments to aid the teaching and learning of experimental S & E.

Since these projects involve teaching and training as well as modeling, simulation and visualization, we employ all the Python scientific tools in our demonstrations such as NumPy, SciPy, SymPy, Matplotlib and VPython. I also discuss the challenges and prospects of the PACSET: this include our solutions to the challenges of providing students in tertiary institutions with computing systems as well as cheap portable charging devices to supplement the irregular power supply in some parts of Africa.

Pycon ZA

October 03, 2014
Tweet

More Decks by Pycon ZA

Other Decks in Programming

Transcript

  1. Challenges and Prospects of the Python African Computational Science and

    Engineering Tour Project Godfrey E. Akpojotor Physics Department, Delta State University, Abraka, Nigeria PyConZA 2014 @ Belmont Square Convention Centre, Cape Town, South Africa Thursday, October 04, 2013 Challenges and Prospects of the Python African Computational Science and Engineering Tour Project Godfrey E. Akpojotor THEORETICAL AND COMPUTATIONAL CONDENSED MATTER PHYSICS Physics Department, Delta State University, Abraka, Nigeria Friday, October 03, 2014 PyConZA 2014 @ The Forum Convention Centre in Bryanston, Johannesburg, South Africa 1
  2. Plan of the presentation • Introduction – Why computational approaches?

    • Choice of a Programing language • Python African Computational Science and Engineering Tour Project (PACSET) • PACSET Packs - Examples from our compendium of modeling, simulation and visualization • Problems and Prospects of PACSET 4
  3. Introduction -Why Computational Approaches? In the past, behold Ernest Rutherford

    (right) and his assistant Hans Geiger in his laboratory in Manchester. One is tempted to believe the joke that the facilities in the experimental lab of Rutherford who is acclaimed to had discovered the nucleus, can be packaged into a travelling bag! 5
  4. Introduction -Why Computational Approaches? But today, a collaboration of over

    10,000 scientists and engineers from over 100 countries has to set up the Large Hadron Collider (LHC) which is the world’s largest and most powerful particle accelerator with a 27-kilometre ring of superconducting magnetic mainly to prove or disprove the existence of the theorized Higgs particle! 6
  5. Introduction -Why Computational Approaches? Similarly, Isaac Newton in the past

    could sit under an apple tree and set up formulations of the laws that governs the macroscopic world using a pen and a paper! But today, researchers need more complex numerical formulation to set up theories governing the physical world and therefore needs the computers Pseudo gap Superconductivity Strange metal Insulator and antiferromagnetic Fermi liquid Temperature Doping TC T* The transition phase diagram of HTSC showing the various phases at various temperatures and doping levels. 7
  6. Science and Engineering Theory Computational Approaches Experiment Computer and computer

    based activities have pervaded our teaching/learning process as well as research so much so that in addition to theory and experiment, they now constitute a third pillar in science and engineering (S & E). Introduction -Why Computational Approaches? 8
  7.  For the teaching/learning process,  a means of understanding

    the various disciplines in S & E as well as useful training for the future in academic, industry, etc while retaining qualities characteristic of these disciplines education, ‡ such as abilities for integrated understanding and adaptive learning. Introduction -Why Computational Approaches? 9
  8. For the research purpose, it provides a testing ground for

    analytical models and can guide the development of new analytical approaches a useful tool for the analysis/interpretation of experimental results and a powerful technique for simulations, that is, to predict properties of systems/models that are not easily accessible to experiments. Akpojotor et. al. (2009; 2011) Introduction -Why Computational Approaches? 10
  9. Introduction -Why Computational Approaches? So the growing consensus is that

    the 21st century researchers in Science and Engineering if they do not posses some computational knowledge to work with both in theory and experiment. cannot fully function 11
  10. Choice of programming language Making this choice vary from one

    individual/group/institution/laboratory to another since each language has its own strengths and weaknesses and better ones may even emerged in the nearest future! However, in general, In making the choice of programming environment to teach new beginners, two very important considerations the desire to ease the learners into programming and to give them the opportunity to develop a conceptual model of what a programme is and what it does its accessibility especially in developing countries 12
  11. Choice of programming language The choice that meets these considerations

    for now is Python hence we have adopted it as the programming language to introduce to Africa. Python Africa Tour- http://www.pythonafricantour.com/  Python is a high level language whose unique features such its interpretative, multipurpose, multiplatform and object oriented nature as well as being a free and open source programming software with an extensive libraries, creates the possibility that any user connected to the internet can download the entire package (including the latest version!) into any platform, install it and immediately begin to use it! 13
  12. Choice of programming language Further  It is easy to

    combine Python with compiled languages like C (CPython) which is a widely used language for scientific computations.  Integration of Python with Java is offered by a special version of Python called Jython as well as PyPy and IronPython  Can be used for various purpose including very elegant website design (as with much of google) and its adoption in Nokia phones, ipods, etc Finally, Python is suitable for scientific computation as it has several modules such as NumPy, SciPy, SymPy, Matplotlib and VPython and even a scientific version (Python x,y) which simplifies scientific computations, visualizations and simulations 14
  13. Python African Computational Science and Engineering Tour (PACSET) Project The

    vision and mission is to introduce computational approaches in S & E to Africans in Africa via * teaching Python to students, new beginners as well as expert programmers * using Python to model, simulate and visualize concepts, laws and phenomena in S & E to compliment the teaching of theory and experiment. * using Python to model, simulate and visualize laboratory experiments to aid the teaching and learning of experimental S & E with the http://www.pacset.net 15
  14. Python African Computational Science and Engineering Tour (PACSET) Project http://www.pacset.net

     PACSET was launched on July 11, 2010 in Nigeria at the International Seminar on Theoretical Physics and National Development (ISOTPAND2010) from July 10 – 22, 2010 as a Foundation Postgraduate Course on Computational Approaches in S & E using Python at the National Mathematical Centre, Abuja, Nigeria.  Just about 3 weeks (June 14 -18, 2010) after a training workshop on Python (mostly for website designers) at the African University of Science and Technology also in Abuja - sponsored by Google and the National Information Technology Development Agency  The Foundation Postgraduate Course on Computational Approaches in S & E using Python has been adopted as a one week training programme at the ISOTPAND Series since then. 16
  15. Python African Computational Science and Engineering Tour (PACSET) Project http://www.pacset.net

    At the Foundation Postgraduate Course,  Participants (many who are novices) are taught the basic syntax and structure of Python that will enable them use it for: * Numerical calculations * Symbolic calculations * Basic programming * Implementation of generalized algorithms in S & E * Graphical analysis * Modelling, simulation and visualization 17
  16. Python African Computational Science and Engineering Tour (PACSET) Project http://www.pacset.net

     Python for kids – Catch ThemYoung  Python for Non-Programmers  Python for Programmers  Python for Statisticians and Financial Managers  Optimizing Python Programs  Windows Programming with Python  Python Extensions with Other Languages  Fast Code with the Cython Compiler  Pygames for various Ages  Network Programming with Python  High-Performance Computation with Python Advanced Python for Scientists and Engineers Python for Exploring Experiments Python for Exploring Concepts, phenomena, etc Modeling, Simulation and Visualization with Python Introduction to Django Advanced Django High Performance XML with Python Developing Computational Illustrative Websites with Python Special Topics as the needs arise Training Programmes 18
  17. PACSET PACKS http://www.pacset.net • Includes various codes for generalized algorithms

    in S & E • compendium of modeling, simulation and visualization of various concepts, laws, phenomena, etc, in S & E • compendium of modeling, simulation and visualization of various experiments in S & E PACSET Packs is a compendium of products that meet the PACSET goals and that are free and open source. So it is a global community movement like its mother, Python So not just new packs but better codes replace old versions! Yes, PACSET Packs are for everybody but for learners, it is better to develop your own codes! 19 The PACSET Packs here are pedagogical
  18. T A L Tension Fnet mg Hooke's Law: F =

    -kx t L g sin max    PACSET PACKS A. Simple Pendulum Simple harmonic motion is an important phenomena in S & E. The simplest experiment to depicts it is by the use of simple pendulum - a point mass suspended from a string or rod of negligible mass. 20 http://www.pacset.net
  19. PACSET PACKS To simulate the simple pendulum, first need to

    know how to create a ceiling, string and bob as well as how to position them The Visual Python module will be used VPython is so simple but yet very elegant and captivating Students find the ability to create simulations and visualizations with few lines of codes so very fascinating! from visual import* sphere() This creates a white (Python default colour) sphere! from visual import* box() This creates a white (Python default colour) box! from visual import* cylinder() This creates a white (Python default colour) cylinder! Each of these objects can then be resized and positioned Just needs simple knowledge of vector as well as some practice: The Cartesian coordinate(x, y, z ) will determine how one can create the appropriate position and sizes. x = length, y = height and z = width. A. Simple Pendulum 21
  20. PACSET PACKS Each of these objects can be instructed to

    move at appropriate velocity and direction. A good knowledge of simple equations of motion: By definition, velocity is displacement (that is, change of distance in specified direction) with respect to the time taken to do so. Thus to move from position x1 to x2 from t1 to t2, the velocity will be v = ∆x/∆t where ∆x = x2 - x1 and ∆t = t2 - t1 It follows that the change in position is simply ∆x = v∆t So that x2 = x1 + v∆t That is, new position = old position + v∆t. The code in Vpython for a box say is box.pos = box.pos + box.velocity*dt box.velocity = vector(x, y, z) A. Simple Pendulum 22
  21. PACSET PACKS The codes to create the ceiling, string and

    bob for the simple pendulum: from __future__ import division from visual import * # Controlling the dimension of the screen scene.width = 1000 scene.height = 1000 scene.background = color.white scene.title = 'Simple Pendulum Visualization' # Turning autoscale off scene.autoscale = False # Length of string length = 10.0 # Setting up the ball and string in an appropriate position ball = sphere(radius=0.5, pos=(length,0,0), color=color.red) string = cylinder(pos=(0,0,0), axis=(length,0,0), radius=0.1) string.color = color.black ceiling = box(pos=(0,0.5,0), size=(2*length, 1, 0), color=color.green) A. Simple Pendulum 23 http://www.pacset.net
  22. PACSET PACKS Here the bob and string position motion are

    by change in their positions # Setting gravity, angular frequency, time and the time step-size gravity = 9.8 dt = 0.01 omega0 = 0 theta0 = 0.5*math.pi label(pos=(-8,-7,0), text='The lenght of the string is: %1.5f' % length) label(pos=(-8,-6,0), text='Radius of ball is: %1.2f' % ball.radius) # Creating a list to hold the values of omega, theta and time omega = [omega0] theta = [theta0] time = [0] Need to add a sinusoidal curve of the variation of angle with time from which we can determine the periodic time Note: This visualization be replaced by requesting for the time only # Setting Up the Corresponding Graph Region graph1 = curve(color = color.green) x_axis = curve(x=[-12,10], y = [5,5], color=color.black) y_axis = curve(x=[-10,-10], y = [10,0], color = color.black) x_label = label(text='Time', pos = (10,4.5,0), opacity=0, color=color.black) x_label.box = False y_label = label(text='Theta', pos=(-10.5,8,0), opacity=0, color=color.black) y_label.box = False A. Simple Pendulum 24
  23. PACSET PACKS Implementing a simple pendulum algorithm # Setting the

    "While" Loop Invariant Loop = True # Counter Variable to Keep Track of the Number of Loops Executed i = 0 while Loop: rate(100) # Determining Omega and Theta Values omega.append(omega[i] - (gravity/length) * theta[i]*dt) theta_modified = theta[i] + omega[i+1] * dt # Reseting Theta to Keep It Within a 180 Degrees Range if theta_modified > pi: theta_modified = theta_modified -pi elif theta_modified < -pi: theta_modified = theta_modified + pi theta.append(theta_modified) time.append(time[i] + dt) # Updating the Position of the Ball and String x = length * math.sin(theta[i]) y = -length * math.cos(theta[i]) ball.pos = (x,y,0) string.axis = (x,y,0) # Updating the Position of the Ball and String x = length * math.sin(theta[i]) y = -length * math.cos(theta[i]) ball.pos = (x,y,0) string.axis = (x,y,0) # Updating the Graph graph1.append(pos=(time[i]-10,2*theta[i]+5,0)) # Print the Times the Graph Cuts the X-axis if theta[i] > -0.01 and theta[i] < 0.01: time_indicator = label(text='%1.2f' % time[i], pos=(time[i]-10,4.5,0)) time_indicator.color = color.black time_indicator.opacity = 0 time_indicator.box = False # Updating the Counting Keeping Track of the Number of Loops Executed i += 1 # Determining When to End the Simulation if i >= 1850: Loop = False end_label = label(text='End of Simulation', pos=(0,-8,0)) ball.pos = (0,-6,0) string.axis = (0,-6, 0) A. Simple Pendulum 25
  24. A snapshot showing the end of simulation of the simple

    pendulum for the string length L = 10.00 A snapshot showing a swigging bob simulation of the simple pendulum for the string length L = 2.00. * Vary the length * Vary the size of the bob * Vary the rate of oscillations * Vary the number of oscillations PACSET PACKS To confirm that only the length affects the periodic time 26
  25. Length (L) Period (T) 10.00 6.35 8.00 5.68 6.00 4.92

    4.00 4.01 2.00 2.84 PACSET PACKS A. Simple Pendulum The beauty of the PACSET Packs is that the experiments are not only simulated but all analyses are easily done as well. For the simple pendulum, it is graphical analysis. Now the Matplotlib is an amazing tool for plotting graphs including graph sheets designs Thus making the plotting of the period against the length straightforward here 27
  26. PACSET PACKS A. Simple Pendulum One of the merits of

    simulation is that one can go beyond experimental limits # Updating the y – positions of the bob and string will result a bob hanging on a string attached to a floor - upward swinging! x = length * math.sin(theta[i]) y = -length * math.cos(theta[i]) ball.pos = (x,4,0) string.axis = (x,4,0) A string of negligible mass cannot be used in real experiments to set up this upward swinging, that is, the string must be rigid and this may only be possible in a physical pendulum wherein the string mass is not negligible The bob swing unrestricted by changing the Theta Values could lead to chaos! omega.append(omega[i] - (gravity/length) * theta[i]*dt) theta_modified = 1.005*theta[i] + omega[i+1] * dt omega.append(omega[i] - (gravity/length) * theta[i]*dt) theta_modified = 1.05*theta[i] + omega[i+1] * dt 28 http://www.pacset.net
  27. PACSET PACKS B. Mimicking Fourier Series Fourier series are infinite

    series of sines and cosines which are capable of representing almost any periodic function whether continuous or not. Fourier series have wide and varied applications in S & E For a function f(x) defined on the interval –π ≤ x ≤ π where f(x + 2nπ) = f(x), the Fourier series is where are called the Fourier coefficients.       1 0 ) sin cos ( 2 ) ( n n n dx nx b nx a a x f       dx x f a ) ( 1 0       nxdx x f a n cos ) ( 1       nxdx x f b n sin ) ( 1 29 http://www.pacset.net
  28. PACSET PACKS B. Mimicking Fourier Series The game is to

    obtain the Fourier coefficients which could be tedious and then substitute back into the Fourier series resulting in a sinusoidal curve To mimic the job of the Fourier series, simple VPython codes have been used to simulate the process Fourier series equation (transformation process) hidden in a dark box e.g square waveform Input (Any waveform) Using appropriate Equations e.g saw tooth waveform e.g saw triangle waveform 30
  29. # Code for Developing a Step-like Function step_fn_data = []

    for i in arange(1,10): if math.fmod(i,2) == 0: switching_value = [-8,8,8] else: switching_value = [0,-0,-0] step_fn_data.extend(switching_value) d = curve(x = arange(-40,size(step_fn_data)-40), y = step_fn_data) d.color = color.green # End - Code for Developing a Step-like Function The snapshots of simulation of the Fourier series for chairlike waveform PACSET PACKS B. Mimicking Fourier Series Only the extract of Fourier series is presented here since the VPython basic syntax has been introduced in Slide 21 and the pendulum complete codes in Slides 23-25 The codes are available on demand On-set Half-way End 31
  30. PACSET PACKS B. Mimicking Fourier Transform switching_value = [-2,-8,-4] Snapshots

    from the simulation of the Fourier series for an M-up and W-down waveform switching_value = [8,0,8] Snapshots from the simulation of the Fourier series for a triangular waveform 32
  31. PACSET PACKS B. Mimicking Fourier Series Using the possibility available

    to simulation, we can go beyond the present mathematical formulation by transforming two different waves into one 33
  32. The web application software can be created using the following

    major steps: i. Installation of the needed softwares to build it ii. Setting up Django iii. Creating dynamic web content and iv. Mapping the URL to the view PACSET PACKS C. Illustrative website An illustrative website here is a web application in form of a set of related webpages served from a single web domain to demonstrate the desired concept, law or phenomenon as well as experiment in S & E. 34
  33. SymPy is a Python library for symbolic computation and the

    overall goal is to promote computer algebraic system (CAS), while keeping the codes as simple as possible for comprehensibility and extensibility. Yea, SymPy is entirely written in pure Python and independent to any other external libraries. PACSET PACKS C. Illustrative website for basic calculus Calculus is an essential mathematical tool in S & E There are already a number of published works on differentiation and integration using Python But the symbolic Python module, SymPy, makes so much sense! So It has a great future in S & E! 35
  34. PACSET PACKS C. Illustrative website for basic calculus from Sympy

    import* def differentiate it(request): c1= request. GET ['a'] c2= request. GET ['b'] c3= request. GET ['c'] c4= request. GET ['n'] c5= request. GET ['n2'] c6= request. GET ['n3'] c7= request. GET ['d'] a1= int (c1) b1= int (c2) c1= int (c3) n1= int (c4) n2= int (c5) n3= int (c6) d1= int (c7) x=Symbol ('x') g=a1*x**n1+b1*x**n2+c1*x**n3+d1 d=diff (g, x,1) Return render_to_response ('result.html', {'d': d}) No nitty gritty of SymPy (split over 13,000 with Documentation) here! Just some classroom codes for a basic illustrative website for differentiation and integration 36 http://www.pacset.net
  35. PACSET PACKS C. Illustrative website for plotting graphs The Ever

    expanding capability of the Matplotlib has been demonstrated in Slide 27 So here is some classroom codes for a basic illustrative website for plotting graphs – showing the macros (1 cm by 1 cm) and micros (1 cm by 1 cm), graph title and legend wherein the compatibility of the scientific mark-up language, latex with Matplotlib is demonstrated ax.yaxis.set_minor_locator(MultipleLocator(0.2)) grid(which='major', axis='x', linewidth=1.00, linestyle='-', color='0.55') grid(which='major', axis='y', linewidth=1.00, linestyle='-', color='0.55') grid(which='minor', axis='x', linewidth=0.45, linestyle='-', color='0.55') grid(which='minor', axis='y', linewidth=0.45, linestyle='-', color='0.55') x = linspace(-3,3) y1 = x + 2 y2 = 3 - 4*x plot(x,y1,'-c') plot(x,y2,'-r') text(0.4,1.4,r'$y = 3 - 4x$',fontsize=15) text(-1.5,0.4,r'$y=x+2$',fontsize=15) title('Linear Graph I') show() from pylab import* ax = axes([0.073,0.073,0.86,0.86]) ax.set_xlim(-4,4) ax.set_ylim(-3,3) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) ax.xaxis.set_major_locator(MultipleLocator(1.0)) # On the x-axis, 1cm represents 1 unit ax.xaxis.set_minor_locator(MultipleLocator(0.2)) ax.yaxis.set_major_locator(MultipleLocator(1.0)) # On the y-axis, 1cm represents 1 unit 37
  36. PACSET PACKS C. Illustrative website for plotting graphs So this

    illustrative website easily provides graphical solutions of various types of equations 38 Enough Insight! http://www.pacset.net
  37. Problems * How to innovate the various curricula in S

    & E to accommodate the computational approaches * The setting up of computer laboratories for computational practicals * Lack of funding to organize frequent conferences, workshops, etc as well as participants inability to get funding * High exchange rates making the computing systems very expensive * Energy – lack of constant power supply in some countries * Limited collaborations among the educational bodies from one country to another Problems and Prospects of PACSET 39
  38. Prospects * Reduction of prices of laptops for simple computations

    * Possibility of cheap alternative to power from the national grid – we have designed and built cheap laptop rechargeable battery chargers * Free and open source of Python making it easily accessible * Its wide range of applicability makes the prospect of Python programmers’ marketability very promising in the academia, industries, etc * The ease, comprehensibility and flexibility to use the PACSET packs, etc. * Subsidized fees at PACSET conferences, training workshops, etc. Problems and Prospects of PACSET 40