Skip to content

Commit 5da38a1

Browse files
authored
feat: expose number of expansions in python (#29)
1 parent 9b0f328 commit 5da38a1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

python/htps.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,10 @@ static PyObject *PyHTPS_is_done(PyHTPS *self, PyObject *Py_UNUSED(ignored)) {
31693169
return res;
31703170
}
31713171

3172+
static PyObject *PyHTPS_expansions(PyHTPS *self, void *closure) {
3173+
return PyLong_FromSize_t(self->graph.num_expansions());
3174+
}
3175+
31723176
static void PyHTPS_dealloc(PyHTPS *self) {
31733177
self->graph.~HTPS();
31743178
Py_TYPE(self)->tp_free((PyObject *) self);
@@ -3217,6 +3221,11 @@ static PyObject *PyHTPS_from_jsonstr(PyTypeObject *type, PyObject *args) {
32173221
}
32183222
}
32193223

3224+
static PyGetSetDef HTPS_getsetters[] = {
3225+
{"expansions", (getter) PyHTPS_expansions, NULL, "Number of expansions", NULL},
3226+
{NULL}
3227+
};
3228+
32203229
static PyMethodDef HTPS_methods[] = {
32213230
{"theorems_to_expand", (PyCFunction) PyHTPS_theorems_to_expand, METH_NOARGS, "Returns a list of subsequent theorems to expand"},
32223231
{"expand_and_backup", (PyCFunction) PyHTPS_expand_and_backup, METH_VARARGS, "Expands and backups using the provided list of EnvExpansion objects"},
@@ -3258,7 +3267,7 @@ static PyTypeObject HTPSType = {
32583267
NULL,
32593268
HTPS_methods,
32603269
NULL,
3261-
NULL,
3270+
HTPS_getsetters,
32623271
NULL,
32633272
NULL,
32643273
NULL,

src/graph/htps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,10 @@ void HTPS::set_params(const htps_params &new_params) {
14251425
policy = std::make_shared<Policy>(params.policy_type, params.exploration);
14261426
}
14271427

1428+
size_t HTPS::num_expansions() const {
1429+
return expansion_count;
1430+
}
1431+
14281432
HTPS HTPS::from_json(const nlohmann::json &j) {
14291433
HTPS htps;
14301434
htps.root = j["root"];

src/graph/htps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ namespace htps {
623623
explicit operator nlohmann::json() const;
624624

625625
htps::htps_params get_params() const;
626+
627+
size_t num_expansions() const;
626628
};
627629

628630
}

0 commit comments

Comments
 (0)