Skip to content

LinearAlgebra.norm {sum?} fails after 9.72.0 with vectors #3662

Closed
@RobbesU

Description

@RobbesU

Describe the example

My 3D-bodies system worked fine under 9.72.
Upgraded last week (9.79 at the time, currently 9.80) and got two distinct failure messages.

  • during the @named get error "Failed to show value: cannot latexify objects of type Pair{Symbol, Bool}" (despite output being suppressed with ";")
  • during the structural_simplify now getting an "ExtraVariablesSystemException: The system is unbalanced."

I eventually traced it to the use of LinearAlgebra.norm() in Equations (to get length of vectors), and splitting that out into its components shows it also fails using sum().

Loading specific versions it appears the error started in 9.73

FWIW: I'm working in Pluto notebook.

Minimal Reproducible Example 👇

using ModelingToolkit          # reexports e.g. Symbolics
using LinearAlgebra: LinearAlgebra as LA
using ModelingToolkit: t_nounits as t, D_nounits as D

@component function MWE(;name, l0=1.0)
	
	pars = @parameters begin
        l0=l0, [description = "Spring length at rest in [m]"]
	end
	
	vars = @variables begin
                 l(t),        [description = "Spring length in [m]"]
		Δl(t),       [description = "Spring strech [m/]"]

		l3_sq(t)[1:3]   # purely for MWE
		s2_mwe(t)[1:3]  # purely for MWE, pos vector normally comes from Flange.s
	end

	
	eqs = [
		collect( s2_mwe .~ [sin(t), 0.0, 0.0])...
		
		l ~ LA.norm(s2_mwe )  # "Failed to show value: cannot latexify objects of type Pair{Symbol, Bool}"
		#collect(l3_sq .~ (s2_mwe).^2)...   # This works !
		
		#l  ~ sum(l3_sq) # "Failed to show value: cannot latexify objects of type Pair{Symbol, Bool}"
		l ~ l3_sq[1] + l3_sq[2] + l3_sq[3]  # This works
		#l ~ l3_sq[1]+l3_sq[2]+l3_sq[3]  # This works
		#l ~ l3_sq[1] +l3_sq[2] +l3_sq[3]  # Fails: "DimensionMismatch: number of columns of each array must match (got (3, 3, 3, 1))"
		
		Δl ~ (l - l0)
		
	]
	ODESystem(eqs, t, vars, pars; name)
end

@named mwe_sys0 = MWE(l0=1.0)

mwe_sys = structural_simplify(mwe_sys0)  

Error & Stacktrace ⚠️

Error message from Latexify

Failed to show value: 

cannot latexify objects of type Pair{Symbol, Bool}
Stack trace

