From 6f244035d14c403631c41ab27fc685ed7d8d52e3 Mon Sep 17 00:00:00 2001
From: Nora Abi Akar <nora.abiakar@gmail.com>
Date: Tue, 18 Jan 2022 14:09:57 +0100
Subject: [PATCH] Allow the use of string s-expression CV-policies in pyarb 
 (#1799)

---
 doc/concepts/morphology.rst | 2 ++
 doc/python/decor.rst        | 6 ++++++
 python/cells.cpp            | 8 +++++++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/doc/concepts/morphology.rst b/doc/concepts/morphology.rst
index 13ffcd4b..3c2fb57c 100644
--- a/doc/concepts/morphology.rst
+++ b/doc/concepts/morphology.rst
@@ -693,6 +693,8 @@ and *B*, while *A* | *B* is a policy which gives all the boundary points from
 The domain of *A* + *B* and *A* | *B* is the union of the domains of *A* and
 *B*.
 
+.. _morph-cv-sexpr:
+
 Reading CV policies from strings
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/python/decor.rst b/doc/python/decor.rst
index 33338141..6eb79d24 100644
--- a/doc/python/decor.rst
+++ b/doc/python/decor.rst
@@ -167,3 +167,9 @@ Cable cell decoration
 
         :param policy: The cv_policy.
         :type policy: :py:class:`cv_policy`
+
+    .. method:: discretization(policy)
+
+        Set the cv_policy used to discretise the cell into control volumes for simulation.
+
+        :param str policy: :ref:`string representation <morph-cv-sexpr>` of a cv_policy.
\ No newline at end of file
diff --git a/python/cells.cpp b/python/cells.cpp
index da9060d0..90932f38 100644
--- a/python/cells.cpp
+++ b/python/cells.cpp
@@ -691,7 +691,13 @@ void register_cells(pybind11::module& m) {
             "The group of spike detectors has the label 'label', used for forming connections between cells.")
         .def("discretization",
             [](arb::decor& dec, const arb::cv_policy& p) { dec.set_default(p); },
-            pybind11::arg_v("policy", "A cv_policy used to discretise the cell into compartments for simulation"));
+            pybind11::arg_v("policy", "A cv_policy used to discretise the cell into compartments for simulation"))
+        .def("discretization",
+            [](arb::decor& dec, const std::string& p) {
+                dec.set_default(arborio::parse_cv_policy_expression(p).unwrap());
+            },
+            pybind11::arg_v("policy", "An s-expression string representing a cv_policy used to discretise the "
+                                      "cell into compartments for simulation"));
 
     // arb::cable_cell
 
-- 
GitLab