Week 3: Embedding and automated bindings

Published: 06/15/2023


Since last week, I was going over the Pybind11 documentation and also looking into automated binding generators. I have been mulling over what it means to provide bindings and how the interface is going to change. I tested out cppyy and its examples, but my mentor suggested that it may not be the right fit for the project as it is unlikely to be able to handle templates without more involved bindings.

However, as I began setting up a new repository for the bindings, it occurred to me that for backwards compatibility, though providing a compiled extension will be useful for more users, switching over from Lua really needs an embedding of the Python interpreter! I am fairly sure of this, as the binary (from last week's main.cpp) essentially copies into C++ data from Lua. Embedding is part of Pybind11's feature-set:

// Starts the interpreter and keeps it alive
py::scoped_interpreter guard{};

However, there's a catch, we need both the bindings (to run seams-core) from python so we can transfer data into the C++ in a robust manner! This means my timeline is a little altered, I will need to write the compiled extension, and then interface that to the main.cpp. So:

from pyseams import PointCloud
pinp = PointCloud(...)

Which will then be read in on the C++ side by the embedded interpreter. Sort of like the existing examples:

print("\n Welcome to the manual lua function evaluation environment.\n");
for frame=targetFrame,finalFrame,frameGap do
   resCloud=readFrame(trajectory,frame,resCloud,oxygenAtomType,isSlice,sliceLowerLimits,sliceUpperLimits) --- Get the frame
   nList=neighborList(cutoffRadius, resCloud, oxygenAtomType); --- Calculate the neighborlist by ID
   resCloud=chillPlus_cij(resCloud,nList,isSlice); --- Calculate Cij (cloud,slice)
   resCloud=chillPlus_iceType(resCloud,nList,outDir,targetFrame,isSlice,chillPlus_noMod); --- Write out data (cloud,slice,name)
   writeDump(resCloud,outDir,dumpChillP); --- Dump the rescloud which currently has CHILL Plus classifications
   --- Modified CHILL+
   avgQ6=averageQ6(resCloud,nList,isSlice); --- Average Q6 (cloud,slice)
   resCloud=modifyChill(resCloud,avgQ6); --- Modification (cloud,q6)
   percentage_Ice(resCloud,outDir,targetFrame,isSlice,chillPlus_mod); --- Post reclassification writeOut
   writeDump(resCloud,outDir,dumpSupaaP); --- Dump the rescloud which now has the supaa CHILL Plus Trajectory
   --- Get the largest ice cluster. Here, iceNeighbourList is the neighbour list by index.
   clusterAnalysis(outDir, clusterCloud, resCloud, nList, iceNeighbourList, cutoffRadius, targetFrame, "q6");
   --- Recenter the cluster such that the centroid is at the center of the simulation box
   recenterCluster(clusterCloud, iceNeighbourList);
   writeDump(resCloud,outDir,largestClusterDump); --- Dump the recentered largest ice cluster

This is a tentative design which I will discuss with my mentor this week.

Check-in Questions

What did you do this week?

  • Looked into automated bindings (cppyy)
  • Realized I need to embed an interpreter for backwards compatibility
  • Started designing the classes based on pypotlib

    What is coming up next?

  • I'm still planning on that personal site
  • I will publicly post my repo for the python-bindings
    • My mentor will move it into the dseams workspace
    • This will be my first time working in an organization on Github
  • I will start a design document
  • I will go over the C-Python documentation to understand the automated / manual bindings system in a bit more detail

The goal is to have working code examples by my midway evaluation as per the original plan.

Did you get stuck anywhere?

  • The embedding of the interpreter was something which I hadn't considered, not even in my proposal
  • I was interested (and a bit caught up on) how automatic bindings work
  • I am having some trouble (the "tyranny of a blank page") getting started with runnable code
    • Especially when I realized I cannot run the exact code (main.cpp) until after the bindings are complete!
  • I was having trouble formatting my posts on the PSF GSoC blogroll
    • Figured out I can use this site (or pandoc)