discopt 0.2.4__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. {discopt-0.2.4 → discopt-0.3.0}/Cargo.lock +5 -4
  2. {discopt-0.2.4 → discopt-0.3.0}/Cargo.toml +1 -1
  3. {discopt-0.2.4 → discopt-0.3.0}/PKG-INFO +5 -1
  4. {discopt-0.2.4 → discopt-0.3.0}/README.md +4 -0
  5. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/bnb/branching.rs +126 -15
  6. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/bnb/node.rs +1 -7
  7. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/bnb/pool.rs +1 -5
  8. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/bnb/tree_manager.rs +74 -20
  9. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/expr.rs +52 -41
  10. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/nl_parser.rs +254 -128
  11. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/presolve/fbbt.rs +1 -4
  12. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/presolve/obbt.rs +7 -21
  13. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/presolve/simplify.rs +3 -7
  14. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/src/batch.rs +6 -2
  15. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/src/bnb_bindings.rs +15 -22
  16. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/src/expr_bindings.rs +86 -62
  17. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/src/nl_bindings.rs +4 -6
  18. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/src/ripopt_bindings.rs +173 -76
  19. {discopt-0.2.4 → discopt-0.3.0}/pyproject.toml +50 -1
  20. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/__init__.py +30 -1
  21. discopt-0.3.0/python/discopt/_jax/convexity/__init__.py +44 -0
  22. discopt-0.3.0/python/discopt/_jax/convexity/certificate.py +173 -0
  23. discopt-0.3.0/python/discopt/_jax/convexity/eigenvalue.py +113 -0
  24. discopt-0.3.0/python/discopt/_jax/convexity/interval.py +391 -0
  25. discopt-0.3.0/python/discopt/_jax/convexity/interval_ad.py +579 -0
  26. discopt-0.3.0/python/discopt/_jax/convexity/interval_eval.py +300 -0
  27. discopt-0.3.0/python/discopt/_jax/convexity/lattice.py +405 -0
  28. discopt-0.3.0/python/discopt/_jax/convexity/linear_context.py +306 -0
  29. discopt-0.3.0/python/discopt/_jax/convexity/patterns.py +562 -0
  30. discopt-0.3.0/python/discopt/_jax/convexity/rules.py +832 -0
  31. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/cutting_planes.py +19 -32
  32. discopt-0.3.0/python/discopt/_jax/dag_compiler.py +335 -0
  33. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/differentiable.py +102 -10
  34. discopt-0.3.0/python/discopt/_jax/discretization.py +238 -0
  35. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/ipm.py +416 -40
  36. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/ipm_callbacks.py +2 -0
  37. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/lp_ipm.py +54 -25
  38. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/mccormick.py +9 -0
  39. discopt-0.3.0/python/discopt/_jax/milp_relaxation.py +993 -0
  40. discopt-0.3.0/python/discopt/_jax/model_utils.py +17 -0
  41. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/nl_evaluator.py +93 -0
  42. discopt-0.3.0/python/discopt/_jax/nlp_evaluator.py +561 -0
  43. discopt-0.3.0/python/discopt/_jax/parametric.py +153 -0
  44. discopt-0.3.0/python/discopt/_jax/partition_selection.py +276 -0
  45. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/problem_classifier.py +10 -2
  46. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/qp_ipm.py +15 -19
  47. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/relaxation_compiler.py +66 -0
  48. discopt-0.3.0/python/discopt/_jax/scaling.py +98 -0
  49. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/sparse_jacobian.py +58 -15
  50. discopt-0.3.0/python/discopt/_jax/term_classifier.py +346 -0
  51. discopt-0.3.0/python/discopt/benchmarks/problems/__init__.py +11 -0
  52. discopt-0.3.0/python/discopt/benchmarks/problems/gas_network_minlp.py +234 -0
  53. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/cli.py +220 -0
  54. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/dae/collocation.py +104 -57
  55. discopt-0.3.0/python/discopt/doe/__init__.py +111 -0
  56. discopt-0.3.0/python/discopt/doe/design.py +781 -0
  57. discopt-0.3.0/python/discopt/doe/discrimination.py +713 -0
  58. discopt-0.3.0/python/discopt/doe/discrimination_sequential.py +237 -0
  59. discopt-0.3.0/python/discopt/doe/estimability.py +377 -0
  60. discopt-0.3.0/python/discopt/doe/exploration.py +204 -0
  61. discopt-0.3.0/python/discopt/doe/fim.py +670 -0
  62. discopt-0.3.0/python/discopt/doe/profile.py +424 -0
  63. discopt-0.3.0/python/discopt/doe/selection.py +376 -0
  64. discopt-0.3.0/python/discopt/doe/sequential.py +187 -0
  65. discopt-0.3.0/python/discopt/estimate.py +476 -0
  66. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/export/__init__.py +3 -1
  67. discopt-0.3.0/python/discopt/export/gams.py +385 -0
  68. discopt-0.3.0/python/discopt/export/nl.py +645 -0
  69. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/interfaces/cutest.py +59 -4
  70. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/__init__.py +2 -2
  71. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/chat.py +2 -2
  72. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/provider.py +4 -4
  73. discopt-0.3.0/python/discopt/mo/__init__.py +93 -0
  74. discopt-0.3.0/python/discopt/mo/indicators.py +267 -0
  75. discopt-0.3.0/python/discopt/mo/nbi.py +336 -0
  76. discopt-0.3.0/python/discopt/mo/pareto.py +256 -0
  77. discopt-0.3.0/python/discopt/mo/scalarization.py +588 -0
  78. discopt-0.3.0/python/discopt/mo/utils.py +243 -0
  79. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/modeling/core.py +159 -26
  80. discopt-0.3.0/python/discopt/modeling/gams_parser.py +2190 -0
  81. discopt-0.3.0/python/discopt/ro/ROADMAP.md +102 -0
  82. discopt-0.3.0/python/discopt/ro/__init__.py +83 -0
  83. discopt-0.3.0/python/discopt/ro/affine_policy.py +421 -0
  84. discopt-0.3.0/python/discopt/ro/counterpart.py +188 -0
  85. discopt-0.3.0/python/discopt/ro/formulations/__init__.py +11 -0
  86. discopt-0.3.0/python/discopt/ro/formulations/_common.py +273 -0
  87. discopt-0.3.0/python/discopt/ro/formulations/box.py +389 -0
  88. discopt-0.3.0/python/discopt/ro/formulations/ellipsoidal.py +240 -0
  89. discopt-0.3.0/python/discopt/ro/formulations/polyhedral.py +278 -0
  90. discopt-0.3.0/python/discopt/ro/uncertainty.py +308 -0
  91. discopt-0.3.0/python/discopt/skills/__init__.py +55 -0
  92. discopt-0.3.0/python/discopt/skills/agents/amp-expert.md +102 -0
  93. discopt-0.3.0/python/discopt/skills/agents/benchmarking-expert.md +118 -0
  94. discopt-0.3.0/python/discopt/skills/agents/convex-relaxation-expert.md +96 -0
  95. discopt-0.3.0/python/discopt/skills/agents/convexity-detection-expert.md +92 -0
  96. discopt-0.3.0/python/discopt/skills/agents/differentiability-expert.md +106 -0
  97. discopt-0.3.0/python/discopt/skills/agents/doe-expert.md +88 -0
  98. discopt-0.3.0/python/discopt/skills/agents/estimability-expert.md +115 -0
  99. discopt-0.3.0/python/discopt/skills/agents/estimation-expert.md +95 -0
  100. discopt-0.3.0/python/discopt/skills/agents/heuristics-expert.md +98 -0
  101. discopt-0.3.0/python/discopt/skills/agents/highs-expert.md +141 -0
  102. discopt-0.3.0/python/discopt/skills/agents/identifiability-expert.md +106 -0
  103. discopt-0.3.0/python/discopt/skills/agents/ipopt-expert.md +121 -0
  104. discopt-0.3.0/python/discopt/skills/agents/jax-ipm-expert.md +102 -0
  105. discopt-0.3.0/python/discopt/skills/agents/llm-feature-expert.md +119 -0
  106. discopt-0.3.0/python/discopt/skills/agents/minlp-solver-expert.md +109 -0
  107. discopt-0.3.0/python/discopt/skills/agents/model-discrimination-expert.md +139 -0
  108. discopt-0.3.0/python/discopt/skills/agents/modeling-expert.md +107 -0
  109. discopt-0.3.0/python/discopt/skills/agents/multiobjective-expert.md +114 -0
  110. discopt-0.3.0/python/discopt/skills/agents/nn-embedding-expert.md +112 -0
  111. discopt-0.3.0/python/discopt/skills/agents/presolve-expert.md +88 -0
  112. discopt-0.3.0/python/discopt/skills/agents/robust-opt-expert.md +115 -0
  113. discopt-0.3.0/python/discopt/skills/agents/scip-expert.md +199 -0
  114. discopt-0.3.0/python/discopt/skills/commands/adversary.md +254 -0
  115. discopt-0.3.0/python/discopt/skills/commands/benchmark-report.md +99 -0
  116. discopt-0.3.0/python/discopt/skills/commands/convert.md +85 -0
  117. discopt-0.3.0/python/discopt/skills/commands/diagnose.md +83 -0
  118. discopt-0.3.0/python/discopt/skills/commands/discoptbot.md +237 -0
  119. discopt-0.3.0/python/discopt/skills/commands/doe.md +138 -0
  120. discopt-0.3.0/python/discopt/skills/commands/estimate.md +102 -0
  121. discopt-0.3.0/python/discopt/skills/commands/explain-model.md +106 -0
  122. discopt-0.3.0/python/discopt/skills/commands/formulate.md +94 -0
  123. discopt-0.3.0/python/discopt/skills/commands/reformulate.md +81 -0
  124. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solver.py +1632 -187
  125. discopt-0.3.0/python/discopt/solvers/amp.py +992 -0
  126. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/gdpopt_loa.py +118 -17
  127. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/lp_highs.py +16 -12
  128. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/nlp_ipopt.py +65 -33
  129. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/nlp_ripopt.py +5 -3
  130. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/oa.py +102 -18
  131. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/qp_highs.py +19 -10
  132. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/sipopt.py +4 -7
  133. discopt-0.2.4/python/discopt/_jax/convexity.py +0 -401
  134. discopt-0.2.4/python/discopt/_jax/dag_compiler.py +0 -265
  135. discopt-0.2.4/python/discopt/_jax/nlp_evaluator.py +0 -225
  136. {discopt-0.2.4 → discopt-0.3.0}/LICENSE +0 -0
  137. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/Cargo.toml +0 -0
  138. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/bnb/mod.rs +0 -0
  139. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/lib.rs +1 -1
  140. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/presolve/mod.rs +0 -0
  141. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-core/src/presolve/probing.rs +2 -2
  142. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/Cargo.toml +0 -0
  143. {discopt-0.2.4 → discopt-0.3.0}/crates/discopt-python/src/lib.rs +0 -0
  144. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/PHASE3_MATH_NOTES.md +0 -0
  145. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/__init__.py +0 -0
  146. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/alphabb.py +0 -0
  147. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/batch_evaluator.py +0 -0
  148. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/differentiable_lp.py +0 -0
  149. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/differentiable_qp.py +0 -0
  150. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/differentiable_solve.py +0 -0
  151. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/envelopes.py +0 -0
  152. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/gdp_reformulate.py +0 -0
  153. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/gnn_branching.py +0 -0
  154. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/gnn_policy.py +0 -0
  155. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/icnn.py +0 -0
  156. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/icnn_trainer.py +0 -0
  157. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/ipm_iterative.py +0 -0
  158. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/learned_relaxations.py +0 -0
  159. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/mccormick_nlp.py +0 -0
  160. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/nl_reconstruction.py +0 -0
  161. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/obbt.py +0 -0
  162. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/pcg.py +0 -0
  163. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/piecewise_mccormick.py +0 -0
  164. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/primal_heuristics.py +0 -0
  165. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/problem_graph.py +0 -0
  166. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/sparse_ipm.py +0 -0
  167. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/sparse_kkt.py +0 -0
  168. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/sparsity.py +0 -0
  169. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/_jax/strong_branching.py +0 -0
  170. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/benchmarks/__init__.py +0 -0
  171. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/benchmarks/metrics.py +0 -0
  172. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/benchmarks/runner.py +0 -0
  173. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/callbacks.py +0 -0
  174. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/constants.py +0 -0
  175. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/dae/__init__.py +0 -0
  176. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/dae/finite_difference.py +0 -0
  177. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/dae/mol.py +0 -0
  178. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/dae/polynomials.py +0 -0
  179. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/export/_extract.py +0 -0
  180. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/export/lp.py +0 -0
  181. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/export/mps.py +0 -0
  182. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/interfaces/__init__.py +0 -0
  183. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/advisor.py +0 -0
  184. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/commentary.py +0 -0
  185. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/diagnosis.py +0 -0
  186. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/prompts.py +0 -0
  187. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/reformulation.py +0 -0
  188. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/safety.py +0 -0
  189. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/serializer.py +0 -0
  190. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/llm/tools.py +0 -0
  191. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/modeling/__init__.py +0 -0
  192. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/modeling/examples.py +0 -0
  193. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/__init__.py +0 -0
  194. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/bounds.py +0 -0
  195. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/formulations/__init__.py +0 -0
  196. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/formulations/base.py +0 -0
  197. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/formulations/full_space.py +0 -0
  198. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/formulations/reduced_space.py +0 -0
  199. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/formulations/relu_bigm.py +0 -0
  200. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/formulations/tree_ensemble.py +0 -0
  201. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/network.py +0 -0
  202. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/predictor.py +0 -0
  203. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/readers/__init__.py +0 -0
  204. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/readers/onnx_reader.py +0 -0
  205. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/readers/sklearn_reader.py +0 -0
  206. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/readers/torch_reader.py +0 -0
  207. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/scaling.py +0 -0
  208. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/nn/tree.py +0 -0
  209. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/__init__.py +0 -0
  210. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/solvers/milp_highs.py +0 -0
  211. {discopt-0.2.4 → discopt-0.3.0}/python/discopt/warm_start.py +0 -0
