Proseminar Python - Python Bindings

Total Page:16

File Type:pdf, Size:1020Kb

Proseminar Python - Python Bindings Proseminar Python - Python Bindings Sven Fischer Student an der TU-Dresden [email protected] Abstract Diese Arbeit beschaftigt¨ sich damit, einen Einblick in die Benut- zung von externen Bibliotheken in Python zu geben und fuhrt¨ den Leser in das Schreiben von eigenen Erweiterungen ein. Daruber¨ hinaus wird darauf eingegangen, wie Projekte in anderen Program- miersprachen Python benutzen konnen.¨ Weiterhin wird kurz auf verschiedene andere Moglichkeiten¨ eingegangen, Python oder Py- thons Benutzung zu erweitern und zu verandern:¨ durch Kompilati- on, Mischen“ mit oder Ubersetzen¨ in anderen Sprachen, oder spe- ” zielle Interpreter. Abbildung 1. Vergleich der Moglichkeiten¨ Python zu erwei- tern (links) und Python einzubetten (rechts). Categories and Subject Descriptors D.3.3 [Programming Lan- guages]: Language Constructs and Features—Modules, packages 1. Daten von C nach Python konvertieren General Terms Languages, Documentation 2. Python Funktion mit konvertierten Werten aufrufen Keywords Python, Extension, Embedding, Library 3. Ergebnis von Python zuruck¨ nach C konvertieren 1. Einfuhrung¨ Diese Konvertierung ist auch das großte¨ Hindernis beim Ver- 1 Python wird mit einer umfangreichen Standartbibliothek ausgelie- knupfen¨ von Python und C , zumindest ist es mit einigem Aufwand fert. Trotzdem gibt es Grunde,¨ warum man Python um verschiedene verbunden. externe Bibliotheken erweitern mochte.¨ Ein Beispiel dafur¨ ware¨ die Es gibt einige Projekte, die sich mit dem Verandern¨ und Erwei- ¨ Geschwindigkeit, die bei Python als interpretierter Sprache nicht tern der Sprache Python beschaftigen.¨ Einen kurzen Uberblick uber¨ immer den Anforderungen entspricht. Weiterhin gibt es genugend¨ einige Moglichkeiten¨ gebe ich in Abschnitt4. Dort gehe ich auf Software von Drittanbietern, welche man in Python nutzbar ma- zwei Python-Interpreter neben dem in der Standard-Distribution chen will - ohne sie in Python zu ubersetzen.¨ Darauf gehe ich in enthaltenen ein und zeige Moglichkeiten¨ auf, Python in andere Abschnitt2 ein. Sprachen zu ubersetzen,¨ beziehungsweise direkt in Maschinencode Python ist eine flexible Sprache, was schon allein durch die zu kompilieren. dynamische Typisierung gegeben ist. Man kann vergleichsweise Zum Abschluss gebe ich noch einen kurzen Ausblick auf eine viel Funktion pro Codezeile realisieren, ware¨ es da nicht nutzlich,¨ Sprache mit ahnlichen¨ Eigenschaften und Anwendungsmoglichkeiten¨ diese Funktionalitat¨ - zusammen mit der großen Standardbibliothek wie Python: LUA. - in einer bereits existierenden Applikation einfugen¨ zu konnen?¨ Abschnitt3 besch aftigt¨ sich damit Python in Projekte in anderen 2. Extending Python Sprachen einzubetten. Python eignet sich als Skriptsprache mit hoher Ausdrucksfahigkeit¨ Zur besseren Unterscheidung sind beide Moglichkeiten¨ in Ab- fur¨ die Verwendung als Glue-Language“ zwischen verschiede- ” bildung1 grafisch dargestellt. Im Grunde sind sich beide Verfahren nen Bausteinen einer großeren¨ Applikation. Dabei werden bereits Erweitern sehr ahnlich:¨ man fuhrt¨ jeweils 3 Schritte aus, zum oder existierende Teile, die in verschiedenen Programmiersprachen ge- Extending : schrieben sind, miteinander verknupft.¨ 1. Daten von Python nach C konvertieren Wenn man ein großes Softwareprojekt erstellen will, wird man 2. C Funktion mit konvertierten Werten aufrufen laut [Brooks], gewollt oder ungewollt, einen Prototypen program- mieren, den man nur dazu verwendet logische Probleme aufzude- 3. Ergebnis von C zuruck¨ nach Python konvertieren cken und anschließend weg wirft. Python kann dabei helfen, die Zum Einbetten oder Embedding sind es die folgenden: Kosten dieses Prototypen zu verringern beziehungsweise diesen schneller zu erstellen. Man kann auch das nachfolgende ausge- ” reifte“ System wieder in Python schreiben und dann aufgrund von Geschwindigkeitsvorteilen oder anderen Anforderungen wie Typ- sicherheit, die Anwendung ganz oder in Teilen in andere Program- 1 Erweiterbar ist Python um dynamische Bibliotheken, die in beliebigen Sprachen geschrieben sein konnen.¨ Einbettbar ist es im Grunde auch in An- wendungen, die in beliebigen Sprachen (C#, Java, ...) geschrieben wurden, allerdings bietet Python von Haus aus die C-API an, die die Zusammenar- [Copyright notice will appear here once ’preprint’ option is removed.] beit mit C wesentlich erleichtert. About Python Bindings 1 2011/2/5 miersprachen auslagern. Wohlgemerkt muss man das nicht, son- bleme konnten¨ auch dabei auftreten, dass ctypes direkt im Speicher dern kann auch die finale Anwendung in 100% Python ausliefern. arbeitet und man zwar nicht in C programmiert, sondern in Py- Wenn man sich die Moglichkeit¨ einer Portierung offen lassen will, thon, aber trotzdem sehr viel uber¨ C wissen muss, zum Beispiel sollte man allerdings vorsichtig mit der Verwendung von spezi- benotigt¨ man Kenntnisse uber¨ Memorymanagement, Alignment, ellen Python-Konstrukten (wie Method-Patching) umgehen, oder Datentypen, Casting. Ein genaueres Eingehen wurde¨ hier den Rah- man muss diese spater¨ in der Zielsprache geeignet umschreiben. men sprengen, deshalb verweise ich auf [Python Docs] unter The ” Python Standard Library: Generic Operating System Services“. Listing 1. Benutzung einer Funktion fak aus einem importierten 2.2 Module selbst schreiben Modul modExample Falls man keine fertige Bibliothek ansprechen mochte,¨ sondern 1 i m p o r t modExample zum Beispiel Funktionalitat¨ in ein externes Modul auslagern will, 2 x = 3 3 r = modExample . fak ( 3 ) auf dessen Erstellung man Einfluss nehmen kann, kann man die C- API benutzen ([Python Docs] unter C API Reference Manual“). ” Um Erweiterungen zu installieren reicht es meist, einen Instal- Wie der Name schon sagt, mussen¨ Erweiterungen unter Benutzung ler bzw. Linux-Paket auszufuhren,¨ oder ein mitgeliefertes Setup- dieser API in C geschrieben werden. Skript zu starten (via $ python setup.py install). Erweiterungen soll- ten moglichst¨ transparent zu benutzen sein, das heißt genauso wie ein normales Paket (siehe zum Beispiel Listing1). Listing 4. Benutzung des Moduls Spam Das Problem am Erweitern von Python mit Bibliotheken liegt 1 i m p o r t spam in den Unterschieden von Python zu anderen Programmiersprachen 2 status = spam . system (”ls −l”) oder kompilierten Bibliotheken: Die Datentypen sind andere, Da- tentypen werden in Python teilweise automatisch konvertiert und es Im Gegensatz zu ctypes lasst¨ sich der benutzende Python Co- steht vor der Ausfuhrung¨ nicht fest, welchen Typ eine Variable an de genau so schreiben, wie der fur¨ eingebaute Module: Listing4 einem bestimmten Punkt hat. Es gibt Unterschiede in der Speicher- zeigt, wie unser Beispiel am Ende zu benutzen sein soll. Es soll verwaltung (Heap-Allokation und Reference Counting gegen teil- eine Schnittstelle zu C erstellt werden, die (nur) die Bibliotheks- weise Stack-Allokation und Speicherverwaltung per Hand“) und funktion int system(char*) aufruft, ahnlich¨ der bereits im Modul os ” in den Funktionsschnittstellen (benannte Parameter). Diese Un- vorhandenen Funktionalitat.¨ terschiede konnen¨ entweder in der Bibliothek selbst (bzw. in C- Wrappern) oder in Python uberbr¨ uckt¨ werden, beide Wege werden vorgestellt. Listing 5. spammodule.h 1 #include <Python . h> 2.1 ctypes 2 3 s t a t i c PyObject *spam_system ( PyObject *self , PyObject * - Mittels des Moduls ctypes ist ein Zugriff von Python auf dyna- args ) f mische Bibliotheken (als DLL- oder SO-Dateien) moglich,¨ ohne 4 ¨ 5 c o n s t char *command ; Anderungen an der Bibliothek vornehmen zu mussen.¨ Samtliche¨ 6 i n t sts ; Konvertierungen werden in Python gehandhabt. 7 8 i f(! PyArg_ParseTuple ( args ,”s”,& command )) 9 r e t u r n NULL ; 10 Listing 2. Import und Aufruf der Microsoft Implementierung der 11 sts = system ( command ); C-Standard-Bibliothek 12 r e t u r n Py_BuildValue (”i”, sts ); 1 i m p o r t ctypes 13 g 2 bibliothek = ctypes . CDLL (”MSVCRT”) 3 bibliothek . printf (”Hallo Welt nn”) Dazu benotigt¨ man zuerst eine Quellcode-Datei, nennen wir Listing2 zeigt ein Beispiel, welches aber viele Probleme ver- sie spammodule.c. Python.h erlaubt Zugriff auf alle benotigten¨ Funk- schweigt: einfache Konvertierungen erledigt Python automatisch, tionen und Makros fur¨ den Zugriff auf die Python Laufzeitum- sobald mehr Datentypen konvertiert werden mussen,¨ als Strings gebung, wobei alles mit Py beziehungsweise PY anfangt.¨ Listing oder Integer, muss man selbst Hand anlegen. 5 zeigt die komplette Datei. Im Prinzip mussen¨ alle Funktio- nen, die aus Python aufrufbar sein sollen, einen Zeiger auf ein PyObject zuruckgeben.¨ Dieses Objekt wird dann in Python als Ruckgabewert¨ verwendet. Jedes Datum was aus Python kommt Listing 3. Aufrufen einer Funktion mit Float-Parameter und setzen oder zu Python geht muss ein PyObject sein, welches die Basisklas- des Ruckgabetyps¨ einer anderen 2 self - 1 f = ctypes . c_float ( 1 . 3 3 7 ) se fur¨ alle Daten von/zu Python darstellt. Der Parameter 2 bib . callFloat ( f ) ist ein Zeiger auf das aufrufende Python-Objekt bzw. Python- 3 Modul fur¨ Modul-Funktionen, args ist ein Tupel aus Argumenten, 4 bib . veclenDouble . restype = c_double von denen jedes seinerseits wieder ein Zeiger auf ein PyObject ist. 5 p r i n t bib . veclenDouble ( c_double ( 1 . 5 ) , c_double ( 2 . 7 ) , - PyArg_ParseTuple args c_double ( 3 . 9 ) ) extrahiert aus mittels eines Typ-Strings die Argumente und macht sie uber¨ bereitgestellte Zeiger verfugbar.¨ Im Listing3 zeigt am Beispiel, wie man einen Bibliotheks-Funktion Fehlerfall gibt es false zuruck¨ und setzt
Recommended publications
  • A Practical Solution for Scripting Language Compilers
    A Practical Solution for Scripting Language Compilers Paul Biggar, Edsko de Vries, David Gregg Department of Computer Science, Trinity College Dublin, Dublin 2, Ireland Abstract Although scripting languages are becoming increasingly popular, even mature script- ing language implementations remain interpreted. Several compilers and reimplemen- tations have been attempted, generally focusing on performance. Based on our survey of these reimplementations, we determine that there are three important features of scripting languages that are difficult to compile or reimplement. Since scripting languages are defined primarily through the semantics of their original implementations, they often change semantics between releases. They provide C APIs, used both for foreign-function interfaces and to write third-party extensions. These APIs typically have tight integration with the original implementation, and are used to providelarge standard libraries, which are difficult to re-use, and costly to reimplement. Finally, they support run-time code generation. These features make the important goal of correctness difficult to achieve for compilers and reimplementations. We present a technique to support these features in an ahead-of-time compiler for PHP. Our technique uses the original PHP implementation through the provided C API, both in our compiler, and in our generated code. We support all of these impor- tant scripting language features, particularly focusing on the correctness of compiled programs. Additionally, our approach allows us to automatically support limited fu- ture language changes. We present a discussion and performance evaluation of this technique. Key words: Compiler, Scripting Language 1. Motivation Although scripting languages1 are becoming increasingly popular, most scripting language implementations remain interpreted. Typically, these implementations are slow, between one and two orders of magnitude slower than C.
    [Show full text]
  • Efficient Use of Python on the Clusters
    Efficient use of Python on the clusters Ariel Lozano CÉCI training November 21, 2018 Outline I Analyze our code with profiling tools: I cpu: cProfile, line_profiler, kernprof I memory: memory_profiler, mprof I Being a highly abstract dynamically typed language, how to make a more efficient use of hardware internals? I Numpy and Scipy ecosystem (mainly wrappers to C/Fortran compiled code) I binding to compiled code: interfaces between python and compiled modules I compiling: tools to compile python code I parallelism: modules to exploit multicores Sieve of eratostenes Algorithm to find all prime numbers up to any given limit. Ex: Find all the prime numbers less than or equal to 25: I 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Cross out every number displaced by 2 after 2 up to the limit: I 23 45 67 89 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Move to next n non crossed, cross out each non crossed number displaced by n: I 23 45 67 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 I 2 3 45 67 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 The remaining numbers non crossed in the list are all the primes below limit. 2 Trivial optimization: jump directlyp to n to start crossing out. Then, n must loop only up to limit.
    [Show full text]
  • Shed Skin Documentation Release V0.9.4
    Shed Skin Documentation Release v0.9.4 Mark Dufour the Shed Skin contributors Mar 16, 2017 Contents 1 An experimental (restricted-Python)-to-C++ compiler1 2 Documentation 3 2.1 Shed Skin documentation........................................3 2.1.1 Introduction...........................................3 2.1.2 Typing restrictions.......................................3 2.1.3 Python subset restrictions....................................4 2.1.4 Library limitations.......................................5 2.1.5 Installation...........................................6 2.1.5.1 Windows........................................6 2.1.5.2 UNIX.........................................6 2.1.5.2.1 Using a package manager..........................6 2.1.5.2.2 Manual installation.............................6 2.1.5.3 OSX..........................................7 2.1.5.3.1 Manual installation.............................7 2.1.6 Compiling a standalone program................................8 2.1.7 Generating an extension module................................8 2.1.7.1 Limitations.......................................9 2.1.7.2 Numpy integration...................................9 2.1.8 Distributing binaries...................................... 10 2.1.8.1 Windows........................................ 10 2.1.8.2 UNIX......................................... 10 2.1.9 Multiprocessing......................................... 10 2.1.10 Calling C/C++ code....................................... 11 2.1.10.1 Standard library...................................
    [Show full text]
  • Py++ Project Report
    Py++ Project Report COMS-E6998-3 Advanced Programming Languages and Compilers Fall 2012 Team Members:- Abhas Bodas ([email protected]) Jared Pochtar ([email protected]) Submitted By:- Abhas Bodas ([email protected]) Project Guide:- Prof. Alfred Aho ([email protected]) Page 1 Contents 1. Overview …...................…...................…...................…...................…....................... 3 2. Background Work …...................…...................…...................…..............…............... 4 3. Architecture …...................…...................…...................…...................…..............….. 5 4. Implementation …...................…...................…...................…...................…................ 6 5. Areas of focus / Optimizations …...................…...................…...................…............... 9 6. Results / Conclusion …...................…...................…...................…...................…....... 10 7. Appendix …...................…...................…...................…...................….................…..... 11 Page 2 1. Overview Our project, Py++ paves the way for a compiled Python with speed as the primary focus. Py++ aims to generate fast C/C++ from Python code. We have used the CPython C-API for most of the built in types, objects, and functions. CPython has extensive standard libraries and builtin object support. These objects are quite efficient -- a set, dictionary, or list implementation written in pure C shouldn’t care whether it’s called in an
    [Show full text]
  • Seq: a High-Performance Language for Bioinformatics
    1 1 Seq: A High-Performance Language for Bioinformatics 2 3 ANONYMOUS AUTHOR(S)∗ 4 5 The scope and scale of biological data is increasing at an exponential rate, as technologies like 6 next-generation sequencing are becoming radically cheaper and more prevalent. Over the last two 7 decades, the cost of sequencing a genome has dropped from $100 million to nearly $100—a factor of 6 8 over 10 —and the amount of data to be analyzed has increased proportionally. Yet, as Moore’s Law continues to slow, computational biologists can no longer rely on computing hardware to 9 compensate for the ever-increasing size of biological datasets. In a field where many researchers are 10 primarily focused on biological analysis over computational optimization, the unfortunate solution 11 to this problem is often to simply buy larger and faster machines. 12 Here, we introduce Seq, the first language tailored specifically to bioinformatics, which marries 13 the ease and productivity of Python with C-like performance. Seq is a subset of Python—and in 14 many cases a drop-in replacement—yet also incorporates novel bioinformatics- and computational 15 genomics-oriented data types, language constructs and optimizations. Seq enables users to write 16 high-level, Pythonic code without having to worry about low-level or domain-specific optimizations, 17 and allows for seamless expression of the algorithms, idioms and patterns found in many genomics or 18 bioinformatics applications. On equivalent CPython code, Seq attains a performance improvement of 19 up to two orders of magnitude, and a 175× improvement once domain-specific language features and optimizations are used.
    [Show full text]
  • Python in a Hacker's Toolbox
    Python in a hacker's toolbox v. 2016 Gynvael Coldwind Security PWNing Conference, Warszawa 2016 Keynote? Raczej prelekcja techniczna. O prelegencie All opinions expressed during this presentations are mine and mine alone. They are not opinions of my lawyer, barber and especially not my employer. Menu Sandboxing Język i VM Bezpieczeństwo RE Ta prezentacja zawiera fragmenty ● Data, data, data... ● "On the battlefield with the dragons" (+ Mateusz Jurczyk) ● "Ataki na systemy i sieci komputerowe" ● "Pwning (sometimes) with style - Dragons' notes on CTFs" (+ Mateusz Jurczyk) ● "Python in a hacker's toolbox" Język i VM Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Python Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Język rozwijany przez Python Software Foundation Python Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Język rozwijany przez Python Software Foundation Python Python Enhancement Proposal (w skrócie: PEP) Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Język rozwijany przez Python Software Foundation Python Python Enhancement Proposal (w skrócie: PEP) Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Python Implementacje https://wiki.python.org/moin/PythonImplementations Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... CPython Brython CLPython Jython HotPy pyjs Python Implementacje PyMite PyPy pyvm SNAPpy RapydScript IronPython tinypy https://wiki.python.org/moin/PythonImplementations Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Jython Python Implementacje https://wiki.python.org/moin/PythonImplementations Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my... Brython Python Implementacje https://wiki.python.org/moin/PythonImplementations Python 2.6, 2.7, 3, CPython?, IronPython??, Jython???, oh my..
    [Show full text]
  • High Performance Python (From Training at Europython 2011) Release 0.2
    High Performance Python (from Training at EuroPython 2011) Release 0.2 Ian Ozsvald (@ianozsvald) July 24, 2011 CONTENTS 1 Testimonials from EuroPython 2011 2 2 Motivation 4 2.1 Changelog ................................................ 4 2.2 Credits .................................................. 4 2.3 Other talks ................................................ 5 3 The Mandelbrot problem 6 4 Goal 8 4.1 MacBook Core2Duo 2.0GHz ...................................... 8 4.2 2.9GHz i3 desktop with GTX 480 GPU ................................. 11 5 Using this as a tutorial 13 6 Versions and dependencies 14 7 Pure Python (CPython) implementation 15 8 Profiling with cProfile and line_profiler 18 9 Bytecode analysis 21 10 A (slightly) faster CPython implementation 22 11 PyPy 24 11.1 numpy .................................................. 24 12 Psyco 26 13 Cython 27 13.1 Compiler directives ............................................ 30 13.2 prange .................................................. 31 14 Cython with numpy arrays 32 15 ShedSkin 33 15.1 Profiling ................................................. 34 15.2 Faster code ................................................ 34 16 numpy vectors 35 i 17 numpy vectors and cache considerations 37 18 NumExpr on numpy vectors 39 19 pyCUDA 41 19.1 numpy-like interface ........................................... 42 19.2 ElementWise ............................................... 43 19.3 SourceModule .............................................. 44 20 multiprocessing 46 21 ParallelPython 48 22 Other
    [Show full text]
  • Building Petri Nets Tools Around Neco Compiler
    Building Petri nets tools around Neco compiler Lukasz Fronc and Franck Pommereau {fronc,pommereau}@ibisc.univ-evry.fr IBISC, Universit´ed’Evry/Paris-Saclay´ IBGBI, 23 boulevard de France 91037 Evry´ Cedex, France Abstract. This paper presents Neco that is a Petri net compiler: it takes a Petri net as its input and produces as its output an optimised library to efficiently explore the state space of this Petri net. Neco is also able to work with LTL formulae and to perform model-checking by using SPOT library. We describe the components of Neco, and in particular the exploration libraries it produces, with the aim that one can use Neco in one’s own projects in order to speedup Petri nets executions. Keywords: Petri nets compilation, optimised transition firing, tools de- velopment, explicit state space exploration 1 Introduction Neco is a Petri net compiler: it takes a Petri net as its input and produces as its output a library allowing to explore the Petri net state space. Neco operates on a very general variant of high-level Petri nets based on the Python language (i.e., the values, expressions, etc., decorating a net are expressed in Python) and including various extensions such as inhibitor-, read- and reset-arcs. It can be seen as coloured Petri nets [1] but annotated with the Python language instead of the dialect of ML as it is traditional for coloured Petri nets. Firing transitions of such a high-level Petri net can be accelerated by resorting to a compilation step: this allows to remove most of the data structures that represent the Petri net by inlining the results of querying such structures directly into the generated code.
    [Show full text]
  • 2.5 Python Virtual Machines
    Shannon, Mark (2011) The construction of high-performance virtual machines for dynamic languages. PhD thesis. http://theses.gla.ac.uk/2975/ Copyright and moral rights for this thesis are retained by the author A copy can be downloaded for personal non-commercial research or study, without prior permission or charge This thesis cannot be reproduced or quoted extensively from without first obtaining permission in writing from the Author The content must not be changed in any way or sold commercially in any format or medium without the formal permission of the Author When referring to this work, full bibliographic details including the author, title, awarding institution and date of the thesis must be given Glasgow Theses Service http://theses.gla.ac.uk/ [email protected] The Construction of High-Performance Virtual Machines for Dynamic Languages Mark Shannon, MSc. Submitted for the Degree of Doctor of Philosophy School of Computing Science College of Science and Engineering University of Glasgow November 2011 2 Abstract Dynamic languages, such as Python and Ruby, have become more widely used over the past decade. Despite this, the standard virtual machines for these lan- guages have disappointing performance. These virtual machines are slow, not be- cause methods for achieving better performance are unknown, but because their implementation is hard. What makes the implementation of high-performance virtual machines difficult is not that they are large pieces of software, but that there are fundamental and complex interdependencies between their components. In order to work together correctly, the interpreter, just-in-time compiler, garbage collector and library must all conform to the same precise low-level protocols.
    [Show full text]
  • High-Performance-Python.Pdf
    High Performance Python PRACTICAL PERFORMANT PROGRAMMING FOR HUMANS Micha Gorelick & Ian Ozsvald www.allitebooks.com High Performance Python High PerformancePython High Your Python code may run correctly, but you need it to run faster. By exploring the fundamental theory behind design choices, this practical “Despite its popularity guide helps you gain a deeper understanding of Python’s implementation. in academia and You’ll learn how to locate performance bottlenecks and significantly speed industry, Python is often High Performance up your code in high-data-volume programs. dismissed as too slow for How can you take advantage of multi-core architectures or clusters? Or build a system that can scale up and down without losing reliability? real applications. This Experienced Python programmers will learn concrete solutions to these book sweeps away that and other issues, along with war stories from companies that use high misconception with a performance Python for social media analytics, productionized machine learning, and other situations. thorough introduction to strategies for fast and ■ Get a better grasp of numpy, Cython, and profilers scalable computation ■ Learn how Python abstracts the underlying computer with Python. Python ” architecture —Jake VanderPlas ■ Use profiling to find bottlenecks in CPU time and memory usage University of Washington PRACTICAL PERFORMANT PROGRAMMING FOR HUMANS ■ Write efficient programs by choosing appropriate data structures ■ Speed up matrix and vector computations ■ Use tools to compile Python down to machine code ■ Manage multiple I/O and computational operations concurrently ■ Convert multiprocessing code to run on a local or remote cluster ■ Solve large problems while using less RAM Micha Gorelick, winner of the Nobel Prize in 2046 for his contributions to time travel, went back to the 2000s to study astrophysics, work on data at bitly, and co-found Fast Forward Labs as resident Mad Scientist, working on issues from machine learning to performant stream algorithms.
    [Show full text]
  • Take the Cannoli
    LEAVE THE FEATURES: TAKE THE CANNOLI A Thesis presented to the Faculty of California Polytechnic State University, San Luis Obispo In Partial Fulfillment of the Requirements for the Degree Master of Science in Computer Science by Jonathan Catanio June 2018 c 2018 Jonathan Catanio ALL RIGHTS RESERVED ii COMMITTEE MEMBERSHIP TITLE: Leave the Features: Take the Cannoli AUTHOR: Jonathan Catanio DATE SUBMITTED: June 2018 COMMITTEE CHAIR: Aaron Keen, Ph.D. Professor of Computer Science COMMITTEE MEMBER: Phillip Nico, Ph.D. Professor of Computer Science COMMITTEE MEMBER: John Seng, Ph.D. Professor of Computer Science iii ABSTRACT Leave the Features: Take the Cannoli Jonathan Catanio Programming languages like Python, JavaScript, and Ruby are becoming increas- ingly popular due to their dynamic capabilities. These languages are often much easier to learn than other, statically type checked, languages such as C++ or Rust. Unfortunately, these dynamic languages come at the cost of losing compile-time op- timizations. Python is arguably the most popular language for data scientists and researchers in the artificial intelligence and machine learning communities. As this research becomes increasingly popular, and the problems these researchers face be- come increasingly computationally expensive, questions are being raised about the performance of languages like Python. Language features found in Python, more specifically dynamic typing and run-time modification of object attributes, preclude common static analysis optimizations that often yield improved performance. This thesis attempts to quantify the cost of dynamic features in Python. Namely, the run-time modification of objects and scope as well as the dynamic type system. We introduce Cannoli, a Python 3.6.5 compiler that enforces restrictions on the lan- guage to enable opportunities for optimization.
    [Show full text]
  • Building Petri Nets Tools Around Neco Compiler Lukasz Fronc, Franck Pommereau
    Building Petri nets tools around Neco compiler Lukasz Fronc, Franck Pommereau To cite this version: Lukasz Fronc, Franck Pommereau. Building Petri nets tools around Neco compiler. International Workshop on Petri Nets and Software Engineering (PNSE 2013), Jun 2013, Milano, Italy. (elec. proc.). hal-00911714 HAL Id: hal-00911714 https://hal.archives-ouvertes.fr/hal-00911714 Submitted on 29 Nov 2013 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Building Petri nets tools around Neco compiler Lukasz Fronc and Franck Pommereau {fronc,pommereau}@ibisc.univ-evry.fr IBISC, Universit´ed’Evry/Paris-Saclay´ IBGBI, 23 boulevard de France 91037 Evry´ Cedex, France Abstract. This paper presents Neco that is a Petri net compiler: it takes a Petri net as its input and produces as its output an optimised library to efficiently explore the state space of this Petri net. Neco is also able to work with LTL formulae and to perform model-checking by using SPOT library. We describe the components of Neco, and in particular the exploration libraries it produces, with the aim that one can use Neco in one’s own projects in order to speedup Petri nets executions.
    [Show full text]