diff --git a/bench/pkg/catalyst.jl b/bench/pkg/catalyst.jl index 0c1f61a958dfe5f5c110c5e3d9ee909d0dde3b4d..dd8b02a5e28fdc9cb2599b2fcf266faf796fc379 100644 --- a/bench/pkg/catalyst.jl +++ b/bench/pkg/catalyst.jl @@ -15,6 +15,7 @@ ER.buffer_size = 100 ER.estim_min_states = 8000 bench1_pkg = @benchmark simulate(ER) +@btime simulate(ER) @show minimum(bench1_pkg), mean(bench1_pkg), maximum(bench1_pkg) rs = @reaction_network begin @@ -31,6 +32,7 @@ jprob = JumpProblem(rs, dprob, Direct()) jsol = solve(jprob, SSAStepper()) bench1_catalyst = @benchmark solve(jprob, SSAStepper()) +@btime solve(jprob, SSAStepper()) @show minimum(bench1_catalyst), mean(bench1_catalyst), maximum(bench1_catalyst) str_latex_bench1 = " diff --git a/core/MarkovProcesses.jl b/core/MarkovProcesses.jl index bd76447ccf97babcee721e7f8ccc4950fc55e6ca..b6b4c6fbe743111e43dd18b401c4168caae835b8 100644 --- a/core/MarkovProcesses.jl +++ b/core/MarkovProcesses.jl @@ -1,14 +1,18 @@ module MarkovProcesses +## Imports import Base: +, -, * import Base: copy, getfield, getindex, getproperty, lastindex import Base: setindex!, setproperty!, fill!, copyto! -import Distributed: @everywhere, @distributed -import Distributions: Distribution, Product, Uniform, Normal import Dates +import Distributed: @everywhere, @distributed +import Distributions: Product, Uniform, Normal +import Distributions: Distribution, Univariate, Continuous, UnivariateDistribution, + MultivariateDistribution, product_distribution import StaticArrays: SVector +## Exports export Distribution, Product, Uniform, Normal # Common types and constructors diff --git a/core/common.jl b/core/common.jl index e7909d52396289a8d49670de1c516cfc96fe225f..407383ac41837332c271fef62c5f1a30fbba27cc 100644 --- a/core/common.jl +++ b/core/common.jl @@ -1,11 +1,12 @@ -import Distributions: Distribution, Univariate, Continuous, UnivariateDistribution, - MultivariateDistribution, product_distribution abstract type Model end abstract type ContinuousTimeModel <: Model end abstract type AbstractTrajectory end +abstract type LHA end +abstract type Edge end + const VariableModel = Symbol const ParameterModel = Symbol const Transition = Union{Symbol,Nothing} @@ -42,27 +43,21 @@ struct Trajectory <: AbstractTrajectory transitions::Vector{Transition} end -#= -struct Edge - transitions::Union{Nothing,Vector{Symbol}} - check_constraints::Function - update_state!::Function -end -=# -abstract type Edge end - -struct LHA - name::String - transitions::Vector{Transition} - locations::Vector{Location} - Λ::Dict{Location,Function} - locations_init::Vector{Location} - locations_final::Vector{Location} - map_var_automaton_idx::Dict{VariableAutomaton,Int} # nvar keys : str_var => idx in values - flow::Dict{Location,Vector{Float64}} # output of length nvar - map_edges::Dict{Location, Dict{Location,Vector{Edge}}} - constants::Dict{Symbol,Float64} - map_var_model_idx::Dict{VariableModel,Int} # of dim d (of a model) +function generate_code_lha_type_def(lha_name::Symbol, edge_type::Symbol) + return quote + struct $(lha_name) <: LHA + transitions::Vector{Transition} + locations::Vector{Location} + Λ::Dict{Location,Function} + locations_init::Vector{Location} + locations_final::Vector{Location} + map_var_automaton_idx::Dict{VariableAutomaton,Int} # nvar keys : str_var => idx in values + flow::Dict{Location,Vector{Float64}} # output of length nvar + map_edges::Dict{Location, Dict{Location,Vector{$(edge_type)}}} + constants::Dict{Symbol,Float64} + map_var_model_idx::Dict{VariableModel,Int} # of dim d (of a model) + end + end end mutable struct StateLHA @@ -123,9 +118,9 @@ function generate_code_model_type_constructor(model_name::Symbol) end end -LHA(A::LHA, map_var::Dict{VariableModel,Int}) = LHA(A.name, A.transitions, A.locations, A.Λ, - A.locations_init, A.locations_final, A.map_var_automaton_idx, A.flow, - A.map_edges, A.constants, map_var) +LHA(A::LHA, map_var::Dict{VariableModel,Int}) = +getfield(Main, Symbol(typeof(A)))(A.transitions, A.locations, A.Λ, A.locations_init, A.locations_final, + A.map_var_automaton_idx, A.flow, A.map_edges, A.constants, map_var) Base.:*(m::ContinuousTimeModel, A::LHA) = SynchronizedModel(m, A) Base.:*(A::LHA, m::ContinuousTimeModel) = SynchronizedModel(m, A) diff --git a/core/network_model.jl b/core/network_model.jl index 9f3a552aa44d6732c838f4b038aa6277f8acdcff..455d2436c24bb57482d96860c6a70356d71e1060 100644 --- a/core/network_model.jl +++ b/core/network_model.jl @@ -145,7 +145,7 @@ macro network_model(expr_network,expr_name...) # Creation of names variables model_name = isempty(expr_name) ? "Network" : expr_name[1] model_name = Symbol(replace(model_name, ' ' => '_') * "Model") - id = Dates.format(Dates.now(), "YmHMs") + id = MarkovProcesses.newid() nbr_reactions = length(list_expr_reactions) basename_func = "$(model_name)_$(id)" basename_func = replace(basename_func, '-'=>'_') diff --git a/core/utils.jl b/core/utils.jl index 83bf39ee4e900b5368b3bed97ac51ee1ce0e2fed..4abde85c61418e2fd1287c7b64a61d7e7c684669 100644 --- a/core/utils.jl +++ b/core/utils.jl @@ -27,3 +27,5 @@ load_model(name_model::String) = Base.MainInclude.include("$(get_module_path())/ load_automaton(automaton::String) = Base.MainInclude.include("$(get_module_path())/automata/$(automaton).jl") load_plots() = Base.MainInclude.include(get_module_path() * "/core/plots.jl") +newid() = Dates.format(Dates.now(), "YmHMs") +