-
Notifications
You must be signed in to change notification settings - Fork 35
Roadmap: typing expressions #913
Copy link
Copy link
Open
Description
CPMpy does a lot of isinstance checks (which causes overhead), because with untyped Python code you don't know what to expect.
This is worsened by the fact that we accept both int/bool as well as the numpy np.integer/np.bool_, futhermore, in some places we even silently accept float/np.float (and even have a few tests that use floats).
Type-annotating our expressions will lead to better documentation, safer code (esp wrt handling constants) and ideally more efficient code (fewer isinstance checks).
The new guidelines are:
- no floats in core expressions
- define @Property args in globalconstraints/globalfunctions, and where possible only store pure Python int/bool as constants in those args
- avoid the is_num and is_int utils, and use direct function calls or the typed _listlike utils on the arguments
The work is ongoing, here is a (probably incomplete) tracker:
- typing of implies and a few others in core.py some more typing of core #907
- typing of most globalfunctions typing with args of global functions (except multiplication, element) #910
- typing of Element globalfunction (requires proper typing/handling of multi-dim element, 2d-element constraint can have out-of-bounds indices #444
- typing of Multiplication globalfunction (requires reworking the float test cases so they don't feed floats into it... consider introducing a WsumFloat for floating-constant objectives)
- typing of more globalconstraints exprs with *args constructors, avoid flatlist #897
- typing of most globalconstraints
- typing of Circuit global constraint (there is something weird with list[Expression] not being a ListLike[ExprLike] in an earlier attempt)
- typing of Comparison in core (check for a float test? or I think the test-suite generates constants on the LHS while Python never will, smth like that)
- typing of Operator in core (needs reworking the float-tests, also the presence of wsum makes it tricky to type the internal args; the constructor needs an overhaul in any case)
- elimination of is_num() (because now core expressions can't receive floats anymore)
- elimination of is_int()/is_bool() whenever the arg can only be pure Python
- elimination/replacing of untyped helper functions in utils
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels