Running the Jupyter Notebook on the linux server over ssh
ssh into the server
clone the psim repo add --recursive flag to also get lin
cd psim
git checkout python-wrappers
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
ipython kernel install --user --name=venv
jupyter notebook --no-browser --port 1234
Start an SSH tunnel to the server, see more info
on unix use ssh -NL 1234:localhost:1234 username@serverip in a new local terminal
copy the URL in the output from step 9 into your browser.
Something like the following should come up.
Click estimatortest and then open Orbit-estimator-test.ipynb
Change the kernel to venv.
Everything should be working now. I would recommend opening another ssh connection to do git stuff, or make edits in vim.
Python Wrappers
There are python wrappers for some C++ types. I am using pybind11 which has great documentation and many examples. pybind11 is just a header only library that makes it easy to write python extensions, https://thomasnyberg.com/what_are_extension_modules.html .
The C++ sources need to be compiled as a shared library to be imported by python.
I am using cppimport to do this automatically on import but it is theoretically possible to compile using cmake, pio, pip ...
To test the compilation run python estimatortest/pythonwrapper/test_compilation.py Which should print a bunch of compiler errors if there is a mistake.
psim/estimatortest/pwrap.cpp Is the main module file.
The giant comment at the top is used in a python script that sets the compiler configuration.
cfg['dependencies'] is a list of filenames that are checked for changes to see if recompiling is needed.
cfg['sources'] are the sources to compile.
cfg['include_dirs'] are the include directories.
cfg['compiler_args'] are the compiler args, I also made a section for platform specific compiler args because my mac needed '-mmacosx-version-min=10.9' to compile.
orb wrappers
psim/estimatortest/orb_ext.cpp Has the orb wrappers.
For now orb::Orbit as python type orb_Orbit is mostly wrapped.
lin wrappers
psim/estimatortest/lin_ext.cpp Has the lin wrappers.
Because lin uses templates, each type that you want to use in python must be specifically wrapped. For example, right now in lin_ext.cpp I have:
These create python types named lin_Matrix6x6d and lin_Vector3d
for C++ types lin::Matrix<double, 6, 6, 6, 6> and lin::Vector<double, 3, 3>.
These are compatible with numpy arrays, so numpy.array(lin_Vector3d([1.0,2.0,3.0])) will work.
The wrapper doesn't wrap all of the lin features, so it's usually best to always convert the lin types into numpy arrays if you want to do math with them in python.
If you need other lin types in python make sure to wrap them in this file using the macros.
Documentation Evidence
I'll make a post to ReadTheDocs about the Orbit estimator.
Python Estimator Testing
Summary
The goal is to quickly test and see the accuracy of an estimator in Jupyter Notebook. psim/estimatortest/Orbit-estimator-test.ipynb is an example.
Running the Jupyter Notebook on the linux server over ssh
ssh into the server
clone the psim repo add
--recursive
flag to also get lincd psim
git checkout python-wrappers
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
ipython kernel install --user --name=venv
jupyter notebook --no-browser --port 1234
Start an SSH tunnel to the server, see more info on unix use
ssh -NL 1234:localhost:1234 username@serverip
in a new local terminalcopy the URL in the output from step 9 into your browser. Something like the following should come up.
Click
estimatortest
and then openOrbit-estimator-test.ipynb
Change the kernel to venv.
Everything should be working now. I would recommend opening another ssh connection to do git stuff, or make edits in vim.
Python Wrappers
There are python wrappers for some C++ types. I am using pybind11 which has great documentation and many examples. pybind11 is just a header only library that makes it easy to write python extensions, https://thomasnyberg.com/what_are_extension_modules.html .
The C++ sources need to be compiled as a shared library to be imported by python. I am using cppimport to do this automatically on import but it is theoretically possible to compile using cmake, pio, pip ...
To test the compilation run
python estimatortest/pythonwrapper/test_compilation.py
Which should print a bunch of compiler errors if there is a mistake.psim/estimatortest/pwrap.cpp
Is the main module file.The giant comment at the top is used in a python script that sets the compiler configuration.
cfg['dependencies']
is a list of filenames that are checked for changes to see if recompiling is needed.cfg['sources']
are the sources to compile.cfg['include_dirs']
are the include directories.cfg['compiler_args']
are the compiler args, I also made a section for platform specific compiler args because my mac needed'-mmacosx-version-min=10.9'
to compile.orb wrappers
psim/estimatortest/orb_ext.cpp
Has theorb
wrappers.For now
orb::Orbit
as python typeorb_Orbit
is mostly wrapped.lin wrappers
psim/estimatortest/lin_ext.cpp
Has thelin
wrappers.Because
lin
uses templates, each type that you want to use in python must be specifically wrapped. For example, right now inlin_ext.cpp
I have:These create python types named
lin_Matrix6x6d
andlin_Vector3d
for C++ typeslin::Matrix<double, 6, 6, 6, 6>
andlin::Vector<double, 3, 3>
. These are compatible with numpy arrays, so numpy.array(lin_Vector3d([1.0,2.0,3.0])) will work. The wrapper doesn't wrap all of thelin
features, so it's usually best to always convert the lin types into numpy arrays if you want to do math with them in python.If you need other
lin
types in python make sure to wrap them in this file using the macros.Documentation Evidence
I'll make a post to ReadTheDocs about the Orbit estimator.