econ-ark / HARK

Heterogenous Agents Resources & toolKit
Apache License 2.0
320 stars 195 forks source link

Syntax for mathematical expressions in model definitions #1085

Open sbenthall opened 2 years ago

sbenthall commented 2 years ago

A desideratum for future versions of HARK is a syntax for mathematical expressions in model definitions.

This syntax need not be the native Python syntax, though this is what is done in @llorracc 's "pre-alpha 2.0" code, which uses strings of Python and the very controversial eval function to parse them.

https://github.com/econ-ark/HARK/pull/1055

Dolo has its own Dolang syntax and interpreter, which is an attractive choice. I wonder if it can be extracted from the YAML context in which it is used.

In conversation with @alanlujan91 and @nicksawhney , Disciplined Convex Programming (DCP) has come up. This is a DSL for convex optimization problems developed by researchers at Stanford. It is implemented in several convex optimization packages, in different languages.

https://www.cvxpy.org/tutorial/dcp/index.html

DCP has the advantage of being featureful with respect to convex optimization -- if it can be expressed in the language, then it guarantees that it can be solved by their optimization engine (in this case CVXPY).

sbenthall commented 2 years ago

I think this comment is partly a reply to this issue?

https://github.com/econ-ark/HARK/issues/1066#issuecomment-979470056

It's a good point that discrete choice problems are not convex optimization.

llorracc commented 2 years ago

Yes, it's a reply. And an attempt to elaborate a bit on the discussion about "magic" solvers.

In particular, to make the point that any general-purpose solution method's first requirement is a general-purpose technology for describing the problem with complete clarity. Even a "magic" solver could not solve correctly a problem that was not defined completely.

On Fri, Nov 26, 2021 at 3:40 PM Sebastian Benthall @.***> wrote:

I think this comment is partly a reply to this issue?

1066 (comment)

https://github.com/econ-ark/HARK/issues/1066#issuecomment-979470056

It's a good point that discrete choice problems are not convex optimization.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/econ-ark/HARK/issues/1085#issuecomment-980427967, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKCK7YFJN3PYUMS3DCV4U3UN7WFRANCNFSM5IR6FJUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--

sbenthall commented 1 month ago

The current approach to this issue that's favored is to use Sympy to parse strings into symbolic expressions, and then convert these into other forms as needed.

I'm working on this in PR #1427