MTK & Linearization

I never use Jupyter notebooks so I cannot really help you there. linearize_symbolic is not exported, so you’d have to call it using ModelingToolkit.linearize_symbolic

When you activate a temp environment in the REPL that is not carried over to the notebook.

IJulia notebooks support REPL mode though, so you can do ] activate --temp in a notebook cell.

1 Like

You can call it programatically through Pkg, though it will have a little different syntax compared to the pkg mode.

From the docstring we see that Pkg.activate(temp=true) is one way to activate a temp environment.

help?> Pkg.activate
  Pkg.activate([s::String]; shared::Bool=false, io::IO=stderr)
  Pkg.activate(; temp::Bool=false, shared::Bool=false, io::IO=stderr)


  Activate the environment at s. The active environment is the environment that is modified
  by executing package commands. The logic for what path is activated is as follows:

    •  If shared is true, the first existing environment named s from the depots in the
       depot stack will be activated. If no such environment exists, create and
       activate that environment in the first depot.

    •  If temp is true this will create and activate a temporary environment which will
       be deleted when the julia process is exited.

    •  If s is an existing path, then activate the environment at that path.

    •  If s is a package in the current project and s is tracking a path, then activate
       the environment at the tracked path.

    •  Otherwise, s is interpreted as a non-existing path, which is then activated.

  If no argument is given to activate, then activate the home project. The home project is
  specified by either the --project command line option to the julia executable, or the
  JULIA_PROJECT environment variable.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  Pkg.activate()
  Pkg.activate("local/path")
  Pkg.activate("MyDependency")
  Pkg.activate(; temp=true)
1 Like

That’s what I did.

Thanks!

How can I then add the master version of ModelingToolkit?

Pkg.add("ModelingToolkit#master")

does not work.

Command line version is:

pkg>  add ModelingToolkit#master

As I said, you can just use the REPL mode in Jupyter by starting your cell with ].

If you want to use the functional API check the docs:

help?> Pkg.add
(...)
  Pkg.add(name="Example", version="0.3") # Specify version; latest release in the 0.3 series
  Pkg.add(name="Example", version="0.3.1") # Specify version; exact release
  Pkg.add(url="https://github.com/JuliaLang/Example.jl", rev="master") # From url to remote gitrepo
2 Likes

OK – some bugs in linearize_partial_model, in addition to relying on an ODESystem model which may have equations and variables auto-removed.

I fixed the code by (i) making it based purely on the equation vector (for which I have full control), and (ii) fixing the bug. The new function is named linearize_symbolic_dae01 (indicating that it only works for DAEs of index 0 or 1) + a helper function to pick out the variables and parameters from equation (get_symbols).

I can make the code available on request, but won’t take up more space here now.