Here is what happened, the most recent locations are first:

    #_latexraw#45(args::Pair{…}; kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
    from 
    Latexify  latexraw.jl:110
    #process_latexify#166(args::Pair{…}; kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
    from 
    Latexify  latexify_function.jl:49
    process_latexify
    from 
    latexify_function.jl:40
    latexraw
    from 
    latexraw.jl:58
    #_latexarray#75(arr::Vector{…}; adjustment::Symbol, transpose::Bool, double_linebreak::Bool, starred::Bool, arraystyle::Symbol, kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
    from 
    Latexify  latexarray.jl:57
    _latexarray
    from 
    latexarray.jl:17
    #_latexarray#81
    from 
    latexarray.jl:79
    _latexarray
    from 
    latexarray.jl:75
    #_latexraw#46
    from 
    latexraw.jl:113
    #process_latexify#166(args::Tuple{…}; kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
    from 
    Latexify  latexify_function.jl:49
    process_latexify
    from 
    latexify_function.jl:40
    latexraw
    from 
    latexraw.jl:58
    anonymous function(i::Tuple{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
    from 
    Latexify  latexoperation.jl:27
    iterate
    from 
    generator.jl:48
    collect_to!(dest::Vector{…}, itr::Base.Generator{…}, offs::Int64, st::Int64) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
    from 
    [julia  array.jl:849](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/array.jl#L844)
     

collect_to!(dest::Vector{…}, itr::Base.Generator{…}, offs::Int64, st::Int64) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  array.jl:857](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/array.jl#L844)
 
collect_to_with_first!(dest::Vector{…}, v1::LaTeXStrings.LaTeXString, itr::Base.Generator{…}, st::Int64) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  array.jl:827](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/array.jl#L824)
 
_collect(c::Vector{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  array.jl:821](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/array.jl#L808)
 
collect_similar
from 
array.jl:720
map
from 
abstractarray.jl:3371
#latexoperation#62(ex::Expr, prevOp::Vector{…}; kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexoperation.jl:27
latexoperation
from 
latexoperation.jl:9
recurseexp!(ex::Expr) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexraw.jl:97
recurseexp!(ex::Expr) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexraw.jl:92
#_latexraw#41(inputex::Expr; convert_unicode::Bool, kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexraw.jl:101
#process_latexify#166(args::Symbolics.Num; kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexify_function.jl:49
process_latexify
from 
latexify_function.jl:40
latexraw
from 
latexraw.jl:58
anonymous function
from 
broadcast.jl:1311
_broadcast_getindex_evalf
from 
broadcast.jl:678
_broadcast_getindex
from 
broadcast.jl:651
getindex
from 
broadcast.jl:610
copyto_nonleaf!(dest::Matrix{…}, bc::Base.Broadcast.Broadcasted{…}, iter::CartesianIndices{…}, state::CartesianIndex{…}, count::Int64) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  broadcast.jl:1082](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/broadcast.jl#L1076)
 
restart_copyto_nonleaf!(newdest::Matrix{…}, dest::Matrix{…}, bc::Base.Broadcast.Broadcasted{…}, val::String, I::CartesianIndex{…}, iter::CartesianIndices{…}, state::CartesianIndex{…}, count::Int64) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  broadcast.jl:1073](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/broadcast.jl#L1067)
 
copyto_nonleaf!(dest::Matrix{…}, bc::Base.Broadcast.Broadcasted{…}, iter::CartesianIndices{…}, state::CartesianIndex{…}, count::Int64) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  broadcast.jl:1089](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/broadcast.jl#L1076)
 
copy
from 
broadcast.jl:919
materialize
from 
broadcast.jl:872
#_latexalign#85(arr::Matrix{…}; separator::String, double_linebreak::Bool, starred::Bool, rows::Symbol, aligned::Bool, kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexalign.jl:46
#process_latexify#166(args::Matrix{…}; kwargs::@Kwargs{…}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexify_function.jl:49
process_latexify
from 
latexify_function.jl:40
latexalign
from 
latexalign.jl:42
#_latexalign#91
from 
latexalign.jl:87
#process_latexify#166(args::Vector{…}; kwargs::@Kwargs{}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexify_function.jl:49
process_latexify
from 
latexify_function.jl:40
#latexify#165(args::Vector{…}; kwargs::@Kwargs{}) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
Latexify  latexify_function.jl:27
latexify
from 
latexify_function.jl:25
macro expansion
from 
abstractsystem.jl:2581
#apply_recipe#392
from 
recipes.jl:174
apply_recipe
from 
recipes.jl:168
process_latexify(args::ModelingToolkit.ODESystem; kwargs::@Kwargs{})
from 
Latexify  latexify_function.jl:42
process_latexify
from 
latexify_function.jl:40
latexify(args::ModelingToolkit.ODESystem; kwargs::@Kwargs{})
from 
Latexify  latexify_function.jl:27
latexify
from 
latexify_function.jl:25
show(io::IOBuffer, ::MIME{…}, x::ModelingToolkit.ODESystem) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
ModelingToolkit  abstractsystem.jl:2585
__binrepr(m::MIME{…}, x::ModelingToolkit.ODESystem, context::Nothing) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  multimedia.jl:171](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/multimedia.jl#L168)
 
#repr#1(m::MIME{…}, x::ModelingToolkit.ODESystem; context::Nothing) [...show types...](http://localhost:1234/edit?id=10b2c9e0-3a07-11f0-0d80-cf0133a16f49#)
from 
[julia  multimedia.jl:159](https://github.com/JuliaLang/julia/tree/760b2e5b7396f9cc0da5efce0cadd5d1974c4069/base/multimedia.jl#L159)

Not Working Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
  Activating project at `C:\Users\robur\OneDrive\Documents\Projects\pluto_notebooks\Notebooks_MTK\Env_MTK`
Status `C:\Users\robur\OneDrive\Documents\Projects\pluto_notebooks\Notebooks_MTK\Env_MTK\Project.toml`
  [5ae59095] Colors v0.13.1
  [a93c6f00] DataFrames v1.7.0
  [82cc6244] DataInterpolations v8.0.1
  [864edb3b] DataStructures v0.18.22
  [0c46a032] DifferentialEquations v7.16.1
⌅ [f6369f11] ForwardDiff v0.10.38
  [f7f18e0c] GLFW v3.4.4
  [e9467ef8] GLMakie v0.11.8
  [5c1252a2] GeometryBasics v0.5.9
  [b964fa9f] LaTeXStrings v1.4.0
  [961ee093] ModelingToolkit v9.80.1
  [16a59e39] ModelingToolkitStandardLibrary v2.21.1
  [1dea7af3] OrdinaryDiffEq v6.97.0
  [127b3ac7] OrdinaryDiffEqNonlinearSolve v1.9.0
  [91a5bcdd] Plots v1.40.13
  [7f904dfe] PlutoUI v0.7.62
  [94ee1d12] Quaternions v0.7.6
  [6038ab10] Rotations v1.7.1
  [0bca4576] SciMLBase v2.95.0
  [5c889d49] SkewLinearAlgebra v1.0.0
  [90137ffa] StaticArrays v1.9.13
  [10745b16] Statistics v1.11.1
  [37e2e46d] LinearAlgebra v1.11.0
  [de0858da] Printf v1.11.0
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`
  • Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
❔

Status `C:\Users\robur\OneDrive\Documents\Projects\pluto_notebooks\Notebooks_MTK\Env_MTK\Manifest.toml`
⌅ [3da002f7] ColorTypes v0.11.5 (<v0.12.1): ColorVectorSpace, PlutoUI
⌃ [c3611d14] ColorVectorSpace v0.10.0 (<v0.11.0)
⌅ [a0c0ee7d] DifferentiationInterface v0.6.54 (<v0.7.0): BoundaryValueDiffEqAscher, BoundaryValueDiffEqFIRK, BoundaryValueDiffEqMIRK, BoundaryValueDiffEqMIRKN, BoundaryValueDiffEqShooting, ModelingToolkit, NLSolversBase, OrdinaryDiffEqDifferentiation, OrdinaryDiffEqRosenbrock
⌅ [8fc22ac5] FilePaths v0.8.3 (<v0.9.0): Makie
⌅ [f6369f11] ForwardDiff v0.10.38 (<v1.0.1): DataInterpolations, ModelingToolkit, OrdinaryDiffEq, OrdinaryDiffEqDifferentiation, OrdinaryDiffEqNonlinearSolve, OrdinaryDiffEqRosenbrock
⌅ [a98d9a8b] Interpolations v0.15.1 (<v0.16.1): KernelDensity, Makie
⌅ [70703baa] JuliaSyntax v0.4.10 (<v1.0.2): JuliaFormatter
⌅ [aea7be01] PrecompileTools v1.2.1 (<v1.3.2): julia
⌅ [c0aeaf25] SciMLOperators v0.4.0 (<v1.3.0): NonlinearSolveBase, NonlinearSolveQuasiNewton, SciMLJacobianOperators, SparseDiffTools
⌃ [83423d85] Cairo_jll v1.18.4+0 (<v1.18.5+0)
⌅ [b22a6f82] FFMPEG_jll v4.4.4+1 (<v7.1.0+0): FFMPEG, Makie
⌃ [7746bdde] Glib_jll v2.82.4+0 (<v2.84.0+0)
⌅ [e9f186c6] Libffi_jll v3.2.2+2 (<v3.4.7+0): Glib_jll, HarfBuzz_jll, Wayland_jll
⌅ [30392449] Pixman_jll v0.44.2+0 (<v0.46.0+0): Cairo_jll
⌅ [fb77eaff] Sundials_jll v5.2.3+0 (<v6.6.0+0): Sundials
⌃ [a2964d1f] Wayland_jll v1.21.0+2 (<v1.23.1+0)
⌅ [02c8fc9c] XML2_jll v2.13.6+1 (<v2.14.1+0): Gettext_jll, Wayland_jll
⌅ [1270edf5] x264_jll v2021.5.5+0 (<v10164.0.1+0): FFMPEG_jll
⌅ [dfaa095f] x265_jll v3.5.0+0 (<v4.1.0+0): FFMPEG_jll

  • Output of versioninfo()
❔

Julia Version 1.11.5
Commit 760b2e5b73 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)
Threads: 4 default, 0 interactive, 2 GC (on 8 virtual cores)
Environment:
  JULIA_REVISE_WORKER_ONLY = 1

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions