Skip to content

Python Build

Rafael C Fatou edited this page Dec 24, 2018 · 5 revisions

Introduction

A python wrapped version of Titan is available for those who want a more intutive user experience without sacrificing the speed improvements and core functionality of Titan C++.

The python version of Titan, or pythonTitan, works by wrapping the C++ core and functions in PyBind11 binding functions that can be imported and called using standard Python.

Functionality

Titan's Python build mirrors most of the C++ version's functionality through binded functions that take python commands as inputs, translate them to C++ syntax, call the C++ functions and send the outputs back to the python interface.

While seamless transition from writing Titan C++ to python code is one of the main goals pythonTitan, some functions may employ slightly different syntax for either practical or unavoidable reasons. Please review the python syntax section for more information about particular cases.

The embedded graphics rendering functionality of C++ Titan is currently unavailable in pythonTitan. Research is ongoing on how to efficiently enable it across languages. The user may still use an external graphics library to render the simulation's data.

Performance

Due to underlaying use of C++ code and CUDA in Titan's python wrapped version, running performance of the simulations is comparable to the C++ version.

Lag is, however, introduced at the start of the simulation in comparison to the C++ version. This is a result of the python code needing to initiate the C++ core as well as translate function calls and input data (e.g Numpy arrays, mass objects) into resources compatible with the underlying C++ architecture. Reduction of the starting lag is a work in progress.

Stability

pythonTitan is inherently less stable that it's C++ version due to the added architectural layers implemented over the C++ core. Python's bindings are susceptible to added stream buffer and translation errors and unresolved bugs in the C++ engine may also affect the python build. In rare cases, bugs within the C++ code that are not apparent in the C++ build will become relevant in the Python build.

Users may use the same Issues section to report bugs encountered using the python version.

Development Schedule

Everytime Titan's C++ master branch is updated, development of python bindings for the new functionality begins. Python updates are launched as soon as testing is finished iregardless of version, meaning Titan's python releases may lag behind the C++ branch while the binding and testing phases are in progress.

Numpy

Numpy arrays and commands are fully compatble with Titan and used as a replacement for C++'s vectors and arrays.

Whenever a function that returns an array is called, the result will be returned in the form of a Numpy array.

Review of advantages and disadvantages over Titan C++

Advantages:

  • Improved user experience inherent to Python code
  • Compatible with Numpy and other Python Libraries
  • Straightforward importing and no need for a Cmake file

Disadvantages:

  • Increased inestability
  • Slower update schedule
  • Simulation start lag (runnign speed after start remains the same as C++ version)
  • Graphics rendering currently unavailable (work in progress)