From bb2647f7f7e91cf17b1a16b50d32e63caae31158 Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Tue, 17 Dec 2024 13:08:48 +0000 Subject: [PATCH] init --- .../serialise_reactionsystem.jl | 14 +++++++++----- .../reactionsystem_serialisation.jl | 2 +- test/runtests.jl | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/reactionsystem_serialisation/serialise_reactionsystem.jl b/src/reactionsystem_serialisation/serialise_reactionsystem.jl index 01a8a2243c..03ee406884 100644 --- a/src/reactionsystem_serialisation/serialise_reactionsystem.jl +++ b/src/reactionsystem_serialisation/serialise_reactionsystem.jl @@ -10,10 +10,10 @@ Arguments: - `annotate = true`: Whether annotation should be added to the file. - `safety_check = true`: After serialisation, Catalyst will automatically load the serialised `ReactionSystem` and check that it is equal to `rn`. If it is not, an error will be thrown. For - models without the `connection_type` field, this should not happen. If performance is required + models without the `connection_type` field, this should not happen. If performance is required (i.e. when saving a large number of models), this can be disabled by setting `safety_check = false`. -Example: +Example: ```julia rn = @reaction_network begin (p,d), 0 <--> X @@ -56,13 +56,17 @@ end # Gets the full string which corresponds to the declaration of a system. Might be called recursively # for systems with subsystems. function get_full_system_string(rn::ReactionSystem, annotate::Bool, top_level::Bool) + # MTK automatically performs flattening when `complete` is carried out. In case of a + # hierarchical system, we must undo this an process the non-flattened system. + iscomplete(rn) && (rn = MT.get_parent(rn)) + # Initiates the file string. file_text = "" # Goes through each type of system component, potentially adding it to the string. # Species, variables, and parameters must be handled differently in case there are default values - # dependencies between them. - # Systems use custom `push_field` function as these require the annotation `Bool`to be passed + # dependencies between them. + # Systems use custom `push_field` function as these require the annotation `Bool`to be passed # to the function that creates the next sub-system declarations. file_text, _ = push_field(file_text, rn, annotate, top_level, IV_FS) file_text, has_sivs = push_field(file_text, rn, annotate, top_level, SIVS_FS) @@ -163,7 +167,7 @@ function make_reaction_system_call(rs::ReactionSystem, annotate, top_level, has_ @string_append! reaction_system_string ", metadata = $(x_2_string(MT.get_metadata(rs)))" end - # Finalises the call. Appends potential annotation. If the system is complete, add a call for this. + # Finalises the call. Appends potential annotation. If the system is complete, add a call for this. @string_append! reaction_system_string ")" if ModelingToolkit.iscomplete(rs) @string_prepend! "rs = " reaction_system_string diff --git a/test/miscellaneous_tests/reactionsystem_serialisation.jl b/test/miscellaneous_tests/reactionsystem_serialisation.jl index 8b84c2b420..d6dab48f86 100644 --- a/test/miscellaneous_tests/reactionsystem_serialisation.jl +++ b/test/miscellaneous_tests/reactionsystem_serialisation.jl @@ -204,7 +204,7 @@ let @test isequal(Catalyst.getmisc(get_rxs(rs_loaded.rs2)[5]), mat_md) # Checks that `ReactionSystem` metadata fields are correct. - @test isequal(get_metadata(rs_loaded), mat_md) + @test_broken isequal(get_metadata(rs_loaded), mat_md) # Issue in MTK: https://github.com/SciML/ModelingToolkit.jl/issues/3275 @test isequal(get_metadata(rs_loaded.rs2), dict_md) end diff --git a/test/runtests.jl b/test/runtests.jl index 5a3176872a..26f322221b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -56,8 +56,7 @@ end end if GROUP == "All" || GROUP == "IO" - # BROKEN - # @time @safetestset "ReactionSystem Serialisation" begin include("miscellaneous_tests/reactionsystem_serialisation.jl") end + @time @safetestset "ReactionSystem Serialisation" begin include("miscellaneous_tests/reactionsystem_serialisation.jl") end # BROKEN # @time @safetestset "Latexify" begin include("visualisation/latexify.jl") end