Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added C++ REST API #497

Merged
merged 115 commits into from
Oct 20, 2021
Merged
Changes from 64 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
c20de3d
Allowed to ground some nodes of the cag with external functions.
May 10, 2021
8f1b4ee
Added code to distinguish between dependent and independent nodes of the
May 25, 2021
1b594bf
Modeling root nodes separately.
May 28, 2021
6d72733
A script to analyze and visualize rain data
Jun 7, 2021
96f6870
Experimenting with using partition median and relative change between
Jun 14, 2021
29fa9c0
Tidying up the head node modeling code
Jun 15, 2021
5649dde
More tidying up head node modeling code.
Jun 16, 2021
6cf939d
more tyding up head node modeling code
Jun 16, 2021
05bf812
more tyding up head node modeling code
Jun 16, 2021
352d732
fixed a logical bug
Jun 16, 2021
e3a1986
Added another graph
Jun 22, 2021
e549984
The head node model that was demoed for 2021 June embed.
Jun 22, 2021
10cf87d
Updated the head node modeling code with a guard to prevent a segment…
Jun 22, 2021
3da99de
Updated the code so that:
Jun 23, 2021
dc9cbb6
Integrated head node modeling component with Causemose
Jul 30, 2021
843b7e4
Pached an old (could be obsolete) method to fix a segmentation fault …
Jul 30, 2021
39bd25f
Accumulating log likelihoods
Jul 31, 2021
15858e9
MAP Sample
Aug 2, 2021
553ec61
Fixed a place that gave a segmentation fault due to faulty logic
Aug 3, 2021
e7dcdaa
Fixed an initialization bug
Aug 3, 2021
2c84eb5
Fixed a bug
Aug 10, 2021
5c0ab70
Generating synthetic CAGs
Aug 19, 2021
b1a0e2e
Cleanup
Aug 23, 2021
c70f374
More cleaning
Aug 23, 2021
8cecf28
Created a class to perform timing
Aug 25, 2021
6a7ab55
Fixed CMakeLists.txt
Aug 25, 2021
65b0910
Changed a file name
Aug 25, 2021
dcd0f92
A basic macro profiler completed.
Aug 30, 2021
f5724d6
Added some progress messages to the timer.
Aug 30, 2021
2290f0b
Added proper error checking for opening delphi.db
Sep 1, 2021
4beb2fd
Improved the newly created delphi.db open method to accept the database
Sep 1, 2021
54b2bf7
Improved the Delphi macro timing program to accept command line options.
Sep 9, 2021
b5919a7
Removed inclusion of dbg.h in main source files.
Sep 9, 2021
9a0fa36
Fixed the help option in timer.
Sep 9, 2021
43c7700
The june embed jupytre notebook got opened and some version number go…
Sep 24, 2021
51f44b2
Seasonal curve from a Fourier series
Sep 24, 2021
efb1c08
Commented out some unused synthetic data generating methods.
Oct 7, 2021
f6fea8b
Deleted commented code related to synthetic data generation.
Oct 7, 2021
d05a596
Added a stub to export a create model json file.
Oct 9, 2021
b68f8fd
Updated the debugger.py script to test synthetic CAG generation.
Oct 10, 2021
caf8b38
Updated the seasonal_fourier.py script
Oct 10, 2021
a8b003d
Changing terminology
Oct 10, 2021
a01e097
Some refactoring
Oct 10, 2021
e2239b2
Added two scripts to perform some regression testing:
Oct 13, 2021
b783508
Added mean and standard deviation of the snapshot differences to the
Oct 13, 2021
170c5df
Added source files from branch 'delphi_modeling_1_dev'
jastier Oct 15, 2021
8ebc0b4
Added test scripts
jastier Oct 15, 2021
ce71507
Added delphi_rest_api CI tests
jastier Oct 15, 2021
e7df4c2
Moved file
jastier Oct 15, 2021
e51c8fc
added wm_test and Bash get_system_status test
jastier Oct 15, 2021
c1ba856
Commended out 'test_wm' test to debug CI failure
jastier Oct 15, 2021
a6832c6
Commented out pip installs for CI debugging
jastier Oct 15, 2021
596e905
commented out delphi_rest_api tests to debug test_wm CI issue
jastier Oct 15, 2021
156e35d
moved test_wm after the served installation
jastier Oct 15, 2021
512ab6d
added 'sudo' to failing commands
jastier Oct 15, 2021
6732c54
CI debugging
jastier Oct 15, 2021
fe4bead
Move 'test_wm' ahead of a directory change
jastier Oct 15, 2021
864d671
Added pwd output
jastier Oct 15, 2021
c480061
debug output
jastier Oct 15, 2021
78e0481
better comment visibility
jastier Oct 15, 2021
e475dc3
added output for test_wm build diretory
jastier Oct 15, 2021
aa31008
current directory output
jastier Oct 15, 2021
3eb5ea6
directory change
jastier Oct 15, 2021
5e1b926
Building WM only
jastier Oct 16, 2021
d44d441
Adding served to WM build
jastier Oct 16, 2021
c75995c
sudo commands
jastier Oct 16, 2021
ee1f33f
sudo mkdir build
jastier Oct 16, 2021
2ae3b6c
Uncommented missing file
jastier Oct 16, 2021
ce44362
Added file, commented out DelphiPython from CMakeLists.txt
jastier Oct 18, 2021
9dbbd7e
Turned on Python build
jastier Oct 18, 2021
aaadf2a
Trying another CMakeLists.txt
jastier Oct 18, 2021
786f34d
Added missing file
jastier Oct 18, 2021
00a5ae8
Building pybind11 from source
jastier Oct 18, 2021
e9b9c90
pybind11 install in ci.yml
jastier Oct 18, 2021
c9c99ae
Removed pybind11 install from CMakeLists.txt
jastier Oct 18, 2021
5c74047
cd into scripts dir
jastier Oct 18, 2021
f04ac1f
install pytest
jastier Oct 18, 2021
c7e8f56
pybind11
jastier Oct 18, 2021
4ad4380
Better directory navigation
jastier Oct 18, 2021
9b252fc
Directory navigation
jastier Oct 18, 2021
30d17a4
Directory navigation
jastier Oct 18, 2021
21aaadd
Directory navigation
jastier Oct 18, 2021
00726e3
commented out test_wm
jastier Oct 18, 2021
fa1de49
Added REST API build to CI
jastier Oct 18, 2021
feecff6
Commented out 'test_cpp_rest_api.py' test
jastier Oct 18, 2021
a8790f5
Directory navigation
jastier Oct 18, 2021
6550613
Uncommented test_wm
jastier Oct 18, 2021
c856cbe
DELPHI_DB check
jastier Oct 19, 2021
b635d24
Fully matrix exponential compatible periodic LDS.
Oct 19, 2021
cde89b8
Modifying ci.yml
adarshp Oct 19, 2021
e6a4408
Added script to test delphi_rest_api progress endpoint
jastier Oct 19, 2021
ae2b871
Removing apps/test_cpp_rest_api.py
adarshp Oct 19, 2021
2917470
Added stub code for the REST API progress function
jastier Oct 19, 2021
667c321
Fixing compilation error related to range-v3 on macOS Big Sur
adarshp Jun 3, 2021
5b9122a
Cleaned up CMakeLists.txt a bit with best practices
adarshp Oct 19, 2021
70a4ef8
Removing delphi/setup.py
adarshp Oct 19, 2021
e8c2531
Added stub code for the REST API stop_computation function
jastier Oct 19, 2021
81820b6
adding #pragma once to DatabaseHelper.cpp, autoformatting
adarshp Oct 19, 2021
8419965
Removing scripts/timer.cpp
adarshp Oct 19, 2021
40ed93d
Moving served installation to earlier in the CI workflow
adarshp Oct 19, 2021
b2053fc
Fixing typo in ci.yml
adarshp Oct 19, 2021
eda8ea7
Deleted a lot of commented code and print statements.
Oct 19, 2021
0816a15
Did some more cleaning.
Oct 19, 2021
bc098f3
trying removing sudo
adarshp Oct 19, 2021
eac9426
pulling origin/delphi_modeling_1_dev
adarshp Oct 19, 2021
851c1d6
Added a utility function for database access
jastier Oct 19, 2021
6a743dd
Fixed printf debugging
jastier Oct 19, 2021
9bdce89
started database query
jastier Oct 19, 2021
f2a1966
removing pybind_tester_driver
adarshp Oct 19, 2021
5130174
trying removing sudo
adarshp Oct 20, 2021
5484631
removing unnecessary call to mkdir
adarshp Oct 20, 2021
db3861d
fixing compilation errors
adarshp Oct 20, 2021
38be6d3
Merge branch 'dev_joseph_2_ap' of github.com:ml4ai/delphi into dev_jo…
adarshp Oct 20, 2021
1a317e3
Replaced deprecated add_stylesheet call in conf.py
jastier Oct 20, 2021
9685f1e
Merge branch 'dev_joseph_2' of github.com:ml4ai/delphi into dev_joseph_2
jastier Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 41 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -44,50 +44,53 @@ jobs:
librange-v3-dev\
nlohmann-json3-dev


