Issue with ModelingToolkit in Pluto

I get the following error for initialising variables. the code runs fine in the terminal and in vscode using the same Julia instance.

Any ideas what this could be?

1 Like

I don’t know. I’ll need @fonsp to help. It should work in any standard REPL or IDE, so Pluto must be changing the semantics of the global scope a bit.

1 Like

Is this related to the lack of the interactive scoping of Pluto? Ie it is not consistent with the REPL/vscode inline/jupyter.

1 Like

This is due to the way Pluto handles running new cells. I think your issue is similar to Not escaping in macro definition gives confusing error · Issue #1112 · fonsp/Pluto.jl · GitHub

Note: I am working on adding support for Macros inside Pluto, if you want to try it see WIP: Analyse macros by Pangoraw · Pull Request #1032 · fonsp/Pluto.jl · GitHub

1 Like

It will probably work if you don’t use the macros. Pluto can’t see the assignments that are accomplished by the macros.

EDIT: See Macros and DSLs · Issue #196 · fonsp/Pluto.jl · GitHub. It may be worth making a specific new issue to see if someone can do some special case code for these macros.

2 Likes

Ok, this makes sense. Can I define the variables without the macro and still use the ModellingToolkit features?

1 Like

Also, the code above works in Neptune (non-reactive version of Pluto). Good to know for these special cases. I am very fond of working in Pluto…

1 Like

I think it should work and I think the MTK docs have examples without macros (but they are a lot wordier). Pluto also can’t track mutation, so if you make an object and then mutate it, you probably want to do both of those operations in one cell. A task in which the mutation can’t be contained in that way probably isn’t a fit for Pluto.

1 Like

yes, actually just doing

begin 
	@parameters t σ ρ β
	@variables x(t) y(t) z(t)	
end

makes it work in Pluto. Nice!

But also, does anyone know how to get the Latex rendered?

1 Like

This solution worked for me:

1 Like

nice, thanks!