arbor-sim/arbor

Units! At least on the Python API surface

Closed this issue · 5 comments

Goal

⚠️ This is a request for comments. ⚠️

Add an additional layer of safety and convenience in the Python API. Might be considered
a trial for going deeper, to C++ API and -- eventually -- the C++ Core.

Rationale

Different simulators, groups, papers, ... use different units. Make interacting with
more people safer and easier

import arbor as A
import arbor.units as U

# Rest of code omitted
decor = (
    arbor.decor()
    .set_property(Vm=-40*U.mV) # OK, expected unit is passed
    .paint('"soma"', arbor.density("hh"))
    .place('"midpoint"', arbor.iclamp(10, # no unit: explodes
                                       2*U.mV, # wrong unit: explodes
                                     0.8*U.mA), # OK
                                     "iclamp")
    .place('"midpoint"', arbor.threshold_detector(-0.01*U.V), "detector") # OK, converted to mV
)

Why not?

More typing, more fuss.

Scope

The Python API's user facing parts, especially Recipe, Decor, Catalogue, ...

Implementation

  • Use Pint (https://pint.readthedocs.io/en/stable/), seems to be a standard.
  • Add relevant and convenient unit definitions
  • Export the definitions ('registry' in pint lingo) from Arbor.
  • (Incrementally) Add units to all user facing APIs
MRIO commented

The extra fuss and writing units down is generously compensated by rigor, trustworthiness and readability of biophysical accurate models. It should be standard practice even for more abstract models, IMO. It increases clarity and helps newcomers to be rigorous. Matters of scales of measurement in empirical data often introduce errors in modeling, which can be mitigated via enforcement of unit consistency.

I fully agree with @MRIO. Units in the Python API would be very nice and leave an open path to lower levels.

Looks pretty ROOTy :)

As maybe obvious by the rather weak argument against, I am all for this. I'll let this stew for a week or so before
making this policy, this way more people can leave their thoughts.

On the implementation side:

  • Anyone with experiences/preferences regarding the library to use?
  • Pint seems to be interesting, although I'd prefer something at the type (hint) level.
  • Alas, I found no implementation of such a Python Units Lib.
MRIO commented