SciML / Catalyst.jl

Chemical reaction network and systems biology interface for scientific machine learning (SciML). High performance, GPU-parallelized, and O(1) solvers in open source software.
https://docs.sciml.ai/Catalyst/stable/
Other
464 stars 78 forks source link

latex display errors with equation in reaction rate #473

Closed fonsp closed 2 years ago

fonsp commented 2 years ago
julia> using Catalyst

julia> rn = @reaction_network begin
         k, Y --> ∅
       end k
Model ##ReactionSystem#275 with 1 equations
States (1):
  Y(t)
Parameters (1):
  k

julia> repr(MIME"text/latex"(), rn)
"\\begin{align}\n\\require{mhchem}\n\\ce{ Y &->[k] \\varnothing}\n\\end{align}\n"

julia> rn = @reaction_network begin
         k*Y, Y --> ∅
       end k
Model ##ReactionSystem#274 with 1 equations
States (1):
  Y(t)
Parameters (1):
  k

julia> repr(MIME"text/latex"(), rn)
ERROR: MethodError: no method matching ^(::Sym{SymbolicUtils.FnType{Tuple{Any}, Real}, Nothing}, ::Int64)
Closest candidates are:
  ^(::Union{AbstractChar, AbstractString}, ::Integer) at /Applications/Julia-1.7 M1.app/Contents/Resources/julia/share/julia/base/strings/basic.jl:721
  ^(::Union{AbstractAlgebra.Generic.PuiseuxSeriesFieldElem{T}, AbstractAlgebra.Generic.PuiseuxSeriesRingElem{T}}, ::Int64) where T<:AbstractAlgebra.RingElement at ~/.julia/packages/AbstractAlgebra/KPT2D/src/generic/PuiseuxSeries.jl:509
  ^(::Union{AbstractAlgebra.Generic.LaurentSeriesFieldElem{T}, AbstractAlgebra.Generic.LaurentSeriesRingElem{T}}, ::Int64) where T<:AbstractAlgebra.RingElement at ~/.julia/packages/AbstractAlgebra/KPT2D/src/generic/LaurentSeries.jl:853
  ...
