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.