Extracted from PR there: https://github.com/EconForge/dolo/pull/128
Extracted from PR there: EconForge/dolo.py#128