Announcing Neptune.jl (now updated to multi-line cells!)

Without reactivity, can you use widgets? This for me is the advantage of Pluto over writing a script or markdown file in vscode.

Sorry for the late entry. Does Neptune run code with macros? I have a simple JuMP model that does not run in Pluto because reactivity collides with defining variables, constraints, and the objective with a macro. There are so many packages in Julia that use macros. If Pluto can not deal with such a fundamental part of Julia, why were we not alerted to this fact? Macros in Julia are just not peanuts, are they?

This is not a philosophical computational issue or just a matter of mere taste. I do not bother typing begin ... end blocks endlessly, I do not bother reactivity (which I sometimes like – when it avoids my students making simple mistakes – and dislike some other times). I do like its simplicity and basic layout and the superb display quality of markdown and LaTeX. But this macro thing is a practical issue of tremendous importance. Some of the most relevant packages of Julia use macros in their syntax, and they cannot be used in Pluto, which was developed for Julia. Something is not right here.

Macro support was much improved recently in Pluto so if you are basing your statements on older posts (maybe by me even) then that information may be out of date.

Can you make a MWE and either make a new post on discourse or make an issue with Pluto?

I think there hasn’t been a Pluto release yet since https://github.com/fonsp/Pluto.jl/pull/1032 was merged, so to try it out one needs to use the main branch instead of the latest release.

4 Likes

Let me frame my problem under a particular context. I had 12 notebooks to migrate into Pluto, which looked fantastic to my teaching duties. I migrated 11 of them: the last one was: optimization. Bang. Could I imagine that the JuMP package can not work inside Pluto? No! How is this possible?

The MWE is an undergraduate optimization problem. I use Pluto v0.15.1, PlutoUI v0.7.9, Julia 1.62, and the problem below runs on VSCode, Atom, and Jupyter.

MWE:

begin
	m1 = Model(Ipopt.Optimizer)
	@variable(m1, z1)
	@variable(m1, z2)
	@variable(m1, z3)

	@objective(m1, Min, z1^2 + 0.5*z2^2 + 0.4*z3^2)

	@constraint(m1, cons1b, 0.5*z1 + z2 == 10)
	@constraint(m1, cons1c, 0.5*z1 + z3 == 20)
end

The error that pops up is:

cannot assign a value to variable workspace5.z1 from module workspace11

	1. macro expansion    @   macros.jl:149[inlined]
	2. top-level scope    @   Local: 3

1 Like

I tried my small optimization problem with Neptune, and there was no problem with the JuMP macros. It worked. That is fine, but I had preferred to have it done with Pluto. Why not a little bit of good common sense. Being flexible is a sign of wisdom, not the opposite. Nothing is pure, immutable in this world. No idea is “pure”, unchangeable.

1 Like

Indeed. Neptune.jl is very useful in many cases for data analysis, optimization, data processing, etc…
I wish it got more attention from the community as it has many advantages over Pluto.jl (Which is amazing).

Have you tried it with Pluto#main, as @ericphanson suggested?
If you still encounter problems there, please fill an issue at https://github.com/fonsp/Pluto.jl

6 Likes

@VivMendes

As @ericphanson suggested, it seems that adding the main branch of Pluto (you can do so by putting the full github url of Pluto instead of just Pluto when adding the package) that conatins the macro support recently added to the repo fixes your problem:

I have no clue about JuMP but tried simply pasting your code so I don’t know if you were getting the error after doing something more advanced.

The new macro analysis capability is quite neat and I am sure that a new version of Pluto including this will get merged soon, probably when @fonsp comes back from holidays

9 Likes

Hi @disberd,

As usual, you know how to talk to a computing moron. I did as you mentioned, and now I can solve the optimization problem using JuMP inside Pluto.

Usually, there are three steps to go through using JuMP. The first is to set up the model and print it out: Print(m1), in this example. There is no problem here; Pluto displays the output correctly:

Min x1² + 0.5 x2² + 0.4 x3²
Subject to
 cons1b : 0.5 x1 + x2 == 10.0
 cons1c : 0.5 x1 + x3 == 20.0

