From 0e9ecec2ed83c94bd3a3cb4a638d724e0a6d1185 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 17:10:23 -0400 Subject: [PATCH 01/12] initial implementation --- CMakeLists.txt | 44 +++++++ README.md | 48 ++++++++ cmake/cmake | 4 + cmake/xo_pyprocessConfig.cmake.in | 4 + include/README.md | 1 + src/pyprocess/CMakeLists.txt | 8 ++ src/pyprocess/pyprocess.cpp | 183 ++++++++++++++++++++++++++++++ src/pyprocess/pyprocess.hpp.in | 25 ++++ 8 files changed, 317 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 cmake/cmake create mode 100644 cmake/xo_pyprocessConfig.cmake.in create mode 100644 include/README.md create mode 100644 src/pyprocess/CMakeLists.txt create mode 100644 src/pyprocess/pyprocess.cpp create mode 100644 src/pyprocess/pyprocess.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..af0bae5b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +# xo-pyprocess/CMakeLists.txt + +cmake_minimum_required(VERSION 3.10) + +project(xo_pyprocess VERSION 0.1) +enable_language(CXX) + +# common XO cmake macros (see github.com:Rconybea/xo-cmake) +include(xo_macros/xo_cxx) +include(xo_macros/code-coverage) + +# ---------------------------------------------------------------- +# unit test setup + +enable_testing() +# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) +add_code_coverage() +# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. +# we're not interested in code coverage for these sources. +# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; +# rather, want coverage on the code that the unit tests exercise. +# +# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target +# +add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*) + +# ---------------------------------------------------------------- +# c++ settings (usually temporary) + +set(PROJECT_CXX_FLAGS "") +add_definitions(${PROJECT_CXX_FLAGS}) + +xo_toplevel_compile_options() + +# ---------------------------------------------------------------- +# sources + +add_subdirectory(src/pyprocess) +#add_subdirectory(utest) + +# ---------------------------------------------------------------- +# provide find_package() support + +xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) diff --git a/README.md b/README.md new file mode 100644 index 00000000..2ad68ffb --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# python bindings for c++ stochastic process library (xo-process) + +# build + install +``` +$ cd xo-pyprocess +$ mkdir build +$ cd build +$ INSTALL_PREFIX=/usr/local # or wherever you prefer, e.g. ~/local +$ cmake \ + -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake \ + -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} .. +$ make +$ make install +``` +(also see .github/workflows/main.yml) + +# build for unit test coverage +``` +$ cd xo-pyprocess +$ mkdir build-ccov +$ cd build-ccov +$ cmake \ + -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake \ + -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ + -DCODE_COVERAGE=ON \ + -DCMAKE_BUILD_TYPE=Debug .. +``` + +# LSP (language server) support + +LSP looks for compile commands in the root of the source tree; +while Cmake creates them in the root of its build directory. + +``` +$ cd xo-pyprocess +$ ln -s build/compile_commands.json # supply compile commands to LSP +``` + +# Examples + +Assumes `xo-pyprocess` installed to `~/local2/lib` + +``` +PYTHONPATH=~/local2/lib python +>>> import pyprocess +>>> dir(pyprocess) +``` diff --git a/cmake/cmake b/cmake/cmake new file mode 100644 index 00000000..b49b4828 --- /dev/null +++ b/cmake/cmake @@ -0,0 +1,4 @@ + /home/roland/proj/xo-pyprocess/cmake: + drwxr-xr-x 2 roland roland 4096 Oct 12 21:49 . + drwxr-xr-x 6 roland roland 4096 Oct 12 21:49 .. + -rw-r--r-- 1 roland roland 125 Oct 12 21:49 xo_pyprocessConfig.cmake.in diff --git a/cmake/xo_pyprocessConfig.cmake.in b/cmake/xo_pyprocessConfig.cmake.in new file mode 100644 index 00000000..9c15f36a --- /dev/null +++ b/cmake/xo_pyprocessConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/include/README.md b/include/README.md new file mode 100644 index 00000000..aca8853c --- /dev/null +++ b/include/README.md @@ -0,0 +1 @@ +placeholder for future pyprocess #include files diff --git a/src/pyprocess/CMakeLists.txt b/src/pyprocess/CMakeLists.txt new file mode 100644 index 00000000..1b6c5347 --- /dev/null +++ b/src/pyprocess/CMakeLists.txt @@ -0,0 +1,8 @@ +# xo_pyprocess/src/pyprocess/CMakeLists.txt + +set(SELF_LIB pyprocess) +set(SELF_SRCS pyprocess.cpp) + +xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) + +xo_pybind11_dependency(${SELF_LIB} process) diff --git a/src/pyprocess/pyprocess.cpp b/src/pyprocess/pyprocess.cpp new file mode 100644 index 00000000..21c2f287 --- /dev/null +++ b/src/pyprocess/pyprocess.cpp @@ -0,0 +1,183 @@ +/* @file pyprocess.cpp */ + +// note: need pyprocess/ here bc pyprocess.hpp is generated, located in build directory +#include "src/pyprocess/pyprocess.hpp" +#include "xo/pywebutil/pywebutil.hpp" +#include "xo/process/init_process.hpp" +#include "xo/process/UpxToConsole.hpp" +#include "xo/process/StochasticProcess.hpp" +#include "xo/process/BrownianMotion.hpp" +#include "xo/process/ExpProcess.hpp" +#include "xo/process/RealizationSource.hpp" +#include "xo/pyreactor/pyreactor.hpp" +#include "xo/reactor/EventStore.hpp" +#include "xo/reactor/PolyAdapterSink.hpp" +#include "xo/randomgen/random_seed.hpp" +#include "xo/randomgen/xoshiro256.hpp" +#include +#include +#include + +/* xo::ref::intrusive_ptr is an intrusively-reference-counted pointer. + * always safe to create one from a T* p + * (since refcount is directly accessible from p) + */ +PYBIND11_DECLARE_HOLDER_TYPE(T, xo::ref::intrusive_ptr, true); + +namespace xo { + using xo::reactor::AbstractSink; + using xo::reactor::AbstractEventStore; + using xo::reactor::StructEventStore; + using xo::reactor::PolyAdapterSink; + using xo::json::PrintJsonSingleton; + using xo::time::utc_nanos; + using xo::rng::Seed; + using xo::rng::xoshiro256ss; + using xo::ref::rp; + namespace py = pybind11; + + namespace process { + PYBIND11_MODULE(PYPROCESS_MODULE_NAME(), m) { + /* ensure process/ will be initialized */ + InitSubsys::require(); + /* ..and immediately perform init steps */ + Subsystem::initialize_all(); + + /* e.g. py wrapper for xo::reactor::ReactorSource */ + PYREACTOR_IMPORT_MODULE(); + /* e.g. py wrapper for xo::web::EndpointDescr */ + PYWEBUTIL_IMPORT_MODULE(); + + m.doc() = "pybind11 plugin for xo.process"; + + m.def("make_brownian_motion", + [](utc_nanos start_tm, + double annual_volatility) { + Seed seed; + + return BrownianMotion::make(start_tm, + annual_volatility, + seed); + }, + "create new BrownianMotion instance"); + + m.def("make_exponential_brownian_motion", + [](utc_nanos start_tm, + double start_value, + double annual_volatility) { + Seed seed; + + return ExpProcess::make(start_value /*scale*/, + BrownianMotion::make(start_tm, + annual_volatility, + seed)); + }, + py::arg("start_tm"), py::arg("start_value"), py::arg("annual_volatility")); + + py::class_, + xo::ref::rp>>(m, "StochasticProcess") + .def_property_readonly("t0", &StochasticProcess::t0) + .def_property_readonly("t0_value", &StochasticProcess::t0_value) + .def("exterior_sample", &StochasticProcess::exterior_sample) + .def("__repr__", &StochasticProcess::display_string); + + py::class_, + StochasticProcess, + xo::ref::rp>>(m, "BrownianMotion"); + //.def("exterior_sample", &BrownianMotion::exterior_sample) + //.def("__repr__", &BrownianMotion::display_string); + + py::class_, + xo::ref::rp>(m, "ExpProcess") + .def_property_readonly("exponent_process", + [](ExpProcess & self) { + return self.exponent_process().promote(); + }); + + m.def("make_tracer", + &RealizationTracer::make); + + py::class_, + xo::ref::rp>>(m, "RealizationTracer"); + + /* e.g. + * import datetime as dt + * t0=dt.datetime.now() + * ebm=pyprocess.make_exponential_brownian_motion(t0, 0.5) + * s=pyprocess.make_realization_source(ebm, dt.timedelta(seconds=1)) + */ + m.def("make_realization_source", + [](xo::ref::rp> p, + xo::time::nanos sample_dt) + { + auto tracer = RealizationTracer::make(p); + + return RealizationSource::make(tracer, + sample_dt); + }); + + /* note: providing __repr__ changes printing behavior, + * but uses default printer for inherited std::pair<..> + */ + py::class_(m, "UpxEvent") + .def_property_readonly("tm", &UpxEvent::tm) + .def_property_readonly("upx", &UpxEvent::upx) + .def("__repr__", &UpxEvent::display_string); + + py::class_, + reactor::ReactorSource, + xo::ref::rp>>(m, "RealizationSource") + .def_property_readonly("current_ev", &RealizationSource::current_ev); + + py::class_> + (m, "UpxToConsole"); + + using UpxEventStore = StructEventStore; + + /* see also: KalmanFilterStateEventStore in [pyfilter/pyfilter.cpp] + */ + py::class_> + (m, "UpxEventStore") + .def_static("make", &UpxEventStore::make) + .def_property_readonly("empty", &UpxEventStore::empty) + .def_property_readonly("size", &UpxEventStore::size) + .def("last_n", &UpxEventStore::last_n, py::arg("n")) + .def("last_dt", &UpxEventStore::last_dt, py::arg("dt")); + //.def("__repr__", &UpxEventStore::display_string); + + /* temporary -- to reveal compiler errors */ + using UpxAdapterSink = PolyAdapterSink; + + py::class_>(m, "UpxAdapterSink") + .def_static("make", &UpxAdapterSink::make); + + /* prints + * std::pair + * pairs + */ + m.def("make_realization_printer", &UpxToConsole::make); + +#ifdef OBSOLETE + /* this implementation fails -- looks like .so libraries + * have separate typeinfo for std::pair + * and don't find each other. + */ + m.def("make_realization_printer2", + [] + { + return reactor::TemporaryTest::realization_printer(); + }); +#endif + + } /*pyprocess*/ + } /*namespace process*/ +} /*namespace xo*/ + +/* end pyprocess.cpp */ diff --git a/src/pyprocess/pyprocess.hpp.in b/src/pyprocess/pyprocess.hpp.in new file mode 100644 index 00000000..d2f5cec1 --- /dev/null +++ b/src/pyprocess/pyprocess.hpp.in @@ -0,0 +1,25 @@ +/* @file pyprocess.hpp + * + * automatically generated from src/pyprocess/pyprocess.hpp.in + * see src/pyprocess/CMakeLists.txt + */ + +/* python requires module name = library name + * example: + * PYBIND11_MODULE(PYPROCESS_MODULE_NAME(), m) { ... } + */ +#define PYPROCESS_MODULE_NAME() @SELF_LIBRARY_NAME@ + +/* example: + * py::module_::import(PYPROCESS_MODULE_NAME_STR) + */ +#define PYPROCESS_MODULE_NAME_STR "@SELF_LIBRARY_NAME@" + +/* example: + * PYPROCESS_IMPORT_MODULE() + * replaces + * py::module_::import("pyprocess") + */ +#define PYPROCESS_IMPORT_MODULE() py::module_::import("@SELF_LIBRARY_NAME@") + +/* end pyprocess.hpp */ From ce5c9145667a842b52c36670ffa1a601b9bc7220 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 17:10:51 -0400 Subject: [PATCH 02/12] + .gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f52f1311 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# lsp keeps state here +.cache +# typical build directory +build +# lsp: symlink to file in build directory (established manually) +compile_commands.json From 1a1383c724524af5419e9a486b994f7f04e0ec7a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 17:13:32 -0400 Subject: [PATCH 03/12] compile fix: include path to pyprocess.hpp --- src/pyprocess/pyprocess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyprocess/pyprocess.cpp b/src/pyprocess/pyprocess.cpp index 21c2f287..56b5b1f8 100644 --- a/src/pyprocess/pyprocess.cpp +++ b/src/pyprocess/pyprocess.cpp @@ -1,7 +1,7 @@ /* @file pyprocess.cpp */ // note: need pyprocess/ here bc pyprocess.hpp is generated, located in build directory -#include "src/pyprocess/pyprocess.hpp" +#include "pyprocess.hpp" #include "xo/pywebutil/pywebutil.hpp" #include "xo/process/init_process.hpp" #include "xo/process/UpxToConsole.hpp" From 20b899fd5ef418ad56f8d5679c4c8ad1ff0cd2f3 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 18:05:25 -0400 Subject: [PATCH 04/12] github: + workflow --- .github/workflows/main.yml | 386 +++++++++++++++++++++++++++++++++++++ 1 file changed, 386 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..4bfa8333 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,386 @@ +name: build xo-pyprocess + dependencies + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - name: checkout source + uses: actions/checkout@v3 + + - name: Install catch2 + # install catch2. see [[https://stackoverflow.com/questions/57982945/how-to-apt-get-install-in-a-github-actions-workflow]] + run: sudo apt-get install -y catch2 + + - name: Install pybind11-dev + run: sudo apt-get install -y pybind11-dev + + # ---------------------------------------------------------------- + + - name: Clone xo-cmake + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-cmake + path: repo/xo-cmake + + - name: Configure xo-cmake + run: cmake -B ${{github.workspace}}/build_xo-cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/xo-cmake + + - name: Build xo-cmake (trivial) + run: cmake --build ${{github.workspace}}/build_xo-cmake --config ${{env.BUILD_TYPE}} + + - name: Install xo-cmake + run: cmake --install ${{github.workspace}}/build_xo-cmake + + # ---------------------------------------------------------------- + + - name: Clone indentlog + uses: actions/checkout@v3 + with: + repository: Rconybea/indentlog + path: repo/indentlog + + - name: Configure indentlog + # configure cmake for indentlog in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_indentlog -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/indentlog + + - name: Build indentlog + run: cmake --build ${{github.workspace}}/build_indentlog --config ${{env.BUILD_TYPE}} + + - name: Install indentlog + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_indentlog + + # ---------------------------------------------------------------- + + - name: Clone subsys + uses: actions/checkout@v3 + with: + repository: Rconybea/subsys + path: repo/subsys + + - name: Configure subsys + # configure cmake for subsys in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_subsys -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/subsys + + - name: Build subsys + run: cmake --build ${{github.workspace}}/build_subsys --config ${{env.BUILD_TYPE}} + + - name: Install subsys + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_subsys + + # ---------------------------------------------------------------- + + - name: Clone refcnt + uses: actions/checkout@v3 + with: + repository: Rconybea/refcnt + path: repo/refcnt + + - name: Configure refcnt + # configure cmake for refcnt in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_refcnt -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/refcnt + + - name: Build refcnt + run: cmake --build ${{github.workspace}}/build_refcnt --config ${{env.BUILD_TYPE}} + + - name: Install refcnt + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_refcnt + + # ---------------------------------------------------------------- + + - name: Clone reflect + uses: actions/checkout@v3 + with: + repository: Rconybea/reflect + path: repo/reflect + + - name: Configure reflect + # configure cmake for reflect in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_reflect -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/reflect + + - name: Build reflect + run: cmake --build ${{github.workspace}}/build_reflect --config ${{env.BUILD_TYPE}} + + - name: Install reflect + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_reflect + + # ---------------------------------------------------------------- + + - name: Clone callback + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-callback + path: repo/callback + + - name: Configure callback + # configure cmake for callback in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_callback -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/callback + + - name: Build callback + run: cmake --build ${{github.workspace}}/build_callback --config ${{env.BUILD_TYPE}} + + - name: Install callback + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_callback + + # ---------------------------------------------------------------- + + - name: Clone webutil + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-webutil + path: repo/webutil + + - name: Configure webutil + # configure cmake for webutil in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_webutil -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/webutil + + - name: Build webutil + run: cmake --build ${{github.workspace}}/build_webutil --config ${{env.BUILD_TYPE}} + + - name: Install webutil + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_webutil + + # ---------------------------------------------------------------- + + - name: Clone pywebutil + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pywebutil + path: repo/pywebutil + + - name: Configure pywebutil + # configure cmake for pywebutil in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pywebutil -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pywebutil + + - name: Build pywebutil + run: cmake --build ${{github.workspace}}/build_pywebutil --config ${{env.BUILD_TYPE}} + + - name: Install pywebutil + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pywebutil + + # ---------------------------------------------------------------- + + - name: Clone printjson + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-printjson + path: repo/printjson + + - name: Configure printjson + # configure cmake for printjson in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_printjson -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/printjson + + - name: Build printjson + run: cmake --build ${{github.workspace}}/build_printjson --config ${{env.BUILD_TYPE}} + + - name: Install printjson + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_printjson + + # ---------------------------------------------------------------- + + - name: Clone randomgen + uses: actions/checkout@v3 + with: + repository: Rconybea/randomgen + path: repo/randomgen + + - name: Configure randomgen + # configure cmake for randomgen in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_randomgen -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/randomgen + + - name: Build randomgen + run: cmake --build ${{github.workspace}}/build_randomgen --config ${{env.BUILD_TYPE}} + + - name: Install randomgen + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_randomgen + + # ---------------------------------------------------------------- + + - name: Clone ordinaltree + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-ordinaltree + path: repo/ordinaltree + + - name: Configure ordinaltree + # configure cmake for ordinaltree in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_ordinaltree -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/ordinaltree + + - name: Build ordinaltree + run: cmake --build ${{github.workspace}}/build_ordinaltree --config ${{env.BUILD_TYPE}} + + - name: Install ordinaltree + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_ordinaltree + + # ---------------------------------------------------------------- + + - name: Clone reactor + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-reactor + path: repo/reactor + + - name: Configure reactor + # configure cmake for reactor in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_reactor -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/reactor + + - name: Build reactor + run: cmake --build ${{github.workspace}}/build_reactor --config ${{env.BUILD_TYPE}} + + - name: Install reactor + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_reactor + + # ---------------------------------------------------------------- + + - name: Clone simulator + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-simulator + path: repo/simulator + + - name: Configure simulator + # configure cmake for simulator in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_simulator -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/simulator + + - name: Build simulator + run: cmake --build ${{github.workspace}}/build_simulator --config ${{env.BUILD_TYPE}} + + - name: Install simulator + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_simulator + + # ---------------------------------------------------------------- + + - name: Clone process + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-process + path: repo/process + + - name: Configure process + # configure cmake for process in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_process -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/process + + - name: Build process + run: cmake --build ${{github.workspace}}/build_process --config ${{env.BUILD_TYPE}} + + - name: Install process + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_process + + # ---------------------------------------------------------------- + + - name: Clone pyutil + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pyutil + path: repo/pyutil + + - name: Configure pyutil + # configure cmake for pyutil in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pyutil -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyutil + + - name: Build pyutil + run: cmake --build ${{github.workspace}}/build_pyutil --config ${{env.BUILD_TYPE}} + + - name: Install pyutil + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pyutil + + # ---------------------------------------------------------------- + + - name: Clone pyreflect + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pyreflect + path: repo/pyreflect + + - name: Configure pyreflect + # configure cmake for pyreflect in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pyreflect -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyreflect + + - name: Build pyreflect + run: cmake --build ${{github.workspace}}/build_pyreflect --config ${{env.BUILD_TYPE}} + + - name: Install pyreflect + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pyreflect + + # ---------------------------------------------------------------- + + - name: Clone pyprintjson + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pyprintjson + path: repo/pyprintjson + + - name: Configure pyprintjson + # configure cmake for pyprintjson in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pyprintjson -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyprintjson + + - name: Build pyprintjson + run: cmake --build ${{github.workspace}}/build_pyprintjson --config ${{env.BUILD_TYPE}} + + - name: Install pyprintjson + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pyprintjson + + # ---------------------------------------------------------------- + + - name: Clone pyreactor + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pyreactor + path: repo/pyreactor + + - name: Configure pyreactor + # configure cmake for pyreactor in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pyreactor -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyreactor + + - name: Build pyreactor + run: cmake --build ${{github.workspace}}/build_pyreactor --config ${{env.BUILD_TYPE}} + + - name: Install pyreactor + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pyreactor + + # ---------------------------------------------------------------- + + - name: Configure self (pyprocess) + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build_pyprocess -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build self (pyprocess) + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build_pyprocess --config ${{env.BUILD_TYPE}} + + - name: Test self (pyprocess) + working-directory: ${{github.workspace}}/build_pyprocess + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} From 1fe15afb57f26504d9e4d7e1f7ad6d8fd03b0505 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 18:07:50 -0400 Subject: [PATCH 05/12] github: fix dep ordering --- .github/workflows/main.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4bfa8333..a760a879 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -161,6 +161,25 @@ jobs: # ---------------------------------------------------------------- + - name: Clone pyutil + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pyutil + path: repo/pyutil + + - name: Configure pyutil + # configure cmake for pyutil in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pyutil -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyutil + + - name: Build pyutil + run: cmake --build ${{github.workspace}}/build_pyutil --config ${{env.BUILD_TYPE}} + + - name: Install pyutil + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pyutil + + # ---------------------------------------------------------------- + - name: Clone pywebutil uses: actions/checkout@v3 with: @@ -294,25 +313,6 @@ jobs: # ---------------------------------------------------------------- - - name: Clone pyutil - uses: actions/checkout@v3 - with: - repository: Rconybea/xo-pyutil - path: repo/pyutil - - - name: Configure pyutil - # configure cmake for pyutil in dedicated build directory. - run: cmake -B ${{github.workspace}}/build_pyutil -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyutil - - - name: Build pyutil - run: cmake --build ${{github.workspace}}/build_pyutil --config ${{env.BUILD_TYPE}} - - - name: Install pyutil - # install into ${{github.workspace}}/local - run: cmake --install ${{github.workspace}}/build_pyutil - - # ---------------------------------------------------------------- - - name: Clone pyreflect uses: actions/checkout@v3 with: From 361a957e3c263dcec19011c36fb12d18f4b245f4 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 24 Oct 2023 12:24:03 -0400 Subject: [PATCH 06/12] + .hpp deps pyreactor,pywebutil --- src/pyprocess/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pyprocess/CMakeLists.txt b/src/pyprocess/CMakeLists.txt index 1b6c5347..03237164 100644 --- a/src/pyprocess/CMakeLists.txt +++ b/src/pyprocess/CMakeLists.txt @@ -6,3 +6,5 @@ set(SELF_SRCS pyprocess.cpp) xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) xo_pybind11_dependency(${SELF_LIB} process) +xo_pybind11_header_dependency(${SELF_LIB} pyreactor) +xo_pybind11_header_dependency(${SELF_LIB} pywebutil) From 500855f426b5aaa808b580b81a5ff8c9e8f60b4f Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 24 Oct 2023 16:16:38 -0400 Subject: [PATCH 07/12] build: streamline .cmake instructions --- CMakeLists.txt | 35 ++----------------------------- EXAMPLES | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 EXAMPLES diff --git a/CMakeLists.txt b/CMakeLists.txt index af0bae5b..36786fb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,42 +3,11 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyprocess VERSION 0.1) -enable_language(CXX) -# common XO cmake macros (see github.com:Rconybea/xo-cmake) -include(xo_macros/xo_cxx) -include(xo_macros/code-coverage) +include(xo_macros/xo-project-macros) -# ---------------------------------------------------------------- -# unit test setup - -enable_testing() -# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) -add_code_coverage() -# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. -# we're not interested in code coverage for these sources. -# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; -# rather, want coverage on the code that the unit tests exercise. -# -# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target -# -add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*) - -# ---------------------------------------------------------------- -# c++ settings (usually temporary) - -set(PROJECT_CXX_FLAGS "") -add_definitions(${PROJECT_CXX_FLAGS}) - -xo_toplevel_compile_options() - -# ---------------------------------------------------------------- -# sources +xo_cxx_toplevel_options() add_subdirectory(src/pyprocess) -#add_subdirectory(utest) - -# ---------------------------------------------------------------- -# provide find_package() support xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) diff --git a/EXAMPLES b/EXAMPLES new file mode 100644 index 00000000..a8ce9feb --- /dev/null +++ b/EXAMPLES @@ -0,0 +1,57 @@ +process module, using pybind11 to wrap c++ implementation + +To demo + +1. build the kalman project + see path/to/kalman/README + + python-compatible .so will be at: + path/to/kalman/build/process_py/process_py.cpython-39-darwin.so + +2. run python: + $ cd path/to/kalman/build/pyprocess + $ python3 + Python 3.9.12 (main, May 13 2022, 08:13:55) + [Clang 11.1.0 ] on darwin + Type "help", "copyright", "credits" or "license" for more information. + >>> + +3. import pybind11 module and run: + >>> import pyprocess + >>> import datetime as dt + >>> from datetime import datetime as clock + >>> t0=clock.now() + # brownian motion, 50% annual volatility + >>> bm=pyprocess.make_brownian_motion(t0, 0.5) + >>> bm + + >>> bm.exterior_sample(t0, [t0, 2.0]) + 2.0 + >>> bm.exterior_sample(t0, [t0, 1.0]) + 1.0 + >>> bm.exterior_sample(t0 + dt.timedelta(days=30, [t0, 1.0])) + 1.959941114989831 + + >>> ebm=pyprocess.make_exponential_brownian_motion(t0, 0.5) + >>> ebm + + >>> ebm.exterior_sample(t + dt.timedelta(days=180, [t0, 50.0])) + 42.3212369005776 + >>> ebm.exterior_sample(t + dt.timedelta(days=180, [t0, 50.0])) + 56.16317742801309 + + >>> r=pyprocess.make_realization_source(ebm, dt.timedelta(seconds=1)) + +4. attach printer + + >>> import reactor_py + >>> p=reactor_py.make_realization_printer() + >>> r.attach_sink(p) + >>> bm.deliver_one() + >>> bm.deliver_one() + >>> r.deliver_one() + [20220718:224818.909576, 0] + 1 + >>> r.deliver_one() + [20220718:224819.909576, -0.000111338] + 1 From bb26c99660be1b7e2b76b110bb3834dc713b1b44 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 24 Oct 2023 16:36:51 -0400 Subject: [PATCH 08/12] build: tidy using streamlined xo-pywebutil --- cmake/cmake | 4 ---- src/pyprocess/CMakeLists.txt | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 cmake/cmake diff --git a/cmake/cmake b/cmake/cmake deleted file mode 100644 index b49b4828..00000000 --- a/cmake/cmake +++ /dev/null @@ -1,4 +0,0 @@ - /home/roland/proj/xo-pyprocess/cmake: - drwxr-xr-x 2 roland roland 4096 Oct 12 21:49 . - drwxr-xr-x 6 roland roland 4096 Oct 12 21:49 .. - -rw-r--r-- 1 roland roland 125 Oct 12 21:49 xo_pyprocessConfig.cmake.in diff --git a/src/pyprocess/CMakeLists.txt b/src/pyprocess/CMakeLists.txt index 03237164..cf35ab2e 100644 --- a/src/pyprocess/CMakeLists.txt +++ b/src/pyprocess/CMakeLists.txt @@ -6,5 +6,5 @@ set(SELF_SRCS pyprocess.cpp) xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) xo_pybind11_dependency(${SELF_LIB} process) -xo_pybind11_header_dependency(${SELF_LIB} pyreactor) -xo_pybind11_header_dependency(${SELF_LIB} pywebutil) +xo_pybind11_header_dependency(${SELF_LIB} xo_pyreactor) +xo_pybind11_header_dependency(${SELF_LIB} xo_pywebutil) From 2f908b7c3638bd66a926626a4d94c26b2f848752 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 15 Mar 2024 19:40:26 -0400 Subject: [PATCH 09/12] build: bugfix SELF_LIB consistency + streamline CMAKE_MODULE_PATH --- .gitignore | 2 +- CMakeLists.txt | 2 +- README.md | 26 +++++++++++++++++++++++++- cmake/xo-bootstrap-macros.cmake | 12 ++++++++++++ src/pyprocess/CMakeLists.txt | 2 +- src/pyprocess/pyprocess.hpp.in | 6 +++--- 6 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 cmake/xo-bootstrap-macros.cmake diff --git a/.gitignore b/.gitignore index f52f1311..53a9c92f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # lsp keeps state here .cache # typical build directory -build +.build* # lsp: symlink to file in build directory (established manually) compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 36786fb8..d53e2ca6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyprocess VERSION 0.1) -include(xo_macros/xo-project-macros) +include(cmake/xo-bootstrap-macros.cmake) xo_cxx_toplevel_options() diff --git a/README.md b/README.md index 2ad68ffb..07725a19 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ # python bindings for c++ stochastic process library (xo-process) -# build + install +## Getting Started + +### build + install dependencies + +- [github/Rconybea/xo-process](https://github.com/Rconybea/xo-process) +- [github/Rconybea/xo-reactor](https://github.com/Rconybea/xo-reactor) +- [github/Rconybea/xo-pyutil](https://github.com/Rconybea/xo-pyutil) +- [github/Rconybea/xo-pyreflect](https://github.com/Rconybea/xo-pyreflect) +- [github/Rconybea/xo-pyprintjson](https://github.com/Rconybea/xo-pyprintjson) +- [github/Rconybea/xo-pyreactor](https://github.com/Rconybea/xo-pyreactor) + +### build + install ``` $ cd xo-pyprocess $ mkdir build @@ -15,6 +26,19 @@ $ make install ``` (also see .github/workflows/main.yml) +## Examples + +Assumes `xo-pyprocess` installed to `~/local2/lib` +``` +PYTHONPATH=~/local2/lib:$PYTHONPATH python +>>> import xo_pyprocess +>>> dir(xo_pyprocess) +['BrownianMotion', 'ExpProcess', 'RealizationSource', 'RealizationTracer', 'StochasticProcess', 'UpxAdapterSink', 'UpxEvent', 'UpxEventStore', 'UpxToConsole', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'make_brownian_motion', 'make_exponential_brownian_motion', 'make_realization_printer', 'make_realization_source', 'make_tracer'] +>>> +``` + +## Development + # build for unit test coverage ``` $ cd xo-pyprocess diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake new file mode 100644 index 00000000..16644435 --- /dev/null +++ b/cmake/xo-bootstrap-macros.cmake @@ -0,0 +1,12 @@ +if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL "prefix")) + # default to typical install location for xo-project-macros + set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake) +endif() + +message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") +message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + +# needs to have been installed somewhere on CMAKE_MODULE_PATH, +# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) +# +include(xo_macros/xo-project-macros) diff --git a/src/pyprocess/CMakeLists.txt b/src/pyprocess/CMakeLists.txt index cf35ab2e..87a23e90 100644 --- a/src/pyprocess/CMakeLists.txt +++ b/src/pyprocess/CMakeLists.txt @@ -1,6 +1,6 @@ # xo_pyprocess/src/pyprocess/CMakeLists.txt -set(SELF_LIB pyprocess) +set(SELF_LIB xo_pyprocess) set(SELF_SRCS pyprocess.cpp) xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) diff --git a/src/pyprocess/pyprocess.hpp.in b/src/pyprocess/pyprocess.hpp.in index d2f5cec1..938bf0c9 100644 --- a/src/pyprocess/pyprocess.hpp.in +++ b/src/pyprocess/pyprocess.hpp.in @@ -8,18 +8,18 @@ * example: * PYBIND11_MODULE(PYPROCESS_MODULE_NAME(), m) { ... } */ -#define PYPROCESS_MODULE_NAME() @SELF_LIBRARY_NAME@ +#define PYPROCESS_MODULE_NAME() @SELF_LIB@ /* example: * py::module_::import(PYPROCESS_MODULE_NAME_STR) */ -#define PYPROCESS_MODULE_NAME_STR "@SELF_LIBRARY_NAME@" +#define PYPROCESS_MODULE_NAME_STR "@SELF_LIB@" /* example: * PYPROCESS_IMPORT_MODULE() * replaces * py::module_::import("pyprocess") */ -#define PYPROCESS_IMPORT_MODULE() py::module_::import("@SELF_LIBRARY_NAME@") +#define PYPROCESS_IMPORT_MODULE() py::module_::import("@SELF_LIB@") /* end pyprocess.hpp */ From 9e7aebd6dd8c74c7e637f0645e7067149ccdf2da Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 29 Mar 2024 14:33:41 -0400 Subject: [PATCH 10/12] build: suppress bootstrap message in submodule build --- cmake/xo-bootstrap-macros.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake index 16644435..96592216 100644 --- a/cmake/xo-bootstrap-macros.cmake +++ b/cmake/xo-bootstrap-macros.cmake @@ -3,8 +3,10 @@ if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL "pr set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake) endif() -message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") -message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") +if (NOT XO_SUBMODULE_BUILD) + message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") + message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") +endif() # needs to have been installed somewhere on CMAKE_MODULE_PATH, # (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) From 5068fd493f66bc86952c34963d3c96d7c620fd04 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 14 Sep 2024 19:02:52 -0500 Subject: [PATCH 11/12] xo-pyprocess: build: update to latest xo-cmake macros --- CMakeLists.txt | 16 +++++++++++++++- cmake/xo-bootstrap-macros.cmake | 33 +++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d53e2ca6..e2693076 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,24 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyprocess VERSION 0.1) +include(GNUInstallDirs) include(cmake/xo-bootstrap-macros.cmake) -xo_cxx_toplevel_options() +xo_cxx_toplevel_options3() + +# ---------------------------------------------------------------- +# c++ settings (usually temporary) + +set(PROJECT_CXX_FLAGS "") +add_definitions(${PROJECT_CXX_FLAGS}) + +# ---------------------------------------------------------------- add_subdirectory(src/pyprocess) +# ---------------------------------------------------------------- +# provide find_package() support + xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) + +# end CMakeLists.txt diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake index 96592216..aba31169 100644 --- a/cmake/xo-bootstrap-macros.cmake +++ b/cmake/xo-bootstrap-macros.cmake @@ -1,14 +1,35 @@ -if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL "prefix")) - # default to typical install location for xo-project-macros - set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake) +# ---------------------------------------------------------------- +# for example: +# $ PREFIX=/usr/local # for example +# $ cmake -DCMAKE_MODULE_PATH=prefix -DCMAKE_INSTALL_PREFIX=$PREFIX -B .build +# +# will get +# CMAKE_MODULE_PATH +# from xo-cmake-config --cmake-module-path +# +# and expect .cmake macros in +# CMAKE_MODULE_PATH/xo_macros/xo_cxx.cmake +# ---------------------------------------------------------------- + +find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED) + +if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND") + message(FATAL "could not find xo-cmake-config executable") endif() +message(STATUS "XO_CMAKE_CONFIG_EXECUTABLE=${XO_CMAKE_CONFIG_EXECUTABLE}") + if (NOT XO_SUBMODULE_BUILD) - message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") - message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix)) + # default to typical install location for xo-project-macros + execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH) + message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + endif() endif() # needs to have been installed somewhere on CMAKE_MODULE_PATH, # (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) # -include(xo_macros/xo-project-macros) +include(xo_macros/xo_cxx) + +xo_cxx_bootstrap_message() From c4af12c62582473c8321f5946194b31afdcf96f5 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 14 Sep 2024 19:03:07 -0500 Subject: [PATCH 12/12] xo-pyprocess: bugfix: track xo::ref::rp -> xo::rp --- src/pyprocess/pyprocess.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pyprocess/pyprocess.cpp b/src/pyprocess/pyprocess.cpp index 56b5b1f8..e5b51dcc 100644 --- a/src/pyprocess/pyprocess.cpp +++ b/src/pyprocess/pyprocess.cpp @@ -33,7 +33,6 @@ namespace xo { using xo::time::utc_nanos; using xo::rng::Seed; using xo::rng::xoshiro256ss; - using xo::ref::rp; namespace py = pybind11; namespace process { @@ -75,7 +74,7 @@ namespace xo { py::arg("start_tm"), py::arg("start_value"), py::arg("annual_volatility")); py::class_, - xo::ref::rp>>(m, "StochasticProcess") + xo::rp>>(m, "StochasticProcess") .def_property_readonly("t0", &StochasticProcess::t0) .def_property_readonly("t0_value", &StochasticProcess::t0_value) .def("exterior_sample", &StochasticProcess::exterior_sample) @@ -83,12 +82,12 @@ namespace xo { py::class_, StochasticProcess, - xo::ref::rp>>(m, "BrownianMotion"); + xo::rp>>(m, "BrownianMotion"); //.def("exterior_sample", &BrownianMotion::exterior_sample) //.def("__repr__", &BrownianMotion::display_string); py::class_, - xo::ref::rp>(m, "ExpProcess") + xo::rp>(m, "ExpProcess") .def_property_readonly("exponent_process", [](ExpProcess & self) { return self.exponent_process().promote(); @@ -98,7 +97,7 @@ namespace xo { &RealizationTracer::make); py::class_, - xo::ref::rp>>(m, "RealizationTracer"); + xo::rp>>(m, "RealizationTracer"); /* e.g. * import datetime as dt @@ -107,7 +106,7 @@ namespace xo { * s=pyprocess.make_realization_source(ebm, dt.timedelta(seconds=1)) */ m.def("make_realization_source", - [](xo::ref::rp> p, + [](xo::rp> p, xo::time::nanos sample_dt) { auto tracer = RealizationTracer::make(p); @@ -126,7 +125,7 @@ namespace xo { py::class_, reactor::ReactorSource, - xo::ref::rp>>(m, "RealizationSource") + xo::rp>>(m, "RealizationSource") .def_property_readonly("current_ev", &RealizationSource::current_ev); py::class_