From 47a16227460ddc655d28b303f5f23e4981d164db Mon Sep 17 00:00:00 2001 From: Marcel Nageler Date: Wed, 20 Dec 2023 15:17:55 +0100 Subject: [PATCH] improve error reporting for Python bindings --- python/src/pyapproxmc.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/src/pyapproxmc.cpp b/python/src/pyapproxmc.cpp index b3bacd6..651cedb 100644 --- a/python/src/pyapproxmc.cpp +++ b/python/src/pyapproxmc.cpp @@ -160,7 +160,7 @@ static int parse_clause(Counter *self, PyObject *clause, std::vector 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; } @@ -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; @@ -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; }