@@ -1067,9 +1067,9 @@ checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
1067
1067
 
1068
1068
  [[package]]
1069
1069
  name = "ripopt"
1070
- version = "0.6.0"
1070
+ version = "0.7.0"
1071
1071
  source = "registry+https://github.com/rust-lang/crates.io-index"
1072
- checksum = "fb2217dfe4ec562aaeefb002b9a9427e8bd47ff9f94f37494f51e13723ddcf61"
1072
+ checksum = "9dc0a384c111f7327f9ae75a18444670a8e8ed1bb3008f3825b5bf7f99d35f99"
1073
1073
  dependencies = [
1074
1074
  "env_logger",
1075
1075
  "faer",
@@ -1081,11 +1081,12 @@ dependencies = [
1081
1081
 
1082
1082
  [[package]]
1083
1083
  name = "rmumps"
1084
- version = "0.1.0"
1084
+ version = "0.1.1"
1085
1085
  source = "registry+https://github.com/rust-lang/crates.io-index"
1086
- checksum = "514a798c9a81dec2c1394589d661e99dc5c95ae7813dbf89c8eaac0ffd8f76bc"
1086
+ checksum = "cf79c819201aea6aeed6acb8aa275f7c0bb822a7b22d1ba089921a61507e9cc5"
1087
1087
  dependencies = [
1088
1088
  "amd",
1089
+ "faer",
1089
1090
  "rayon",
1090
1091
  ]
1091
1092
 
@@ -11,4 +11,4 @@ repository = "https://github.com/discopt-org/discopt"
11
11
  [workspace.dependencies]
12
12
  pyo3 = { version = "0.23", features = ["extension-module"] }
13
13
  numpy = "0.23"
14
- ripopt = "0.6.0"
14
+ ripopt = "0.7.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: discopt
3
- Version: 0.2.4
3
+ Version: 0.3.0
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Science/Research
6
6
  Classifier: License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)
@@ -61,11 +61,15 @@ Project-URL: Repository, https://github.com/jkitchin/discopt
61
61
 
62
62
  # discopt
63
63
 
64
+ [![PyPI](https://img.shields.io/pypi/v/discopt)](https://pypi.org/project/discopt/)
64
65
  [![CI](https://github.com/jkitchin/discopt/actions/workflows/ci.yml/badge.svg)](https://github.com/jkitchin/discopt/actions/workflows/ci.yml)
65
66
  [![codecov](https://codecov.io/gh/jkitchin/discopt/graph/badge.svg?token=B3Y6LAtox9)](https://codecov.io/gh/jkitchin/discopt)
67
+ [![DOI](https://zenodo.org/badge/1151864770.svg)](https://zenodo.org/badge/latestdoi/1151864770)
66
68
 
67
69
  [![discopt](https://github.com/jkitchin/discopt/blob/main/discopt.png?raw=true)](https://github.com/jkitchin/discopt/blob/main/discopt.png?raw=true)
68
70
 
71
+ ![PyPI Downloads](https://img.shields.io/pypi/dm/discopt.svg)
72
+
69
73
  A hybrid Mixed-Integer Nonlinear Programming (MINLP) solver combining a Rust backend, JAX automatic differentiation, and Python orchestration. Solves MINLP problems via NLP-based spatial Branch and Bound with JIT-compiled objective/gradient/Hessian evaluation.
70
74
 
71
75
  ## Features
@@ -1,10 +1,14 @@
1
1
  # discopt
2
2
 
3
+ [![PyPI](https://img.shields.io/pypi/v/discopt)](https://pypi.org/project/discopt/)
3
4
  [![CI](https://github.com/jkitchin/discopt/actions/workflows/ci.yml/badge.svg)](https://github.com/jkitchin/discopt/actions/workflows/ci.yml)
4
5
  [![codecov](https://codecov.io/gh/jkitchin/discopt/graph/badge.svg?token=B3Y6LAtox9)](https://codecov.io/gh/jkitchin/discopt)
6
+ [![DOI](https://zenodo.org/badge/1151864770.svg)](https://zenodo.org/badge/latestdoi/1151864770)
5
7
 
6
8
  [![discopt](https://github.com/jkitchin/discopt/blob/main/discopt.png?raw=true)](https://github.com/jkitchin/discopt/blob/main/discopt.png?raw=true)
7
9
 
10
+ ![PyPI Downloads](https://img.shields.io/pypi/dm/discopt.svg)
11
+
8
12
  A hybrid Mixed-Integer Nonlinear Programming (MINLP) solver combining a Rust backend, JAX automatic differentiation, and Python orchestration. Solves MINLP problems via NLP-based spatial Branch and Bound with JIT-compiled objective/gradient/Hessian evaluation.
9
13
 
10
14
  ## Features
@@ -287,6 +287,12 @@ pub fn create_children(
287
287
  // Warm-start: pass parent's stored solution to children.
288
288
  let parent_sol = parent.parent_solution.clone();
289
289
 
290
+ // Inherit parent's lower bound: the child's feasible region is a subset
291
+ // of the parent's, so the parent's lower bound is valid for the child.
292
+ // This prevents the global lower bound from dropping to -inf when
293
+ // unsolved children enter the pool.
294
+ let inherited_lb = parent.local_lower_bound;
295
+
290
296
  // Left child: x_i <= floor(val)
291
297
  let mut left_ub = parent.ub.clone();
292
298
  left_ub[idx] = bp; // bp is already floor(val)
@@ -296,7 +302,7 @@ pub fn create_children(
296
302
  depth: parent.depth + 1,
297
303
  lb: parent.lb.clone(),
298
304
  ub: left_ub,
299
- local_lower_bound: f64::NEG_INFINITY,
305
+ local_lower_bound: inherited_lb,
300
306
  status: NodeStatus::Pending,
301
307
  parent_solution: parent_sol.clone(),
302
308
  };
@@ -310,7 +316,7 @@ pub fn create_children(
310
316
  depth: parent.depth + 1,
311
317
  lb: right_lb,
312
318
  ub: parent.ub.clone(),
313
- local_lower_bound: f64::NEG_INFINITY,
319
+ local_lower_bound: inherited_lb,
314
320
  status: NodeStatus::Pending,
315
321
  parent_solution: parent_sol,
316
322
  };
@@ -318,6 +324,111 @@ pub fn create_children(
318
324
  (left, right)
319
325
  }
320
326
 
327
+ /// Create two child nodes by spatial bisection on a continuous variable.
328
+ ///
329
+ /// Left child: x_i <= midpoint. Right child: x_i >= midpoint.
330
+ /// Unlike integer branching, there is no +1 gap between children.
331
+ pub fn create_children_spatial(
332
+ parent: &Node,
333
+ decision: &BranchDecision,
334
+ mut next_id: impl FnMut() -> NodeId,
335
+ ) -> (Node, Node) {
336
+ let idx = decision.var_index;
337
+ let bp = decision.branch_point; // midpoint
338
+
339
+ let parent_sol = parent.parent_solution.clone();
340
+ let inherited_lb = parent.local_lower_bound;
341
+
342
+ // Left child: x_i <= midpoint
343
+ let mut left_ub = parent.ub.clone();
344
+ left_ub[idx] = bp;
345
+ let left = Node {
346
+ id: next_id(),
347
+ parent: Some(parent.id),
348
+ depth: parent.depth + 1,
349
+ lb: parent.lb.clone(),
350
+ ub: left_ub,
351
+ local_lower_bound: inherited_lb,
352
+ status: NodeStatus::Pending,
353
+ parent_solution: parent_sol.clone(),
354
+ };
355
+
356
+ // Right child: x_i >= midpoint (no gap)
357
+ let mut right_lb = parent.lb.clone();
358
+ right_lb[idx] = bp;
359
+ let right = Node {
360
+ id: next_id(),
361
+ parent: Some(parent.id),
362
+ depth: parent.depth + 1,
363
+ lb: right_lb,
364
+ ub: parent.ub.clone(),
365
+ local_lower_bound: inherited_lb,
366
+ status: NodeStatus::Pending,
367
+ parent_solution: parent_sol,
368
+ };
369
+
370
+ (left, right)
371
+ }
372
+
373
+ /// Minimum relative domain width for a continuous variable to be eligible
374
+ /// for spatial branching. Prevents infinite bisection.
375
+ const SPATIAL_MIN_WIDTH: f64 = 1e-6;
376
+
377
+ /// Select a continuous variable for spatial branching (longest-edge bisection).
378
+ ///
379
+ /// Picks the variable with the widest domain relative to its global range.
380
+ /// Only considers variables whose current domain width exceeds
381
+ /// [`SPATIAL_MIN_WIDTH`] times the global width.
382
+ pub fn select_spatial_branch_variable(
383
+ node_lb: &[f64],
384
+ node_ub: &[f64],
385
+ global_lb: &[f64],
386
+ global_ub: &[f64],
387
+ integer_vars: &[VarBranchInfo],
388
+ ) -> Option<BranchDecision> {
389
+ let n = node_lb.len();
390
+ let mut best_idx: Option<usize> = None;
391
+ let mut best_width = 0.0_f64;
392
+
393
+ // Build a quick lookup of which flat indices are integer variables.
394
+ let mut is_int = vec![false; n];
395
+ for var in integer_vars {
396
+ for i in 0..var.size {
397
+ let idx = var.offset + i;
398
+ if idx < n {
399
+ is_int[idx] = true;
400
+ }
401
+ }
402
+ }
403
+
404
+ for idx in 0..n {
405
+ if is_int[idx] {
406
+ continue;
407
+ }
408
+ let width = node_ub[idx] - node_lb[idx];
409
+ let global_width = global_ub[idx] - global_lb[idx];
410
+ if global_width < 1e-15 {
411
+ continue; // Fixed variable, skip.
412
+ }
413
+ let relative_width = width / global_width;
414
+ if relative_width < SPATIAL_MIN_WIDTH {
415
+ continue; // Domain already very tight.
416
+ }
417
+ if width > best_width {
418
+ best_width = width;
419
+ best_idx = Some(idx);
420
+ }
421
+ }
422
+
423
+ best_idx.map(|idx| {
424
+ let mid = 0.5 * (node_lb[idx] + node_ub[idx]);
425
+ BranchDecision {
426
+ var_index: idx,
427
+ branch_point: mid,
428
+ }
429
+ })
430
+ }
431
+
321
432
  #[cfg(test)]
322
433
  mod tests {
323
434
  use super::*;
@@ -363,8 +474,16 @@ mod tests {
363
474
  // x0 continuous=0.5, x1 integer=0.7
364
475
  let solution = vec![0.5, 0.7];
365
476
  let vars = vec![
366
- VarBranchInfo { offset: 0, size: 1, is_integer: false },
367
- VarBranchInfo { offset: 1, size: 1, is_integer: true },
477
+ VarBranchInfo {
478
+ offset: 0,
479
+ size: 1,
480
+ is_integer: false,
481
+ },
482
+ VarBranchInfo {
483
+ offset: 1,
484
+ size: 1,
485
+ is_integer: true,
486
+ },
368
487
  ];
369
488
  let decision = select_branch_variable(&solution, &vars).unwrap();
370
489
  assert_eq!(decision.var_index, 1); // only x1 is integer
@@ -417,13 +536,7 @@ mod tests {
417
536
 
418
537
  #[test]
419
538
  fn test_create_children_bounds() {
420
- let parent = Node::new(
421
- NodeId(0),
422
- None,
423
- 0,
424
- vec![0.0, 0.0],
425
- vec![10.0, 10.0],
426
- );
539
+ let parent = Node::new(NodeId(0), None, 0, vec![0.0, 0.0], vec![10.0, 10.0]);
427
540
  let decision = BranchDecision {
428
541
  var_index: 0,
429
542
  branch_point: 3.0, // branching x0 at floor(3.7) = 3
@@ -542,8 +655,7 @@ mod tests {
542
655
  pc.update(2, 0.0, 10.0, 0.5, true); // per-unit = 20.0
543
656
  pc.update(2, 0.0, 10.0, 0.5, false); // per-unit = 20.0
544
657
 
545
- let (decision, _unreliable) =
546
- select_branch_variable_pseudocost(&solution, &vars, &pc, 8);
658
+ let (decision, _unreliable) = select_branch_variable_pseudocost(&solution, &vars, &pc, 8);
547
659
  let d = decision.unwrap();
548
660
  assert_eq!(d.var_index, 2); // var 2 has highest score
549
661
  assert_eq!(d.branch_point, 0.0);
@@ -558,8 +670,7 @@ mod tests {
558
670
  is_integer: true,
559
671
  }];
560
672
  let pc = Pseudocosts::new(2); // no observations
561
- let (_decision, unreliable) =
562
- select_branch_variable_pseudocost(&solution, &vars, &pc, 8);
673
+ let (_decision, unreliable) = select_branch_variable_pseudocost(&solution, &vars, &pc, 8);
563
674
  // Both variables have 0 observations < 8 threshold → unreliable.
564
675
  assert_eq!(unreliable.len(), 2);
565
676
  assert!(unreliable.contains(&0));
@@ -68,13 +68,7 @@ mod tests {
68
68
 
69
69
  #[test]
70
70
  fn test_node_creation() {
71
- let node = Node::new(
72
- NodeId(0),
73
- None,
74
- 0,
75
- vec![0.0, 0.0],
76
- vec![1.0, 1.0],
77
- );
71
+ let node = Node::new(NodeId(0), None, 0, vec![0.0, 0.0], vec![1.0, 1.0]);
78
72
  assert_eq!(node.id, NodeId(0));
79
73
  assert_eq!(node.parent, None);
80
74
  assert_eq!(node.depth, 0);
@@ -100,11 +100,7 @@ impl NodePool {
100
100
  /// If the node is Pending, it is added to the open set.
101
101
  pub fn add(&mut self, node: Node) -> NodeId {
102
102
  let id = node.id;
103
- assert_eq!(
104
- id.0,
105
- self.nodes.len(),
106
- "Node ID must match insertion order"
107
- );
103
+ assert_eq!(id.0, self.nodes.len(), "Node ID must match insertion order");
108
104
  if node.status == NodeStatus::Pending {
109
105
  self.open.push(HeapEntry {
110
106
  node_id: id,
@@ -3,8 +3,9 @@
3
3
  use std::collections::HashMap;
4
4
 
5
5
  use crate::bnb::branching::{
6
- create_children, is_integer_feasible, select_branch_variable,
7
- select_branch_variable_pseudocost, BranchDecision, Pseudocosts, VarBranchInfo,
6
+ create_children, create_children_spatial, is_integer_feasible, select_branch_variable,
7
+ select_branch_variable_pseudocost, select_spatial_branch_variable, BranchDecision, Pseudocosts,
8
+ VarBranchInfo,
8
9
  };
9
10
  use crate::bnb::node::{Node, NodeId, NodeStatus};
10
11
  use crate::bnb::pool::{NodePool, SelectionStrategy};
@@ -109,6 +110,11 @@ pub struct TreeManager {
109
110
  /// Records of branching decisions: maps child NodeId → parent's BranchRecord.
110
111
  /// Used to retroactively update pseudocosts when child results arrive.
111
112
  branch_records: HashMap<NodeId, BranchRecord>,
113
+ /// When true, integer-feasible nodes are NOT fathomed; instead, spatial
114
+ /// branching on continuous variables continues. Required for nonconvex
115
+ /// MINLPs where the NLP local optimum at an integer-feasible node may
116
+ /// not be the global optimum of the continuous subproblem.
117
+ nonconvex: bool,
112
118
  }
113
119
 
114
120
  impl TreeManager {
@@ -143,9 +149,16 @@ impl TreeManager {
143
149
  use_pseudocosts: true,
144
150
  reliability_threshold: 8,
145
151
  branch_records: HashMap::new(),
152
+ nonconvex: false,
146
153
  }
147
154
  }
148
155
 
156
+ /// Enable nonconvex mode: integer-feasible nodes continue spatial
157
+ /// branching on continuous variables instead of being fathomed.
158
+ pub fn set_nonconvex(&mut self, nonconvex: bool) {
159
+ self.nonconvex = nonconvex;
160
+ }
161
+
149
162
  /// Allocate a fresh NodeId.
150
163
  fn next_id(&mut self) -> NodeId {
151
164
  let id = NodeId(self.node_counter);
@@ -237,7 +250,11 @@ impl TreeManager {
237
250
  let node = self.pool.get(result.node_id);
238
251
  let is_down = record.var_index < node.ub.len()
239
252
  && node.ub[record.var_index]
240
- < self.global_ub.get(record.var_index).copied().unwrap_or(f64::INFINITY);
253
+ < self
254
+ .global_ub
255
+ .get(record.var_index)
256
+ .copied()
257
+ .unwrap_or(f64::INFINITY);
241
258
  self.pseudocosts.update(
242
259
  record.var_index,
243
260
  record.parent_lb,
@@ -259,15 +276,27 @@ impl TreeManager {
259
276
  result.is_feasible || is_integer_feasible(&result.solution, &self.integer_vars);
260
277
 
261
278
  if int_feasible {
262
- self.pool.get_mut(result.node_id).status = NodeStatus::Fathomed;
263
- stats.fathomed += 1;
264
-
265
- if node_lb < self.incumbent_value {
266
- self.incumbent_value = node_lb;
267
- self.incumbent_solution = Some(result.solution.clone());
268
- stats.incumbent_updates += 1;
279
+ if self.nonconvex {
280
+ // Nonconvex mode: node_lb holds the convex RELAXATION
281
+ // bound (not the NLP objective). The Python side has
282
+ // already injected the NLP objective as an incumbent
283
+ // candidate via inject_incumbent(). Do NOT update the
284
+ // incumbent from node_lb here.
285
+ // Fall through to branching (step 3) to spatially branch
286
+ // on continuous variables.
287
+ } else {
288
+ // Convex mode: NLP local optimum = global optimum for the
289
+ // continuous subproblem. Fathom the node.
290
+ self.pool.get_mut(result.node_id).status = NodeStatus::Fathomed;
291
+ stats.fathomed += 1;
292
+
293
+ if node_lb < self.incumbent_value {
294
+ self.incumbent_value = node_lb;
295
+ self.incumbent_solution = Some(result.solution.clone());
296
+ stats.incumbent_updates += 1;
297
+ }
298
+ continue;
269
299
  }
270
- continue;
271
300
  }
272
301
 
273
302
  // 3. Branch: use hint if available, else pseudocost/most-fractional.
@@ -332,6 +361,32 @@ impl TreeManager {
332
361
  self.pool.add(left);
333
362
  self.pool.add(right);
334
363
  stats.branched += 1;
364
+ } else if self.nonconvex && int_feasible {
365
+ // No fractional integer variable, but nonconvex mode: try
366
+ // spatial branching on continuous variables.
367
+ let node = self.pool.get(result.node_id);
368
+ let spatial = select_spatial_branch_variable(
369
+ &node.lb,
370
+ &node.ub,
371
+ &self.global_lb,
372
+ &self.global_ub,
373
+ &self.integer_vars,
374
+ );
375
+ if let Some(ref spatial_decision) = spatial {
376
+ let parent = self.pool.get(result.node_id).clone();
377
+ self.pool.get_mut(result.node_id).status = NodeStatus::Branched;
378
+
379
+ let (left, right) =
380
+ create_children_spatial(&parent, spatial_decision, || self.next_id());
381
+
382
+ self.pool.add(left);
383
+ self.pool.add(right);
384
+ stats.branched += 1;
385
+ } else {
386
+ // All continuous domains are tight; fathom.
387
+ self.pool.get_mut(result.node_id).status = NodeStatus::Fathomed;
388
+ stats.fathomed += 1;
389
+ }
335
390
  } else {
336
391
  // No fractional variable found — treat as fathomed.
337
392
  self.pool.get_mut(result.node_id).status = NodeStatus::Fathomed;
@@ -355,10 +410,8 @@ impl TreeManager {
355
410
  for i in 0..self.pool.total_count() {
356
411
  let node = self.pool.get(NodeId(i));
357
412
  match node.status {
358
- NodeStatus::Pending | NodeStatus::Evaluated => {
359
- if node.local_lower_bound < min_lb {
360
- min_lb = node.local_lower_bound;
361
- }
413
+ NodeStatus::Pending | NodeStatus::Evaluated if node.local_lower_bound < min_lb => {
414
+ min_lb = node.local_lower_bound;
362
415
  }
363
416
  _ => {}
364
417
  }
@@ -395,7 +448,11 @@ impl TreeManager {
395
448
  return f64::INFINITY;
396
449
  }
397
450
  let denom = self.incumbent_value.abs().max(1.0);
398
- (self.incumbent_value - self.global_lower_bound) / denom
451
+ let raw = (self.incumbent_value - self.global_lower_bound) / denom;
452
+ // Clamp to zero: a negative gap means the bound exceeds the
453
+ // incumbent due to numerical noise or suboptimal NLP solves.
454
+ // Don't report it as closed; keep exploring.
455
+ raw.max(0.0)
399
456
  }
400
457
 
401
458
  /// Get aggregate tree statistics.
@@ -432,10 +489,7 @@ impl TreeManager {
432
489
  ///
433
490
  /// This allows the Python orchestrator to identify unreliable candidates
434
491
  /// and perform strong branching before calling `process_evaluated`.
435
- pub fn score_candidates(
436
- &self,
437
- solution: &[f64],
438
- ) -> Vec<(usize, f64, u32, f64)> {
492
+ pub fn score_candidates(&self, solution: &[f64]) -> Vec<(usize, f64, u32, f64)> {
439
493
  let mut candidates = Vec::new();
440
494
  for var in &self.integer_vars {
441
495
  if !var.is_integer {
@@ -374,7 +374,11 @@ impl ModelBuilder {
374
374
  lb: Vec<f64>,
375
375
  ub: Vec<f64>,
376
376
  ) -> usize {
377
- let size: usize = if shape.is_empty() { 1 } else { shape.iter().product() };
377
+ let size: usize = if shape.is_empty() {
378
+ 1
379
+ } else {
380
+ shape.iter().product()
381
+ };
378
382
  let offset = self.n_vars;
379
383
  let block_idx = self.variables.len();
380
384
 
@@ -848,9 +852,7 @@ impl ExprArena {
848
852
  self.collect_var_indices_inner(*t, out);
849
853
  }
850
854
  }
851
- ExprNode::Constant(_)
852
- | ExprNode::ConstantArray(_, _)
853
- | ExprNode::Parameter { .. } => {}
855
+ ExprNode::Constant(_) | ExprNode::ConstantArray(_, _) | ExprNode::Parameter { .. } => {}
854
856
  }
855
857
  }
856
858
  }
@@ -878,9 +880,7 @@ impl ExprArena {
878
880
  f64::NAN
879
881
  }
880
882
  }
881
- ExprNode::Variable {
882
- size, shape, ..
883
- } => {
883
+ ExprNode::Variable { size, shape, .. } => {
884
884
  if *size == 1 {
885
885
  // Scalar variable — compute the flat offset.
886
886
  let offset = self.var_offset(id);
@@ -969,7 +969,7 @@ impl ExprArena {
969
969
  };
970
970
  a0.max(a1)
971
971
  }
972
- MathFunc::Prod => a0, // single-arg prod is identity
972
+ MathFunc::Prod => a0, // single-arg prod is identity
973
973
  MathFunc::Norm2 => a0, // single-arg norm2 is abs
974
974
  }
975
975
  }
@@ -1005,9 +1005,7 @@ impl ExprArena {
1005
1005
  // Sum all elements of the operand.
1006
1006
  self.evaluate_sum_all(*operand, x)
1007
1007
  }
1008
- ExprNode::SumOver { terms } => {
1009
- terms.iter().map(|t| self.evaluate(*t, x)).sum()
1010
- }
1008
+ ExprNode::SumOver { terms } => terms.iter().map(|t| self.evaluate(*t, x)).sum(),
1011
1009
  }
1012
1010
  }
1013
1011
 
@@ -1024,7 +1022,10 @@ impl ExprArena {
1024
1022
  let mut vars: Vec<(usize, usize)> = Vec::new();
1025
1023
  let mut seen = std::collections::HashSet::new();
1026
1024
  for node in &self.nodes {
1027
- if let ExprNode::Variable { index: idx, size, .. } = node {
1025
+ if let ExprNode::Variable {
1026
+ index: idx, size, ..
1027
+ } = node
1028
+ {
1028
1029
  if seen.insert(*idx) {
1029
1030
  vars.push((*idx, *size));
1030
1031
  }
@@ -1173,47 +1174,57 @@ impl ModelRepr {
1173
1174
  MathFunc::Tanh => a0.tanh(),
1174
1175
  MathFunc::Abs => a0.abs(),
1175
1176
  MathFunc::Sign => {
1176
- if a0 > 0.0 { 1.0 } else if a0 < 0.0 { -1.0 } else { 0.0 }
1177
+ if a0 > 0.0 {
1178
+ 1.0
1179
+ } else if a0 < 0.0 {
1180
+ -1.0
1181
+ } else {
1182
+ 0.0
1183
+ }
1177
1184
  }
1178
1185
  MathFunc::Min => {
1179
- let a1 = if args.len() > 1 { self.evaluate_node(args[1], x) } else { f64::NAN };
1186
+ let a1 = if args.len() > 1 {
1187
+ self.evaluate_node(args[1], x)
1188
+ } else {
1189
+ f64::NAN
1190
+ };
1180
1191
  a0.min(a1)
1181
1192
  }
1182
1193
  MathFunc::Max => {
1183
- let a1 = if args.len() > 1 { self.evaluate_node(args[1], x) } else { f64::NAN };
1194
+ let a1 = if args.len() > 1 {
1195
+ self.evaluate_node(args[1], x)
1196
+ } else {
1197
+ f64::NAN
1198
+ };
1184
1199
  a0.max(a1)
1185
1200
  }
1186
1201
  MathFunc::Prod => a0,
1187
1202
  MathFunc::Norm2 => a0,
1188
1203
  }
1189
1204
  }
1190
- ExprNode::Index { base, index } => {
1191
- match self.arena.get(*base) {
1192
- ExprNode::Variable { index: var_idx, shape, .. } => {
1193
- let offset = self.variables[*var_idx].offset;
1194
- let flat = index_spec_to_flat(index, shape);
1195
- x[offset + flat]
1196
- }
1197
- ExprNode::ConstantArray(data, shape) => {
1198
- let flat = index_spec_to_flat(index, shape);
1199
- data[flat]
1200
- }
1201
- ExprNode::Parameter { value, shape, .. } => {
1202
- let flat = index_spec_to_flat(index, shape);
1203
- value[flat]
1204
- }
1205
- _ => f64::NAN,
1205
+ ExprNode::Index { base, index } => match self.arena.get(*base) {
1206
+ ExprNode::Variable {
1207
+ index: var_idx,
1208
+ shape,
1209
+ ..
1210
+ } => {
1211
+ let offset = self.variables[*var_idx].offset;
1212
+ let flat = index_spec_to_flat(index, shape);
1213
+ x[offset + flat]
1206
1214
  }
1207
- }
1208
- ExprNode::MatMul { left, right } => {
1209
- self.evaluate_matmul(*left, *right, x)
1210
- }
1211
- ExprNode::Sum { operand, .. } => {
1212
- self.evaluate_sum_all(*operand, x)
1213
- }
1214
- ExprNode::SumOver { terms } => {
1215
- terms.iter().map(|t| self.evaluate_node(*t, x)).sum()
1216
- }
1215
+ ExprNode::ConstantArray(data, shape) => {
1216
+ let flat = index_spec_to_flat(index, shape);
1217
+ data[flat]
1218
+ }
1219
+ ExprNode::Parameter { value, shape, .. } => {
1220
+ let flat = index_spec_to_flat(index, shape);
1221
+ value[flat]
1222
+ }
1223
+ _ => f64::NAN,
1224
+ },
1225
+ ExprNode::MatMul { left, right } => self.evaluate_matmul(*left, *right, x),
1226
+ ExprNode::Sum { operand, .. } => self.evaluate_sum_all(*operand, x),
1227
+ ExprNode::SumOver { terms } => terms.iter().map(|t| self.evaluate_node(*t, x)).sum(),
1217
1228
  }
1218
1229
  }
1219
1230