Skip to content

Commit

Permalink
Add DC verifier python bindings and basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
xJoskiy committed Oct 30, 2024
1 parent 4a12f46 commit 2ccd19a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
20 changes: 20 additions & 0 deletions examples/basic/verifying_dc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import desbordante as db

# # Given denial constraint tells us that if two persons
# live in the same state, the one earning a lower
# salary has a lower tax rate
DC = "!(s.State == t.State and s.Salary < t.Salary and s.FedTaxRate > t.FedTaxRate)"

TABLE = "test_input_data/TestDC1.csv"

# Creating a verificator and loading data in algortihm
verificator = db.dc_verification.algorithms.Default()
verificator.load_data(table=(TABLE, ',', True))

# Algorithm execution
verificator.execute(denial_constraint=DC)

# Obtaining the result
result: bool = verificator.dc_holds()

print("DC " + DC + " holds: " + str(result))
6 changes: 5 additions & 1 deletion src/python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "bind_main_classes.h"
#include "cfd/bind_cfd.h"
#include "data/bind_data_types.h"
#include "dc/bind_dc_verification.h"
#include "dd/bind_split.h"
#include "dynamic/bind_dynamic_fd_verification.h"
#include "fd/bind_fd.h"
Expand Down Expand Up @@ -38,12 +39,15 @@ PYBIND11_MODULE(desbordante, module, pybind11::mod_gil_not_used()) {
el::Loggers::reconfigureAllLoggers(conf);
}

// clang-format off
for (auto bind_func :
{BindMainClasses, BindDataTypes, BindFd, BindCfd, BindAr, BindUcc, BindAc, BindOd, BindNd,
BindFdVerification, BindMfdVerification, BindUccVerification, BindStatistics, BindInd,
BindGfdVerification, BindSplit, BindDynamicFdVerification, BindNdVerification, BindSFD}) {
BindGfdVerification, BindSplit, BindDynamicFdVerification, BindNdVerification, BindSFD,
BindDCVerification}) {
bind_func(module);
}
// clang-format on
}

} // namespace python_bindings
17 changes: 17 additions & 0 deletions src/python_bindings/dc/bind_dc_verification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "bind_dc_verification.h"

#include "algorithms/dc/verifier/dc_verifier.h"
#include "py_util/bind_primitive.h"

namespace python_bindings {

namespace py = pybind11;

void BindDCVerification(py::module_& main_module) {
auto dc_verification_module = main_module.def_submodule("dc_verification");

BindPrimitiveNoBase<algos::DCVerifier>(dc_verification_module, "DCVerification")
.def("dc_holds", &algos::DCVerifier::DCHolds);
}

} // namespace python_bindings
7 changes: 7 additions & 0 deletions src/python_bindings/dc/bind_dc_verification.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <pybind11/pybind11.h>

namespace python_bindings {
void BindDCVerification(pybind11::module_& main_module);
} // namespace python_bindings
2 changes: 1 addition & 1 deletion src/python_bindings/py_util/get_py_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ py::tuple GetPyType(std::type_index type_index) {
PyTypePair<std::filesystem::path, kPyStr>,
PyTypePair<std::vector<std::filesystem::path>, kPyList, kPyStr>,
PyTypePair<std::unordered_set<size_t>, kPySet, kPyInt>,
};
PyTypePair<std::string, kPyStr>};
return type_map.at(type_index)();
}

Expand Down
2 changes: 1 addition & 1 deletion src/python_bindings/py_util/py_to_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ std::unordered_map<std::type_index, ConvFunc> const kConverters{
kNormalConvPair<std::filesystem::path>,
kNormalConvPair<std::vector<std::filesystem::path>>,
kNormalConvPair<std::unordered_set<size_t>>,
};
kNormalConvPair<std::string>};

} // namespace

Expand Down
2 changes: 2 additions & 0 deletions src/tests/all_csv_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@ CSVConfig const kLineItem = CreateCsvConfig("LineItem.csv", '|', true);
CSVConfig const kTmpDC = CreateCsvConfig("tmp_dc.csv", ',', true);
CSVConfig const kTestDC = CreateCsvConfig("TestDC.csv", ',', true);
CSVConfig const kTestDC1 = CreateCsvConfig("TestDC1.csv", ',', true);
CSVConfig const kTestDC2 = CreateCsvConfig("TestDC2.csv", ',', true);
CSVConfig const kTestDC3 = CreateCsvConfig("TestDC3.csv", ',', true);
} // namespace tests
2 changes: 2 additions & 0 deletions src/tests/all_csv_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ extern CSVConfig const kLineItem;
extern CSVConfig const kTmpDC;
extern CSVConfig const kTestDC;
extern CSVConfig const kTestDC1;
extern CSVConfig const kTestDC2;
extern CSVConfig const kTestDC3;
} // namespace tests

0 comments on commit 2ccd19a

Please sign in to comment.