pwd
echo "### Installing pytest"
sudo /usr/bin/python -m pip install pytest

pwd
echo "### Building Served from source"
sudo git clone https://github.com/meltwater/served
cd served
sudo mkdir build
cd build
sudo cmake ..
sudo make -j `nproc` install
cd ../..
curl -LO https://github.com/meltwater/served/archive/refs/tags/v1.6.0.tar.gz
tar -xzf v1.6.0.tar.gz
pushd served-1.6.0
mkdir build
cd build
cmake ..
sudo make -j `nproc` install
popd

pwd
echo "### Building the Delphi REST API"
# build the delpi REST API
sudo mkdir build
cd build
sudo cmake ..
sudo make -j `nproc`
# Download delphi.db
mkdir -p data && curl http://vanga.sista.arizona.edu/delphi_data/delphi.db -o $DELPHI_DB
echo "DELPHI_DB = $DELPHI_DB"

pwd
echo "### Running the Delphi REST API"
# run the api as a background process
./delphi_rest_api &
# Create a virtual environment
python3 -m venv delphi_venv

# Activate the virtual environment
source delphi_venv/bin/activate

# test the delphi REST API using python
cd ../apps
# python3 ./test_cpp_rest_api.py
# Install wheel
pip install wheel

# test the delphi with Bash scripts
cd ../tests/wm/scripts
./get_system_status
cd ../../../
# Install delphi in editable mode
pip install -e .[test]

