About the pybind11 module

Contents

About the pybind11 module#

The engine is written in C++, and the five-line script on the home page drives it from Python. This module explains the bridge between the two: pybind11, a library that makes C++ functions and classes callable from Python.

The first chapter builds the smallest possible bridge, for the lj_energy function from the C++ module, and calls it from Python. The second reads the engine’s real bridge and follows sim.run() from Python into C++. The third shows how the same module runs the simulations on these pages, inside your browser. The first two build on the C++ module: the first on Functions and on compiling, the second on Classes and the plug.

As in the C++ module, every example is a file you can build and run, and every output on the pages comes from running it. Each chapter ends with a few questions; click a question to see its answer.

Chapters:

  1. A first binding

  2. Binding the engine

  3. The same module, in your browser

Next#

Start with A first binding. It needs Python 3 and the same C++ compiler as the C++ module.