Stacktrace:
  [1] unstable_pow(a::Sym{SymbolicUtils.FnType{Tuple{Any}, Real}, Nothing}, b::Int64)
    @ SymbolicUtils ~/.julia/packages/SymbolicUtils/v2ZkM/src/types.jl:801
  [2] (::SymbolicUtils.var"#44#45")(::Pair{Any, Number})
    @ SymbolicUtils ./none:0
  [3] iterate
    @ ./generator.jl:47 [inlined]
  [4] collect(itr::Base.Generator{Dict{Any, Number}, SymbolicUtils.var"#44#45"})
    @ Base ./array.jl:724
  [5] arguments(a::SymbolicUtils.Mul{Real, Int64, Dict{Any, Number}, Nothing})
    @ SymbolicUtils ~/.julia/packages/SymbolicUtils/v2ZkM/src/types.jl:810
  [6] function_to_expr(op::typeof(*), O::SymbolicUtils.Mul{Real, Int64, Dict{Any, Number}, Nothing}, st::SymbolicUtils.Code.LazyState)
    @ SymbolicUtils.Code ~/.julia/packages/SymbolicUtils/v2ZkM/src/code.jl:110
  [7] toexpr(O::SymbolicUtils.Mul{Real, Int64, Dict{Any, Number}, Nothing}, st::SymbolicUtils.Code.LazyState)
    @ SymbolicUtils.Code ~/.julia/packages/SymbolicUtils/v2ZkM/src/code.jl:157
  [8] toexpr(x::SymbolicUtils.Mul{Real, Int64, Dict{Any, Number}, Nothing})
    @ SymbolicUtils.Code ~/.julia/packages/SymbolicUtils/v2ZkM/src/code.jl:77
  [9] chemical_arrows(rn::WARNING: both Symbolics and ModelingToolkit export "degree"; uses of it in module Catalyst must be qualified
WARNING: both Symbolics and ModelingToolkit export "infimum"; uses of it in module Catalyst must be qualified
WARNING: both Symbolics and ModelingToolkit export "supremum"; uses of it in module Catalyst must be qualified
ReactionSystem{Nothing}; expand::Bool, double_linebreak::Bool, mathjax::Bool, starred::Bool, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:cdot, :env), Tuple{Bool, Symbol}}})
    @ Catalyst ~/.julia/packages/Catalyst/E8uTL/src/latexify_recipes.jl:88
 [10] process_latexify(args::ReactionSystem{Nothing}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Latexify ~/.julia/packages/Latexify/Kg8HA/src/latexify_function.jl:25
 [11] process_latexify
    @ ~/.julia/packages/Latexify/Kg8HA/src/latexify_function.jl:18 [inlined]
 [12] latexify(args::ReactionSystem{Nothing}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Latexify ~/.julia/packages/Latexify/Kg8HA/src/latexify_function.jl:3
 [13] latexify
    @ ./iobuffer.jl:0 [inlined]
 [14] repr(m::MIME{Symbol("text/latex")}, x::ReactionSystem{Nothing}; context::Nothing)
    @ Base.Multimedia ./multimedia.jl:147
 [15] repr(m::MIME{Symbol("text/latex")}, x::ReactionSystem{Nothing})
    @ Base.Multimedia ./multimedia.jl:147
 [16] top-level scope
    @ REPL[5]:1

Versions

Details ``` (@v1.7) pkg> activate --temp Activating new project at `/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_QM1HKS` (jl_QM1HKS) pkg> add Catalyst Updating registry at `~/.julia/registries/General.toml` Resolving package versions... Installed StatsFuns ──────────────────────── v0.9.15 Installed RecursiveArrayTools ────────────── v2.24.1 Installed Polyester ──────────────────────── v0.6.3 Installed DiffEqBase ─────────────────────── v6.81.3 Installed LinearSolve ────────────────────── v1.11.1 Installed TimerOutputs ───────────────────── v0.5.15 Installed SciMLBase ──────────────────────── v1.26.1 Installed SpecialFunctions ───────────────── v2.1.0 Installed ExprTools ──────────────────────── v0.1.8 Installed NaNMath ────────────────────────── v0.3.7 Installed DynamicPolynomials ─────────────── v0.4.3 Installed BitTwiddlingConvenienceFunctions ─ v0.1.2 Installed LayoutPointers ─────────────────── v0.1.5 Installed DiffRules ──────────────────────── v1.9.1 Installed Catalyst ───────────────────────── v10.4.2 Installed ModelingToolkit ────────────────── v8.3.2 Installed PolyesterWeave ─────────────────── v0.1.3 Installed CPUSummary ─────────────────────── v0.1.7 Installed VectorizationBase ──────────────── v0.21.24 Installed JLLWrappers ────────────────────── v1.4.1 Installed Krylov ─────────────────────────── v0.7.11 Installed ChainRulesCore ─────────────────── v1.12.0 Installed Transducers ────────────────────── v0.4.69 Installed OrdinaryDiffEq ─────────────────── v6.6.5 Installed HostCPUFeatures ────────────────── v0.1.6 Installed RecursiveFactorization ─────────── v0.2.9 Installed SymbolicUtils ──────────────────── v0.19.7 Installed Distributions ──────────────────── v0.25.45 Updating `/private/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_QM1HKS/Project.toml` [479239e8] + Catalyst v10.4.2 Updating `/private/var/folders/v_/fhpj9jn151d4p9c2fdw2gv780000gn/T/jl_QM1HKS/Manifest.toml` [c3fe647b] + AbstractAlgebra v0.23.0 [1520ce14] + AbstractTrees v0.3.4 [79e6a3ab] + Adapt v3.3.3 [dce04be8] + ArgCheck v2.1.0 [ec485272] + ArnoldiMethod v0.2.0 [4fba245c] + ArrayInterface v3.2.2 [15f4f7f2] + AutoHashEquals v0.2.0 [198e06fe] + BangBang v0.3.34 [9718e550] + Baselet v0.1.1 [e2ed5e7c] + Bijections v0.1.3 [62783981] + BitTwiddlingConvenienceFunctions v0.1.2 [2a0fbf3d] + CPUSummary v0.1.7 [00ebfdb7] + CSTParser v3.3.0 [479239e8] + Catalyst v10.4.2 [d360d2e6] + ChainRulesCore v1.12.0 [9e997f8a] + ChangesOfVariables v0.1.2 [fb6a15b2] + CloseOpenIntervals v0.1.4 [861a8166] + Combinatorics v1.0.2 [a80b9123] + CommonMark v0.8.5 [38540f10] + CommonSolve v0.2.0 [bbf7d656] + CommonSubexpressions v0.3.0 [34da2185] + Compat v3.41.0 [b152e2b5] + CompositeTypes v0.1.2 [a33af91c] + CompositionsBase v0.1.1 [187b0558] + ConstructionBase v1.3.0 [a8cc5b0e] + Crayons v4.1.1 [754358af] + DEDataArrays v0.2.0 [9a962f9c] + DataAPI v1.9.0 [864edb3b] + DataStructures v0.18.11 [e2d170a0] + DataValueInterfaces v1.0.0 [244e2a9f] + DefineSingletons v0.1.2 [b429d917] + DensityInterface v0.4.0 [2b5f629d] + DiffEqBase v6.81.3 [459566f4] + DiffEqCallbacks v2.20.1 [c894b116] + DiffEqJump v8.1.0 [163ba53b] + DiffResults v1.0.3 [b552c78f] + DiffRules v1.9.1 [b4f34e82] + Distances v0.10.7 [31c24e10] + Distributions v0.25.45 [ffbed154] + DocStringExtensions v0.8.6 [5b8099bc] + DomainSets v0.5.9 [7c1d4256] + DynamicPolynomials v0.4.3 [da5c29d0] + EllipsisNotation v1.3.0 [d4d017d3] + ExponentialUtilities v1.11.0 [e2ba6199] + ExprTools v0.1.8 [7034ab61] + FastBroadcast v0.1.12 [9aa1b823] + FastClosures v0.3.2 [1a297f60] + FillArrays v0.12.7 [6a86dc24] + FiniteDiff v2.10.0 [59287772] + Formatting v0.4.2 [f6369f11] + ForwardDiff v0.10.25 [069b7b12] + FunctionWrappers v1.1.2 [86223c79] + Graphs v1.5.1 [d5909c97] + GroupsCore v0.4.0 [3e5b6fbb] + HostCPUFeatures v0.1.6 [0e44f5e4] + Hwloc v2.0.0 [615f187c] + IfElse v0.1.1 [d25df0c9] + Inflate v0.1.2 [22cec73e] + InitialValues v0.3.1 [8197267c] + IntervalSets v0.5.3 [3587e190] + InverseFunctions v0.1.2 [92d709cd] + IrrationalConstants v0.1.1 [42fd0dbc] + IterativeSolvers v0.9.2 [82899510] + IteratorInterfaceExtensions v1.0.0 [692b3bcd] + JLLWrappers v1.4.1 [682c06a0] + JSON v0.21.2 [98e50ef6] + JuliaFormatter v0.21.2 [ef3ab10e] + KLU v0.2.3 [ba0b0d4f] + Krylov v0.7.11 [0b1a1467] + KrylovKit v0.5.3 [b964fa9f] + LaTeXStrings v1.3.0 [2ee39098] + LabelledArrays v1.7.0 [23fbe1c1] + Latexify v0.15.9 [10f19ff3] + LayoutPointers v0.1.5 [d3d80556] + LineSearches v7.1.1 [7ed4a6bd] + LinearSolve v1.11.1 [2ab3a3ac] + LogExpFunctions v0.3.6 [bdcacae8] + LoopVectorization v0.12.101 [1914dd2f] + MacroTools v0.5.9 [d125e4d3] + ManualMemory v0.1.6 [e9d8d322] + Metatheory v1.3.3 [128add7d] + MicroCollections v0.1.2 [e1d29d7a] + Missings v1.0.2 [961ee093] + ModelingToolkit v8.3.2 [46d2c3a1] + MuladdMacro v0.2.2 [102ac46a] + MultivariatePolynomials v0.4.2 [d8a4904e] + MutableArithmetics v0.3.2 [d41bc354] + NLSolversBase v7.8.2 [2774e3e8] + NLsolve v4.5.1 [77ba4419] + NaNMath v0.3.7 [8913a72c] + NonlinearSolve v0.3.14 [6fe1bfb0] + OffsetArrays v1.10.8 [bac558e1] + OrderedCollections v1.4.1 [1dea7af3] + OrdinaryDiffEq v6.6.5 [90014a1f] + PDMats v0.11.5 [d96e819e] + Parameters v0.12.3 [69de0a69] + Parsers v2.2.1 [e409e4f3] + PoissonRandom v0.4.0 [f517fe37] + Polyester v0.6.3 [1d0040c9] + PolyesterWeave v0.1.3 [d236fae5] + PreallocationTools v0.2.3 [21216c6a] + Preferences v1.2.3 [1fd47b50] + QuadGK v2.4.2 [fb686558] + RandomExtensions v0.4.3 [e6cf234a] + RandomNumbers v1.5.3 [3cdcf5f2] + RecipesBase v1.2.1 [731186ca] + RecursiveArrayTools v2.24.1 [f2c3362d] + RecursiveFactorization v0.2.9 [189a3867] + Reexport v1.2.2 [42d2dcc6] + Referenceables v0.1.2 [ae029012] + Requires v1.3.0 [79098fc4] + Rmath v0.7.0 [7e49a35a] + RuntimeGeneratedFunctions v0.5.3 [3cdde19b] + SIMDDualNumbers v0.1.0 [94e857df] + SIMDTypes v0.1.0 [476501e8] + SLEEFPirates v0.6.28 [1bc83da4] + SafeTestsets v0.0.1 [0bca4576] + SciMLBase v1.26.1 [efcf1570] + Setfield v0.8.1 [699a6c99] + SimpleTraits v0.9.4 [a2af1166] + SortingAlgorithms v1.0.1 [47a9eef4] + SparseDiffTools v1.20.0 [276daf66] + SpecialFunctions v2.1.0 [171d559e] + SplittablesBase v0.1.14 [aedffcd0] + Static v0.4.1 [90137ffa] + StaticArrays v1.3.3 [82ae8749] + StatsAPI v1.2.0 [2913bbd2] + StatsBase v0.33.14 [4c63d2b9] + StatsFuns v0.9.15 [7792a7ef] + StrideArraysCore v0.2.9 [d1185830] + SymbolicUtils v0.19.7 [0c5d862f] + Symbolics v4.3.0 [3783bdb8] + TableTraits v1.0.1 [bd369af6] + Tables v1.6.1 [8ea1fca8] + TermInterface v0.2.3 [8290d209] + ThreadingUtilities v0.4.7 [ac1d9e8a] + ThreadsX v0.1.9 [a759f4b9] + TimerOutputs v0.5.15 [0796e94c] + Tokenize v0.5.21 [28d57a85] + Transducers v0.4.69 [a2a6695c] + TreeViews v0.3.0 [d5829a12] + TriangularSolve v0.1.9 [5c2747f8] + URIs v1.3.0 [3a884ed6] + UnPack v1.0.2 [1986cc42] + Unitful v1.10.1 [3d5dd08c] + VectorizationBase v0.21.24 [19fa3120] + VertexSafeGraphs v0.2.0 [700de1a5] + ZygoteRules v0.2.2 [e33a78d0] + Hwloc_jll v2.7.0+0 [efe28fd5] + OpenSpecFun_jll v0.5.5+0 [f50d1b31] + Rmath_jll v0.3.0+0 [0dad84c5] + ArgTools [56f22d72] + Artifacts [2a0f44e3] + Base64 [ade2ca70] + Dates [8bb1440f] + DelimitedFiles [8ba89e20] + Distributed [f43a241f] + Downloads [9fa8497b] + Future [b77e0a4c] + InteractiveUtils [b27032c2] + LibCURL [76f85450] + LibGit2 [8f399da3] + Libdl [37e2e46d] + LinearAlgebra [56ddb016] + Logging [d6f4376e] + Markdown [a63ad114] + Mmap [ca575930] + NetworkOptions [44cfe95a] + Pkg [de0858da] + Printf [3fa0cd96] + REPL [9a3f8284] + Random [ea8e919c] + SHA [9e88b42a] + Serialization [1a1011a3] + SharedArrays [6462fe0b] + Sockets [2f01184e] + SparseArrays [10745b16] + Statistics [4607b0f0] + SuiteSparse [fa267f1f] + TOML [a4e569a6] + Tar [8dfed614] + Test [cf7118a7] + UUIDs [4ec0a83e] + Unicode [e66e0078] + CompilerSupportLibraries_jll [deac9b47] + LibCURL_jll [29816b5a] + LibSSH2_jll [c8ffd9c3] + MbedTLS_jll [14a3606d] + MozillaCACerts_jll [4536629a] + OpenBLAS_jll [05823500] + OpenLibm_jll [bea87d4a] + SuiteSparse_jll [83775a58] + Zlib_jll [8e850b90] + libblastrampoline_jll [8e850ede] + nghttp2_jll [3f19e933] + p7zip_jll ```
isaacsas commented 2 years ago

@shashi looks like something changed in Symbolics. Any chance you can point us to what we need to update in

https://github.com/SciML/Catalyst.jl/blob/6db2cd3e7d518872ba96585361cd9b3a9c7d945b/src/latexify_recipes.jl#L64

to make this work again? Thanks!

isaacsas commented 2 years ago

I think ModelingToolkit.substituter isn't quite working the same anymore maybe?

isaacsas commented 2 years ago

Seems to be from https://github.com/JuliaSymbolics/Symbolics.jl/issues/523

fonsp commented 2 years ago

Awesome, thanks for looking into this! Progress looks promising!

isaacsas commented 2 years ago

Should work now as I redid how we handle terms in a way that bypasses the Symbolics' issue, but let me know if you still have problems.