Skip to content

Commit

Permalink
Merge pull request #45 from fanosta/improve-python-exceptions
Browse files Browse the repository at this point in the history
improve error reporting for Python bindings
  • Loading branch information
msoos committed Dec 21, 2023
2 parents a40eb45 + 47a1622 commit a1eecee
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions python/src/pyapproxmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int parse_clause(Counter *self, PyObject *clause, std::vector<CMSat::Lit>
if (allow_more_vars)
self->arjun->new_vars(max_var-(long int)self->arjun->nVars()+1);
else {
PyErr_SetString(PyExc_SystemError,
PyErr_SetString(PyExc_ValueError,
"ERROR: Sampling vars contain variables that are not in the original clauses!");
return 0;
}
Expand Down Expand Up @@ -413,8 +413,7 @@ Approximately count the number of solutions to the formula. It can only be calle
static PyObject* count(Counter *self, PyObject *args, PyObject *kwds)
{
if (self->count_called) {
PyErr_SetString(PyExc_SystemError,
"ERROR: Sampling vars contain variables that are not in the original clauses!");
PyErr_SetString(PyExc_ValueError, "ERROR: Counter.count() may only be called once!");
return NULL;
} else {
self->count_called = true;
Expand All @@ -436,7 +435,7 @@ static PyObject* count(Counter *self, PyObject *args, PyObject *kwds)
}
for(const auto& l: sampling_lits) {
if (l.var() > self->arjun->nVars()) {
PyErr_SetString(PyExc_SystemError,
PyErr_SetString(PyExc_ValueError,
"ERROR: Sampling vars contain variables that are not in the original clauses!");
return NULL;
}
Expand Down

0 comments on commit a1eecee

Please sign in to comment.