Quantcast

upcoming change to JuMP syntax (or, JuMP to dump curly braces)

Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

upcoming change to JuMP syntax (or, JuMP to dump curly braces)

Miles Lubin
I'd like to let everyone know about an upcoming change to JuMP syntax. This change has the potential to be more annoying than the big renaming we recently did because it requires more manual work than a simple find-and-replace.

To provide some context, the curly-brace sum{x[i], i=1:N; isodd(i)} syntax that exists in JuMP but not in Julia itself was designed as a hack for the lack of support for filter conditions in Julia's comprehension syntax. Well, Julia 0.5 now provides this syntax. This means we can now replace the previous expression with sum(x[i] for i=1:N if isodd(i))which is 1) more human readable, and 2) more consistent with plain Julia code. I just merged support for this syntax into JuMP master.

More examples:

sum{ship[i,j], j=1:nummarkets} becomes sum(ship[i,j] for j=1:nummarkets)
prod{x[i],i=1:18} becomes prod(x[i] for i=1:18)
sum{x[i,j] * y[i,j], i = 1:N, j in 1:M; i != j} becomes sum(x[i,j] * y[i,j] for i = 1:N, j in 1:M if i != j)
sum{foo[i,j], i = 1:N, j = 1:i} becomes sum(foo[i,j] for i = 1:N, j = 1:i)**

The current plan for transitioning to this new syntax is as follows:
- The next release, JuMP 0.14, will support both Julia 0.4 and Julia 0.5. The new syntax will be available for testing to users of Julia 0.5. No deprecation warnings for the old curly-brace syntax (yet).
- The following release, JuMP 0.15, will support only Julia 0.5 and using old curly-brace syntax will result in annoying deprecation warnings. At this point we will again call on the community to help update the JuMP code snippets that are floating around the internet.
- Support for the old syntax (with deprecation warnings) will continue for quite a long time; I imagine at least a year. However, leaving it as a permanent alternative is not an option because it would be quite confusing to new users to do so and it places an additional burden on us as the developers.

I'm aware that this is a big change, although updating code to remove the curly braces is probably not much more time consuming than dealing with the rest the changes that need to be made to transition from Julia 0.4 to Julia 0.5. If you'd like to test out the new syntax right now, install a recent version of Julia master and check out the master branch of JuMP (if you don't know how to do this, you may want to wait for the release).

Miles


** This example deviates slightly from Julia code. In JuMP we can allow dependencies in the index sets. In plain Julia code this would need to be sum(foo[i,j] for i = 1:N for j = 1:i). This discrepancy between JuMP and Julia syntax might go away in the future.

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: upcoming change to JuMP syntax (or, JuMP to dump curly braces)

Cesar P.
I want to congratulate the JuMP developers for this change.
I strongly agree that this is the time to improve things, even if it breaks current programs.
Better break now and have an improved language for the future than keep things as they are and regret in the future.
I hope the full deprecation takes place sooner than expected. Backwards compatibility only adds complexity and head-aches.

> This discrepancy between JuMP and Julia syntax might go away in the future

I hope that means Julia will behave more like JuMP.
sum(foo[i,j] for i = 1:N, j = 1:i) is much more natural.

But there's some inconsistency here?
> sum(x[i,j] * y[i,j] for i = 1:N, j in 1:M if i != j)
Why isn't it -
  sum(x[i,j] * y[i,j] for i = 1:N, j = 1:M if i != j)

Last, if improvements comes from breaking, please don't be shy. Keep on breaking!



--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: upcoming change to JuMP syntax (or, JuMP to dump curly braces)

Miles Lubin
But there's some inconsistency here?
> sum(x[i,j] * y[i,j] for i = 1:N, j in 1:M if i != j)
Why isn't it -
  sum(x[i,j] * y[i,j] for i = 1:N, j = 1:M if i != j)

'=' and 'in' will remain interchangeable as they are now. 

--
You received this message because you are subscribed to the Google Groups "julia-opt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Visit this group at https://groups.google.com/group/julia-opt.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: upcoming change to JuMP syntax (or, JuMP to dump curly braces)

wwei8825
This post has NOT been accepted by the mailing list yet.
In reply to this post by Miles Lubin
Hi Miles,
This is nice change since the syntax becomes more readable. I am using Jupyter, which will indent automatically after for until there is an end. But in this sum syntax there will be no end. Is there any method to avoid the indent in this situation? Thanks so much.
Loading...