dwavesystems / dwave-optimization

Enables the formulation of nonlinear models for industrial optimization problems.
https://docs.ocean.dwavesys.com/en/stable/docs_optimization/index.html#index-optimization
Apache License 2.0
7 stars 18 forks source link

Add NaryReduceNode and InputNode #166

Open wbernoudy opened 2 weeks ago

wbernoudy commented 2 weeks ago

Adds InputNode which subclasses ConstantNode but allows assigning of the state after initialization.

This is to support the new NaryReduceNode, which does an n-ary reduce operation on an arbitrary number of inputs/predecessors. The node is constructed by providing an expression, formulated as a separate Graph, and initial values for the reduction operation.

The current design accepts any Graph but then throws exceptions if it contains unsupported nodes. It would be best if we can pass along helpful error messages to users at the python level. Currently this works by encoding the error message and a Node* in a simple JSON string that is then parsed from Python, where we can grab the corresponding symbol.

wbernoudy commented 1 week ago

I tried out some more complicated things to support custom exception handling in Cython. I put it in a separate branch for now as I'm not sure we'll go that direction. Separate PR here to try to make it a bit easier to review https://github.com/wbernoudy/dwave-optimization/pull/1