@@ -450,6 +450,17 @@ diff_2_zero(expr) = (Symbolics.is_derivative(expr) ? 0 : expr)
450
450
451
451
COMPLETENESS_ERROR = " A ReactionSystem must be complete before it can be converted to other system types. A ReactionSystem can be marked as complete using the `complete` function."
452
452
453
+ # Used to, when required, display a warning about conservation law removeal and remake.
454
+ function check_cons_warning (remove_conserved, remove_conserved_warn)
455
+ (remove_conserved && remove_conserved_warn) || return
456
+ @warn " You are creating a system while eliminating conserved quantities. While this is possible,
457
+ if you use the created system to create a problem (e.g. an `ODEProblem`), you *should not*
458
+ modify that problem's species values (e.g. using `remake`). Modification of parameter values
459
+ is still possible. You might get this warning when creating a problem directly.
460
+
461
+ You can remove this warning by setting `remove_conserved_warn = false`."
462
+ end
463
+
453
464
# ## System Conversions ###
454
465
455
466
"""
@@ -467,15 +478,20 @@ Keyword args and default values:
467
478
- `remove_conserved=false`, if set to `true` will calculate conservation laws of the
468
479
underlying set of reactions (ignoring constraint equations), and then apply them to reduce
469
480
the number of equations.
481
+ - `remove_conserved_warn = true`: If `true`, if also `remove_conserved = true`, there will be
482
+ a warning regarding limitations of modifying problems generated from the created system.
470
483
"""
471
484
function Base. convert (:: Type{<:ODESystem} , rs:: ReactionSystem ; name = nameof (rs),
472
485
combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
473
- include_zero_odes = true , remove_conserved = false , checks = false ,
474
- default_u0 = Dict (), default_p = Dict (),
486
+ include_zero_odes = true , remove_conserved = false , remove_conserved_warn = true ,
487
+ checks = false , default_u0 = Dict (), default_p = Dict (),
475
488
defaults = _merge (Dict (default_u0), Dict (default_p)),
476
489
kwargs... )
490
+ # Error checks.
477
491
iscomplete (rs) || error (COMPLETENESS_ERROR)
478
492
spatial_convert_err (rs:: ReactionSystem , ODESystem)
493
+ check_cons_warning (remove_conserved, remove_conserved_warn)
494
+
479
495
fullrs = Catalyst. flatten (rs)
480
496
remove_conserved && conservationlaws (fullrs)
481
497
ists, ispcs = get_indep_sts (fullrs, remove_conserved)
@@ -509,16 +525,19 @@ Keyword args and default values:
509
525
- `remove_conserved=false`, if set to `true` will calculate conservation laws of the
510
526
underlying set of reactions (ignoring constraint equations), and then apply them to reduce
511
527
the number of equations.
528
+ - `remove_conserved_warn = true`: If `true`, if also `remove_conserved = true`, there will be
529
+ a warning regarding limitations of modifying problems generated from the created system.
512
530
"""
513
531
function Base. convert (:: Type{<:NonlinearSystem} , rs:: ReactionSystem ; name = nameof (rs),
514
532
combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
515
533
include_zero_odes = true , remove_conserved = false , checks = false ,
516
- default_u0 = Dict (), default_p = Dict (),
534
+ remove_conserved_warn = true , default_u0 = Dict (), default_p = Dict (),
517
535
defaults = _merge (Dict (default_u0), Dict (default_p)),
518
536
all_differentials_permitted = false , kwargs... )
519
537
# Error checks.
520
538
iscomplete (rs) || error (COMPLETENESS_ERROR)
521
539
spatial_convert_err (rs:: ReactionSystem , NonlinearSystem)
540
+ check_cons_warning (remove_conserved, remove_conserved_warn)
522
541
if ! isautonomous (rs)
523
542
error (" Attempting to convert a non-autonomous `ReactionSystem` (e.g. where some rate depend on $(get_iv (rs)) ) to a `NonlinearSystem`. This is not possible. if you are intending to compute system steady states, consider creating and solving a `SteadyStateProblem." )
524
543
end
@@ -589,17 +608,19 @@ Notes:
589
608
- `remove_conserved=false`, if set to `true` will calculate conservation laws of the
590
609
underlying set of reactions (ignoring constraint equations), and then apply them to reduce
591
610
the number of equations.
592
- - Does not currently support `ReactionSystem`s that include coupled algebraic or
593
- differential equations .
611
+ - `remove_conserved_warn = true`: If `true`, if also `remove_conserved = true`, there will be
612
+ a warning regarding limitations of modifying problems generated from the created system .
594
613
"""
595
614
function Base. convert (:: Type{<:SDESystem} , rs:: ReactionSystem ;
596
615
name = nameof (rs), combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
597
616
include_zero_odes = true , checks = false , remove_conserved = false ,
598
- default_u0 = Dict (), default_p = Dict (),
617
+ remove_conserved_warn = true , default_u0 = Dict (), default_p = Dict (),
599
618
defaults = _merge (Dict (default_u0), Dict (default_p)),
600
619
kwargs... )
620
+ # Error checks.
601
621
iscomplete (rs) || error (COMPLETENESS_ERROR)
602
622
spatial_convert_err (rs:: ReactionSystem , SDESystem)
623
+ check_cons_warning (remove_conserved, remove_conserved_warn)
603
624
604
625
flatrs = Catalyst. flatten (rs)
605
626
@@ -651,7 +672,6 @@ function Base.convert(::Type{<:JumpSystem}, rs::ReactionSystem; name = nameof(rs
651
672
kwargs... )
652
673
iscomplete (rs) || error (COMPLETENESS_ERROR)
653
674
spatial_convert_err (rs:: ReactionSystem , JumpSystem)
654
-
655
675
(remove_conserved != = nothing ) &&
656
676
throw (ArgumentError (" Catalyst does not support removing conserved species when converting to JumpSystems." ))
657
677
@@ -684,12 +704,12 @@ function DiffEqBase.ODEProblem(rs::ReactionSystem, u0, tspan,
684
704
p = DiffEqBase. NullParameters (), args... ;
685
705
check_length = false , name = nameof (rs),
686
706
combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
687
- include_zero_odes = true , remove_conserved = false ,
707
+ include_zero_odes = true , remove_conserved = false , remove_conserved_warn = true ,
688
708
checks = false , structural_simplify = false , kwargs... )
689
709
u0map = symmap_to_varmap (rs, u0)
690
710
pmap = symmap_to_varmap (rs, p)
691
711
osys = convert (ODESystem, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
692
- remove_conserved)
712
+ remove_conserved, remove_conserved_warn )
693
713
694
714
# Handles potential differential algebraic equations (which requires `structural_simplify`).
695
715
if structural_simplify
@@ -708,12 +728,12 @@ function DiffEqBase.NonlinearProblem(rs::ReactionSystem, u0,
708
728
p = DiffEqBase. NullParameters (), args... ;
709
729
name = nameof (rs), include_zero_odes = true ,
710
730
combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
711
- remove_conserved = false , checks = false ,
731
+ remove_conserved = false , remove_conserved_warn = true , checks = false ,
712
732
check_length = false , all_differentials_permitted = false , kwargs... )
713
733
u0map = symmap_to_varmap (rs, u0)
714
734
pmap = symmap_to_varmap (rs, p)
715
735
nlsys = convert (NonlinearSystem, rs; name, combinatoric_ratelaws, include_zero_odes,
716
- checks, all_differentials_permitted, remove_conserved)
736
+ checks, all_differentials_permitted, remove_conserved, remove_conserved_warn )
717
737
nlsys = complete (nlsys)
718
738
return NonlinearProblem (nlsys, u0map, pmap, args... ; check_length,
719
739
kwargs... )
@@ -723,12 +743,12 @@ end
723
743
function DiffEqBase. SDEProblem (rs:: ReactionSystem , u0, tspan,
724
744
p = DiffEqBase. NullParameters (), args... ;
725
745
name = nameof (rs), combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
726
- include_zero_odes = true , checks = false , check_length = false ,
727
- remove_conserved = false , structural_simplify = false , kwargs... )
746
+ include_zero_odes = true , checks = false , check_length = false , remove_conserved = false ,
747
+ remove_conserved_warn = true , structural_simplify = false , kwargs... )
728
748
u0map = symmap_to_varmap (rs, u0)
729
749
pmap = symmap_to_varmap (rs, p)
730
750
sde_sys = convert (SDESystem, rs; name, combinatoric_ratelaws,
731
- include_zero_odes, checks, remove_conserved)
751
+ include_zero_odes, checks, remove_conserved, remove_conserved_warn )
732
752
733
753
# Handles potential differential algebraic equations (which requires `structural_simplify`).
734
754
if structural_simplify
@@ -772,12 +792,12 @@ function DiffEqBase.SteadyStateProblem(rs::ReactionSystem, u0,
772
792
p = DiffEqBase. NullParameters (), args... ;
773
793
check_length = false , name = nameof (rs),
774
794
combinatoric_ratelaws = get_combinatoric_ratelaws (rs),
775
- remove_conserved = false , include_zero_odes = true ,
795
+ remove_conserved = false , remove_conserved_warn = true , include_zero_odes = true ,
776
796
checks = false , structural_simplify = false , kwargs... )
777
797
u0map = symmap_to_varmap (rs, u0)
778
798
pmap = symmap_to_varmap (rs, p)
779
799
osys = convert (ODESystem, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
780
- remove_conserved)
800
+ remove_conserved, remove_conserved_warn )
781
801
782
802
# Handles potential differential algebraic equations (which requires `structural_simplify`).
783
803
if structural_simplify
0 commit comments