Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moving plots to extensions #146

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Expand All @@ -21,11 +20,13 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b"
DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[extensions]
AlgebraicDynamicsAlgebraicPetriExt = "AlgebraicPetri"
AlgebraicDynamicsDelayDiffEqExt = "DelayDiffEq"
AlgebraicDynamicsOrdinaryDiffEqExt = "OrdinaryDiffEq"
AlgebraicDynamicsPlotsExt = "Plots"

[compat]
AlgebraicPetri = "0.9"
Expand Down
25 changes: 25 additions & 0 deletions ext/AlgebraicDynamicsPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module AlgebraicDynamicsPlotsExt

using AlgebraicDynamics

using Plots

### Plotting backend
@recipe function f(sol, m::AbstractMachine, p=nothing)
labels = (String ∘ Symbol).(output_ports(m))
label --> reshape(labels, 1, length(labels))
vars --> map(1:noutputs(m)) do i
((t, args...) -> (t, readout(m)(collect(args), p, t)[i]), 0:nstates(m)...)
end
sol
end

### Plotting backend
@recipe function f(sol, r::AbstractResourceSharer)
labels = (String ∘ Symbol).(collect(view(ports(r), portmap(r))))
label --> reshape(labels, 1, length(labels))
vars --> portmap(r)
sol
end

end
16 changes: 3 additions & 13 deletions src/dwd_dynam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import Catlab.WiringDiagrams: oapply, input_ports, output_ports

import ..UWDDynam: AbstractInterface, nstates, eval_dynamics, euler_approx, trajectory

using Plots

export AbstractMachine, ContinuousMachine, DiscreteMachine, DelayMachine,
InstantaneousContinuousMachine, InstantaneousDiscreteMachine, InstantaneousDelayMachine,
nstates, ninputs, noutputs, eval_dynamics, readout, euler_approx,
dependency_pairs
InstantaneousContinuousMachine, InstantaneousDiscreteMachine, InstantaneousDelayMachine, nstates, ninputs, noutputs, eval_dynamics, readout, euler_approx,
dependency_pairs, output_ports

using Base.Iterators
import Base: show, eltype, zero
Expand Down Expand Up @@ -378,15 +376,7 @@ euler_approx(fs::AbstractDict{S, M}, args...) where {S, M<:ContinuousMachine} =



### Plotting backend
@recipe function f(sol, m::AbstractMachine, p=nothing)
labels = (String ∘ Symbol).(output_ports(m))
label --> reshape(labels, 1, length(labels))
vars --> map(1:noutputs(m)) do i
((t, args...) -> (t, readout(m)(collect(args), p, t)[i]), 0:nstates(m)...)
end
sol
end



""" oapply(d::WiringDiagram, ms::Vector{M}) where {M<:AbstractMachine}
Expand Down
12 changes: 1 addition & 11 deletions src/uwd_dynam.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
module UWDDynam
using Catlab


using Catlab.WiringDiagrams.UndirectedWiringDiagrams: AbstractUWD
import Catlab.WiringDiagrams: oapply, ports

using Plots

export AbstractResourceSharer, ContinuousResourceSharer, DelayResourceSharer, DiscreteResourceSharer,
euler_approx, nstates, nports, portmap, portfunction, trajectory,
euler_approx, nstates, nports, ports, portmap, portfunction, trajectory,
eval_dynamics, eval_dynamics!, exposed_states, fills, induced_states

using Base.Iterators
Expand Down Expand Up @@ -217,13 +214,6 @@ euler_approx(fs::AbstractDict{S, R}, args...) where {S, T, R<:ContinuousResource
# Trajectories
function trajectory() end

### Plotting backend
@recipe function f(sol, r::ResourceSharer)
labels = (String ∘ Symbol).(collect(view(ports(r), portmap(r))))
label --> reshape(labels, 1, length(labels))
vars --> portmap(r)
sol
end

""" fills(r::AbstractResourceSharer, d::AbstractUWD, b::Int)

Expand Down
Loading