Replies: 4 comments 12 replies
|
Exciting! Would you elaborate on the goals of this? Is it
I tried running some benchmarks and the 4.0.0a2 came out close to or even slower than the current latest version. I do not doubt I may have had bad benchmarks, do you have any to show? |
|
Hey, some feedback on the rewrite from my side :) Generally, I like the fact that PuLP is so Python-centered and easy to use. I prefer to write my code as a standard Python lists, and using familiar Python features like list and dictionary comprehensions. When it comes to AI, I'm not bought on the "coding is solved" narration pushed by the providers of AI models/tools. I believe that human expertise is very valuable and needed for a good end result. The PuLP project is so small that AI probably can do a perfect job in re-writing it from one language to another when it has full specification, but I'm not that confident it will be beneficial in the long term. My biggest concern that there is no one experienced in Rust to do the code reviews of the AI work. Over the recent months, I have seen situations where a project was flooded with so many PRs where the author had no idea what the AI wrote for them the maintainers had to include a "this is not AI slop and I take the responsibility for it" checkbox in the PR template. I've seen so bad AI code in the languages I know, that I don't want to fall into the Gell-Mann amnesia with the languages I don't know. I do believe we should write good software, and that includes performance. I think Python is a really good scripting "frontend" language for libraries, but not that good for their implementation. I like the architecture of a python interface backed by a more performant language. However, I think you accurately noticed that being fully written in Python made it easier to read, understand and contribute to the project. We should take into the account the profile of a potential contributor, and in my opinion they are much less likely to know Rust than Python, which considerably shrinks the potential for contributions. Also, while AI is really great for learning a new skill, I'm not sure if a popular open-source repository with millions of downloads is a good place for such adventures. I think that a migration to a more performant language can be a good thing, but it should be overseen by someone experienced in the language, and AI output should be taken with a big caution. |
|
One regression that I found is that you can no longer modify the constraints after adding them to the program. For example, this code used to work: >>> import pulp as lp
>>> prob = lp.LpProblem()
>>> x = lp.LpVariable('x')
>>> constr = x <= 2
>>> prob += constr
>>> constr[x] = 2
>>> constr
2*x + -2 <= 0
>>> prob.constraints
OrderedDict({'_C1': 2*x + -2 <= 0}In the new version, the constraint doesn't get updated: >>> import pulp as lp
>>> prob = lp.LpProblem()
>>> x = prob.add_variable('x')
>>> constr = x <= 2
>>> prob += constr
>>> constr[x] = 2
>>> constr
2.0*x + -2.0 <= 0
>>> prob.constraints()
[1.0*x + -2.0 <= 0]To back up why this could be useful, consider an example where I want to create a plot where the x-axis is one of the coefficient in the constraints, and the y-axis is the objective value: import pulp as lp
import matplotlib.pyplot as plt
import numpy as np
prob = lp.LpProblem()
var = prob.add_variable('var')
constr = ...
# fill prob with some constraints and objective
xs = np.linspace(0, 3, 20)
ys = []
for x in xs:
constr[var] = x
prob.solve()
ys.append(prob.objective.value())
plt.plot(xs, ys)I see in the source code that the immutability is intentional. @pchtsp can you share the rationale behind this change? It seems very unintuitive for me. |
|
Hello @greg19 thanks for pointing this out. Interesting! I think you found an unintentional backwards incompatibility. I don't think that was an explicit functionality (and I've never used that and I don't think it was ever documented). I've always re-created a model from scratch. Can you create (1) an issue and then (2) a PR with a proposed fix? Thanks again. |

Uh oh!
There was an error while loading. Please reload this page.
I'm working on a new version of PuLP with a Rust core that's supposed to bring good efficiency gains.
The code is being kept in a separate branch for now: https://github.com/coin-or/pulp/tree/rust_core
I recently built wheels and uploaded them into a pre-release on pypi so it's easy to install and test by end users.
In case someone wants to try it out with a large problem (or with any problem):
or with uv:
You need to explicitly pin the version or you won't get the pre-release.
Let me know if something breaks THAT'S NOT SUPPOSED TO BREAK (see: https://github.com/coin-or/pulp/tree/rust_core?tab=readme-ov-file#quickstart) for the syntax change in variable creation (e.g., prob.add_variable() instead of LpVariable()).
All reactions