# Run the Python WM test suite
make test_wm

pwd
echo "### Building WM"
echo "DELPHI_DB = $DELPHI_DB"
sudo python3 -m venv delphi_venv
source delphi_venv/bin/activate
sudo mkdir -p data && curl http://vanga.sista.arizona.edu/delphi_data/delphi.db -o $DELPHI_DB
sudo pip install wheel
sudo pip install -e .[test]
# sudo make test_wm
echo "### Building and running Python tests"


pwd
echo "### Building the Delphi REST API"
# Build the Delphi REST API server program
pushd build
cmake ..
make -j `nproc` delphi_rest_api

echo "### Running the Delphi REST API"
# Run the api as a background process
./delphi_rest_api &
popd

# Test the Delphi with Bash scripts
pushd tests/wm/scripts
./get_system_status
popd
98 changes: 41 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.11)
project(delphi)

# Uncomment this line to generate debug code
set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Debug)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -14,12 +14,8 @@ set(CMAKE_CXX_FLAGS

find_package(Graphviz)

include_directories(${GRAPHVIZ_INCLUDE_DIRS})
# Add and link pybind11 modules
find_package(Boost COMPONENTS graph program_options REQUIRED)
include_directories(lib)
include_directories(external)
include_directories(${Boost_INCLUDE_DIR})

find_package(range-v3 REQUIRED)
find_package(Eigen3 REQUIRED NO_MODULE)
@@ -30,64 +26,44 @@ option(BUILD_PYTHON_BINDINGS "Build Python bindings" ON)

# Optional building of Python bindings using Pybind11
if(BUILD_PYTHON_BINDINGS)

find_package(pybind11 CONFIG REQUIRED)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
find_package(Python3 REQUIRED)
set(PYBIND11_PYTHON_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
set(PYBIND11_CPP_STANDARD -std=c++17)
endif()

file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/lib/*.cpp)
find_package(SQLite3 REQUIRED)

add_library(Delphi
lib/AnalysisGraph.hpp
lib/causemos_integration.cpp
lib/constructors.cpp
lib/CSVWriter.hpp
lib/database.cpp
lib/DatabaseHelper.cpp
lib/DatabaseHelper.hpp
lib/data.cpp
lib/data.hpp
#lib/DelphiPython.cpp
lib/DiGraph.hpp
lib/Edge.hpp
lib/exceptions.hpp
lib/format_output.cpp
lib/graph_building.cpp
lib/graph_modification.cpp
lib/graph_utils.cpp
lib/graphviz.cpp
lib/graphviz_interface.cpp
lib/graphviz_interface.hpp
lib/head_nodes.cpp
lib/Indicator.cpp
lib/Indicator.hpp
lib/indicator_manipulation.cpp
lib/KDE.cpp
lib/KDE.hpp
lib/Node.hpp
lib/parameter_initialization.cpp
lib/prediction.cpp
lib/printing.cpp
lib/PybindTester.hpp
lib/Random_Variables.cpp
lib/Random_Variables.hpp
lib/rng.cpp
lib/rng.hpp
lib/sampling.cpp
lib/sandbox.cpp
lib/subgraphs.cpp
lib/synthetic_data.cpp
lib/Timer.hpp
lib/to_json.cpp
lib/train_model.cpp
lib/Tran_Mat_Cell.cpp
lib/Tran_Mat_Cell.hpp
lib/utils.cpp
lib/utils.hpp
lib/parameter_initialization.cpp
lib/to_json.cpp
lib/data.cpp
lib/graphviz_interface.cpp
lib/graphviz.cpp
lib/KDE.cpp
lib/Random_Variables.cpp
lib/rng.cpp
lib/train_model.cpp
lib/Tran_Mat_Cell.cpp
lib/utils.cpp
lib/Indicator.cpp
lib/subgraphs.cpp
lib/constructors.cpp
lib/causemos_integration.cpp
lib/sampling.cpp
lib/prediction.cpp
lib/synthetic_data.cpp
lib/graph_building.cpp
lib/graph_modification.cpp
lib/graph_utils.cpp
lib/printing.cpp
lib/indicator_manipulation.cpp
lib/sandbox.cpp
lib/format_output.cpp
lib/database.cpp
lib/DatabaseHelper.cpp
lib/head_nodes.cpp
)

target_link_libraries(Delphi
@@ -98,11 +74,13 @@ target_link_libraries(Delphi
Eigen3::Eigen
${GRAPHVIZ_LIBS})
target_link_libraries(Delphi INTERFACE range-v3)
target_include_directories(Delphi PRIVATE ${GRAPHVIZ_INCLUDE_DIRS} lib external)

if(BUILD_PYTHON_BINDINGS)

pybind11_add_module(DelphiPython MODULE NO_EXTRAS lib/DelphiPython.cpp)
target_link_libraries(DelphiPython PRIVATE Delphi Eigen3::Eigen)
target_include_directories(DelphiPython PRIVATE ${GRAPHVIZ_INCLUDE_DIRS})
add_custom_command(TARGET DelphiPython POST_BUILD
COMMAND echo ""
COMMAND echo "Copying..."
@@ -112,7 +90,6 @@ if(BUILD_PYTHON_BINDINGS)
COMMAND rm -rf ${PROJECT_SOURCE_DIR}/delphi/cpp/DelphiPython*
COMMAND cp DelphiPython* ${PROJECT_SOURCE_DIR}/delphi/cpp/
)
#add_executable(pybind_tester_driver apps/pybind_tester_driver.cpp)

endif()

@@ -123,15 +100,22 @@ pkg_check_modules(SERVED REQUIRED IMPORTED_TARGET served)
# Executables
add_executable(create_model apps/create_model.cpp)
target_link_libraries(create_model PRIVATE Delphi Eigen3::Eigen)
target_include_directories(create_model PRIVATE ${Boost_INCLUDE_DIR} lib external ${GRAPHVIZ_INCLUDE_DIRS})

## Sandbox tester
add_executable(sandbox_tester apps/sandbox_tester.cpp)
target_link_libraries(sandbox_tester PRIVATE Delphi Eigen3::Eigen)
target_include_directories(sandbox_tester PRIVATE lib ${GRAPHVIZ_INCLUDE_DIRS})

## Timer program
add_executable(timer
scripts/timer.cpp
apps/timer.cpp
lib/Timer.hpp
lib/CSVWriter.hpp)
target_link_libraries(timer PRIVATE Delphi Eigen3::Eigen ${Boost_LIBRARIES})
target_include_directories(timer PRIVATE ${Boost_INCLUDE_DIR} lib external ${GRAPHVIZ_INCLUDE_DIRS})

# Build the REST API program
add_executable(delphi_rest_api apps/delphi_rest_api.cpp)
target_link_libraries(delphi_rest_api PRIVATE Delphi PkgConfig::SERVED)
target_link_libraries(delphi_rest_api PRIVATE Eigen3::Eigen pthread)
target_link_libraries(delphi_rest_api PRIVATE Delphi PkgConfig::SERVED Eigen3::Eigen pthread)
target_include_directories(delphi_rest_api PRIVATE ${Boost_INCLUDE_DIR} lib external ${GRAPHVIZ_INCLUDE_DIRS})
11 changes: 0 additions & 11 deletions apps/pybind_tester_driver.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions apps/test_cpp_rest_api.py

This file was deleted.

134 changes: 0 additions & 134 deletions delphi/setup.py

This file was deleted.

57 changes: 31 additions & 26 deletions lib/DatabaseHelper.hpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
#ifndef DATABASEHELPER_H
#define DATABASEHELPER_H

#pragma once

#include <nlohmann/json.hpp>
#include <range/v3/all.hpp>
#include <sqlite3.h>
#include <vector>
#include <range/v3/all.hpp>
#include <nlohmann/json.hpp>


class Database {
private:

sqlite3 *db;

sqlite3* db;

public:
Database();

Database();
~Database();

~Database();

void create_table();
void create_table();

std::vector<std::string> read_column_text(std::string query);
std::vector<std::string> read_column_text(std::string query);

std::vector<std::string> read_column_text_query(std::string table_name, std::string column_name);
std::vector<std::string> read_column_text_query(std::string table_name,
std::string column_name);

std::vector<std::string> read_column_text_query_where(std::string table_name, std::string column_name, std::string where_column_name, std::string where_value);
std::vector<std::string>
read_column_text_query_where(std::string table_name,
std::string column_name,
std::string where_column_name,
std::string where_value);

nlohmann::json select_delphimodel_row(std::string modelId);
nlohmann::json select_delphimodel_row(std::string modelId);

nlohmann::json select_causemosasyncexperimentresult_row(std::string modelId);
nlohmann::json select_causemosasyncexperimentresult_row(std::string modelId);

void insert(std::string insert_query);
void insert(std::string insert_query);

void insert_into_delphimodel(std::string id, std::string model);
void insert_into_delphimodel(std::string id, std::string model);

void insert_into_causemosasyncexperimentresult(std::string id, std::string status, std::string experimentType, std::string results);
void insert_into_causemosasyncexperimentresult(std::string id,
std::string status,
std::string experimentType,
std::string results);

void update_row(std::string table_name, std::string column_name, std::string value, std::string where_column_name, std::string where_value);

void delete_rows(std::string table_name, std::string where_column_name, std::string where_value);
void update_row(std::string table_name,
std::string column_name,
std::string value,
std::string where_column_name,
std::string where_value);

void delete_rows(std::string table_name,
std::string where_column_name,
std::string where_value);
};

#endif /* DATABASEHELPER_H */
9 changes: 6 additions & 3 deletions lib/subgraphs.cpp
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
#include "Node.hpp"
#include "utils.hpp"
#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <range/v3/all.hpp>

using boost::for_each;
@@ -82,7 +84,8 @@ AnalysisGraph AnalysisGraph::get_subgraph_for_concept(string concept,
bool inward,
int depth) {

using ranges::views::filter, ranges::views::transform, ranges::to;
using ranges::to;
using namespace boost::adaptors;

// Mark all the vertices as not visited
for_each(this->nodes(), [](Node& node) { node.visited = false; });
@@ -96,8 +99,8 @@ AnalysisGraph AnalysisGraph::get_subgraph_for_concept(string concept,

unordered_set<string> nodes_to_remove =
this->node_indices() |
filter([&](int v) { return !in(vertices_to_keep, v); }) |
transform([&](int v) { return (*this)[v].name; }) | to<unordered_set>();
filtered([&](int v) { return !in(vertices_to_keep, v); }) |
transformed([&](int v) { return (*this)[v].name; }) | to<unordered_set>();

if (vertices_to_keep.size() == 0) {
print("Subgraph has 0 nodes - returning an empty CAG!");
109 changes: 0 additions & 109 deletions scripts/timer.cpp

This file was deleted.