The second is to display the properties of the solution that was found (not found). When we run optimize!(m1), in VScode, Atom, or Jupyter the following information pops up automatically:

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

This is Ipopt version 3.13.4, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation). 

Number of nonzeros in equality constraint Jacobian...:        4
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:        3

Total number of variables............................:        3
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        2
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  0.0000000e+00 2.00e+01 0.00e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  1.7551020e+02 0.00e+00 0.00e+00  -1.0 1.73e+01    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 1

                                   (scaled)                 (unscaled)
Objective...............:   1.7551020408163265e+02    1.7551020408163265e+02
Dual infeasibility......:   0.0000000000000000e+00    0.0000000000000000e+00
Constraint violation....:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   0.0000000000000000e+00    0.0000000000000000e+00


Number of objective function evaluations             = 2
Number of objective gradient evaluations             = 2
Number of equality constraint evaluations            = 2
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 1
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 1
Total CPU secs in IPOPT (w/o function evaluations)   =      0.237
Total CPU secs in NLP function evaluations           =      0.104

EXIT: Optimal Solution Found.

However, to get this information in Pluto, I had to resort to the terminal:

with_terminal() do
		optimize!(m1)
end

The third is to display the model’s output, which consists of 6 elements in this case:

Objective value: 175.51020408163265
x1 = 5.3061224489795915
x2 = 7.346938775510204
x3 = 17.346938775510203
Lagrangian Multiplier for constraint (1b) = 7.346938775510204
Lagrangian Multiplier for constraint (1c) = 13.877551020408163

Again I had to resort to the terminal to get a table-like display:

with_terminal() do
		println("Objective value = ", objective_value(m1))	
		println("z1 = ", getvalue(z1))	
		println("z2 = ", getvalue(z2))	
		println("z3 = ", getvalue(z3))	
		println("Lagrangian Multiplier for constraint (1b) = ", getdual(cons1b))	
		println("Lagrangian Multiplier for constraint (1c) = ", getdual(cons1c))
end

@disberd, thanks. Now, I can finish my set of Pluto notebooks. In this migration process, you started helping me by providing a solution to integrate PlotlyJS into Pluto and sorting out small obstacles that appeared along the way. It works immaculately. Then, you finished it with JuMP. I owe you a lot. Thank you very, very much.

11 Likes

It doesn’t work.

What doesn’t work? Can you be more precise? The comment about using Jump in Pluto above? [as opposed to Neptune]
If there is an issue with Neptune (which is what this thread is about) you should post it on the repo.

Sorry, I was replying to the above. When I select my notebook in the list of recent files, there’s an error saying the file can’t be opened. If I omit run_notebook_on_load=true, the notebook opens correctly.

ps: thank you for Neptune!

This would be awesome. Is this something already merged onto the latest Pluto release? Not sure if I understood the workaround.
Instead of adding
(@v1.7) pkg> add Pluto
, if we do
(@v1.7) pkg> add GitHub - fonsp/Pluto.jl: 🎈 Simple reactive notebooks for Julia
we can use the macro?

The macro analysis feature has been released some time ago, thus it is sufficient to do ] add Pluto now.

2 Likes

How hard will it be to merge the current code of Pluto.jl into the current Neptune.jl with keeping the static linear model of Neptune.jl?

3 Likes

From a quick look, I think it would be much easier to start with the current head of pluto and just port these three commits below.

The other commits in current neptune are pretty much superficial s/Pluto/Neptune changes, which seems like a maintenance nightmare.

(I’m not volunteering since I love reactive mode, but others might wanna give it a shot, should not take very much code at all to disable reactive mode)

3 Likes

I wish a sequential, non reactive was just a mode of operation of Pluto.jl.
@compleat , Any chance to do as suggested by @sashmit ?

6 Likes

This sounds a great idea. I am not sure how to do this without risk of breaking things, but once I figure out how, I will do this. I know you said you didn’t want to get involved, but if (as it seems) this is simple and you are willing to do it, I am happy to authorise you if you are willing to do this one bit.

4 Likes