Skip to content

Commit

Permalink
🚧 Upgrade default_model.
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Dec 20, 2024
1 parent 65624fb commit 07944a5
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 143 deletions.
4 changes: 2 additions & 2 deletions src/EcologicalNetworksDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ include("./expose_data.jl")
include("./components/main.jl")

# HERE: now that all components have been upgraded, upgrade the following!
# # Additional exposed utils built on top of components and methods.
# include("./default_model.jl")
# Additional exposed utils built on top of components and methods.
include("./default_model.jl")
# include("./nontrophic_layers.jl")
# include("./simulate.jl")
# include("./topology.jl")
Expand Down
6 changes: 6 additions & 0 deletions src/Framework/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ singleton_instance(C::CompType) = throw("No concrete singleton instance of '$C'.
# Extract underlying system wrapped value type from a component.
system_value_type(::CompRef{V}) where {V} = V

# Typecheck regardless of the instance/type.
isacomponent(::CompType) = true
isacomponent(::Component) = true
isacomponent(::Any) = false
export isacomponent

#-------------------------------------------------------------------------------------------
# Requirements.

Expand Down
5 changes: 4 additions & 1 deletion src/components/args_to_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ end
# fall back attempt to convert to its 'Union' field, which is not a constructor.
pass_args_kwargs(BF::Type{<:F.BroughtField}, ::Nothing) = BF(nothing)
pass_args_kwargs(BF::Type{<:F.BroughtField}, C::F.CompType) = BF(C)
pass_args_kwargs(BF::Type{<:F.BroughtField}, C::F.Component) = BF(C)
pass_args_kwargs(BF::Type{<:F.BroughtField}, bp::F.Blueprint) = BF(bp)
function pass_args_kwargs(BF::Type{<:F.BroughtField}, input)
ak = to_args_kwargs(input)
convert(BF, ak)
Expand All @@ -25,7 +27,8 @@ end
# unless the input is already of the right type
# and then there is no need to construct more.
function pass_args_kwargs_to_type(type, input)
input isa type ? input : pass_args_kwargs(type, input)
res = input isa type
res ? input : pass_args_kwargs(type, input)
end

# Given a struct type,
Expand Down
2 changes: 0 additions & 2 deletions src/components/nontrophic_layers/competition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,4 @@ export Layer
# Calling the component is like calling the (single) corresponding blueprint constructor.
(::_Layer)(args...; kwargs...) = Pack(args...; kwargs...)

F.shortline(io::IO, ::Model, ::_Layer) = print(io, "Competition Layer.")

end
2 changes: 0 additions & 2 deletions src/components/nontrophic_layers/facilitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,4 @@ export Layer
# Calling the component is like calling the (single) corresponding blueprint constructor.
(::_Layer)(args...; kwargs...) = Pack(args...; kwargs...)

F.shortline(io::IO, ::Model, ::_Layer) = print(io, "Facilitation Layer.")

end
2 changes: 0 additions & 2 deletions src/components/nontrophic_layers/interference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,4 @@ export Layer
# Calling the component is like calling the (single) corresponding blueprint constructor.
(::_Layer)(args...; kwargs...) = Pack(args...; kwargs...)

F.shortline(io::IO, ::Model, ::_Layer) = print(io, "Interference Layer.")

end
2 changes: 0 additions & 2 deletions src/components/nontrophic_layers/refuge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,4 @@ export Layer
# Calling the component is like calling the (single) corresponding blueprint constructor.
(::_Layer)(args...; kwargs...) = Pack(args...; kwargs...)

F.shortline(io::IO, ::Model, ::_Layer) = print(io, "Refuge Layer.")

end
4 changes: 2 additions & 2 deletions src/components/nutrients/nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ F.add_trigger!(
end,
)

(::_Nodes)() = Nodes.PerProducer()
(::_Nodes)(names) = Nodes.Names(names)
(::_Nodes)(n::Integer) = Nodes.Number(n)
(::_Nodes)(names) = Nodes.Names(names)
(::_Nodes)(; per_producer = 1) = Nodes.PerProducer(per_producer)

function F.shortline(io::IO, model::Model, ::_Nodes)
N = model.nutrients.number
Expand Down
8 changes: 6 additions & 2 deletions src/dedicate_framework_to_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import .F:
System,
add!,
blueprints,
embedded,
checkfails,
checkrefails,
components,
does_bring,
does_embed,
does_imply,
embedded,
has_component,
implied
implied,
isacomponent

# Direct re-exports from the framework module.
export add!
Expand All @@ -33,11 +34,14 @@ export does_imply
export embedded
export has_component
export implied
export isacomponent
export properties

const Internal = Internals.ModelParameters # <- TODO: rename when refactoring Internals.

const Blueprint = F.Blueprint{Internal}
const BlueprintSum = F.BlueprintSum{Internal}
const CompType = F.CompType{Internal}
const Component = F.Component{Internal}

const Model = F.System{Internal}
Expand Down
Loading

0 comments on commit 07944a5

Please sign in to comment.