Skip to content

query on conservationlaws returned matrix #360

@yewalenikhil65

Description

@yewalenikhil65

Hi, @kaandocal
This is about conservationlaws
The way i understand this is, smith normal form was used to find the nullspace of netstoichmat(rn)

example taken from https://github.com/SciML/Catalyst.jl/blob/master/test/conslaws.jl

rn = @reaction_network begin
    (1, 2), A + B <--> C 
    (3, 2), D <--> E 
    (0.1, 0.2), E <--> F
    6, F --> G
    7, H --> G
    5, 0 --> K
    3, A + B --> Z + C
end

N = netstoichmat(rn)

julia> C = conservationlaws(N)
3×10 Matrix{BigInt}:
  0  0  0  1  1  1  1  1  0  0
 -1  1  0  0  0  0  0  0  0  0
  0  1  1  0  0  0  0  0  0  0

which returns vector of conserved quantities as

julia> C*states(rn)
3-element Vector{Any}:
 D(t) + E(t) + F(t) + G(t) + H(t)
 B(t) - A(t)
 B(t) + C(t)

I use a little different approach to check C matrix. Following is the nullspace estimate from rational basis perspective, meaning the way we would have done to calculate nullspace had we done it by hand. (Code logic taken from null.m in MATLAB and used RowEchelon.jl library to obtain rref)

using LinearAlgebra
using RowEchelon
function rational_basis_nullspace(A::AbstractVecOrMat)
"""
Citation:
This function is re-written in Julia , based on
Built-in MATLAB function null.m ( Copyright 1984-2017 The MathWorks, Inc.)
"""

    R,pivcol = rref_with_pivots(A)
    m,n = size(A);
    r = length(pivcol);
    nopiv = collect(1:n);
    deleteat!(nopiv, pivcol)
    Z = zeros(n,n-r);
    if n > r
        Z[nopiv,:] = diagm(0 => ones(n-r));
        if r > 0
            Z[pivcol,:] = -R[1:r,nopiv];
        end
    end
    return Z
end

This returns conservation laws as follows

julia> rational_basis_nullspace(N)'*states(rn)
3-element Vector{Any}:
 B(t) - A(t)
 A(t) + C(t)
 D(t) + E(t) + F(t) + G(t) + H(t)

As noticed, B(t) + C(t) conserved quantity earlier from conservationlaws is now A(t) +C(t)..
To notice further difference lets see the entries returned by LinearAlgebra.nullspace() and conservationlaws() as follows
image

It seems some entries returned from conservationlaws don't agree with LinearAlgebra.nullspace and rational_basis_nullspace (even after appropriate scaling etc.) in a sense that expected conservedquantities differ by both approaches

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