minimize_constrained is not consistent with different variable names

102 views
Skip to first unread message

Pol del Aguila Pla

unread,
Sep 3, 2021, 5:25:38 AM9/3/21
to sage-devel
I've encountered a bug in minimize_constrained where it seems that the variable name has an effect on the result. My guess is that this happens somewhere along the translation from symbolic to numerical function. Attached is a minimal notebook to reproduce the bug. Run in the latest docker image sagemath/sagemath:latest.


bug_in_minimize_constrained.ipynb

Michael Orlitzky

unread,
Sep 14, 2021, 7:26:28 AM9/14/21
to sage-...@googlegroups.com
minimize_constrained() is using the variables() method on your
function, and variables() sorts said variables alphabetically. So, for
example,

sage: cm1,c0,c1 = SR.var('cm1,c0,c1')
sage: f(cm1,c0,c1) = cm1 + c0 + c1
sage: f.variables()
(c0, c1, cm1)

The minimizer is thus not in the order that you'd expect (i.e. not in
the correct order to be passed to f). I opened

https://trac.sagemath.org/ticket/32511

for this.


Pol del Aguila Pla

unread,
Sep 16, 2021, 4:28:26 AM9/16/21
to sage-devel
How would one go about contributing a fix to this? It should be easy. I would be happy to try. Could you provide some links on how to do it?  

El dia dimarts, 14 de setembre de 2021 a les 13:26:28 UTC+2, Michael Orlitzky va escriure:

Michael Orlitzky

unread,
Sep 16, 2021, 8:29:23 AM9/16/21
to sage-...@googlegroups.com
On Thu, 2021-09-16 at 01:28 -0700, Pol del Aguila Pla wrote:
> How would one go about contributing a fix to this? It should be easy. I
> would be happy to try. Could you provide some links on how to do it?

The documentation can be found at

 https://doc.sagemath.org/html/en/developer/

The biggest hurdle will be learning git, if you're not already familiar
with it. That can take a few days on its own, but the payoff is worth
it in my opinion.

After that, you follow a "normal" git workflow:

1. Clone the sage repository
2. Create a new branch for your fix
3. Fix the bug, and add a doctest for it
4. Commit the fix
5. Push your branch to the server

And then the only sage-specific part is,

6. Put the name of your branch in the "branch" field on the trac 
ticket, and change its status to "needs review."


With that said... there is one tiny complication in this case. We have
another branch at https://trac.sagemath.org/ticket/32234 that is
awaiting review and that modifies the code for minimize_constrained.
It's likely that a fix for your bug would conflict with that change,
and vice-versa. To avoid that, you can perform an intermediate step,

1a. Check out the branch listed in the "branch" field of trac
ticket 32234.

That way, you'll be working on top of the code that is already awaiting
review, and there will be no merge conflict down the road.

If that's getting too complicated, though, you can just skip it, and
I'll deal with the merge conflict when it happens. I don't think it
will be difficult.


Emmanuel Charpentier

unread,
Aug 19, 2024, 10:52:12 AM8/19/24
to sage-devel

I have filed a new issue which seems germane to this problem.

HTH,

Reply all
Reply to author
Forward
0 new messages