Browse Source

Merge pull request #48 from AlgebraicJulia/requires

Starting to add Requires.jl
master v0.6.5
Micah Halter 4 weeks ago
committed by GitHub
parent
commit
47be95119f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      .github/workflows/test.yml
  2. 11
      Project.toml
  3. 24
      src/AlgebraicPetri.jl
  4. 28
      src/interoperability.jl
  5. 6
      test/Project.toml
  6. 2
      test/runtests.jl

11
.github/workflows/test.yml

@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia-version: ['1.0', '1.6']
julia_version: ['1.0', '1.6']
os: [ubuntu-latest]
steps:
@ -16,6 +16,13 @@ jobs:
- name: "Set up Julia"
uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}
version: ${{ matrix.julia_version }}
- name: "Run tests"
uses: julia-actions/julia-runtest@master
if: matrix.julia_version != '1.0'
- name: "Run tests (Julia v1.0)"
run: |
julia -e 'using Pkg; Pkg.activate("test"); Pkg.develop(PackageSpec(path="."))'
julia --color=yes --check-bounds=yes --project=test test/runtests.jl
# XXX: Julia 1.0 does not use the Project.toml in `tests` directory.
if: matrix.julia_version == '1.0'

11
Project.toml

@ -2,26 +2,23 @@ name = "AlgebraicPetri"
uuid = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b"
license = "MIT"
authors = ["Micah Halter <micah@mehalter.com>"]
version = "0.6.4"
version = "0.6.5"
[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
[compat]
AutoHashEquals = "^0.2.0"
Catlab = "0.11, 0.12"
LabelledArrays = "^1"
Petri = "^1.2.5"
Requires = "^1"
StatsBase = "^0.33"
julia = "1.0"
[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[targets]
test = ["Test"]
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33"

24
src/AlgebraicPetri.jl

@ -17,10 +17,8 @@ using Catlab.CategoricalAlgebra
using Catlab.CategoricalAlgebra.FinSets
using Catlab.Present
using Catlab.Theories
using Petri
using LabelledArrays
using LinearAlgebra: mul!
import Petri: Model, Graph, vectorfield
vectorify(n::Vector) = n
vectorify(n::Tuple) = length(n) == 1 ? [n] : n
@ -325,27 +323,6 @@ LabelledReactionNet{R,C}(pn::Union{AbstractPetriNet}, states, transitions) where
pn′
end
# Interoperability with Petri.jl
Petri.Model(p::AbstractPetriNet) = begin
ts = TransitionMatrices(p)
t_in = map(i->Dict(k=>v for (k,v) in enumerate(ts.input[i,:]) if v != 0), 1:nt(p))
t_out = map(i->Dict(k=>v for (k,v) in enumerate(ts.output[i,:]) if v != 0), 1:nt(p))
Δ = Dict(i=>t for (i,t) in enumerate(zip(t_in, t_out)))
return Petri.Model(ns(p), Δ)
end
Petri.Model(p::Union{AbstractLabelledPetriNet, AbstractLabelledReactionNet}) = begin
snames = [sname(p, s) for s in 1:ns(p)]
tnames = [tname(p, t) for t in 1:nt(p)]
ts = TransitionMatrices(p)
t_in = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.input[i,:]) if v != 0]...), 1:nt(p))
t_out = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.output[i,:]) if v != 0]...), 1:nt(p))
Δ = LVector(;[(tnames[i]=>t) for (i,t) in enumerate(zip(t_in, t_out))]...)
return Petri.Model(collect(values(snames)), Δ)
end
concentration(p::AbstractLabelledReactionNet,s) = subpart(p,s,:concentration)
rate(p::AbstractLabelledReactionNet,t) = subpart(p,t,:rate)
@ -359,6 +336,7 @@ rates(p::AbstractLabelledReactionNet) = begin
LVector(;[(tnames[t]=>rate(p, t)) for t in 1:nt(p)]...)
end
include("interoperability.jl")
include("visualization.jl")
include("Epidemiology.jl")

28
src/interoperability.jl

@ -0,0 +1,28 @@
using Requires
function __init__()
@require Petri="4259d249-1051-49fa-8328-3f8ab9391c33" begin
import .Petri
# Interoperability with Petri.jl
Petri.Model(p::AbstractPetriNet) = begin
ts = TransitionMatrices(p)
t_in = map(i->Dict(k=>v for (k,v) in enumerate(ts.input[i,:]) if v != 0), 1:nt(p))
t_out = map(i->Dict(k=>v for (k,v) in enumerate(ts.output[i,:]) if v != 0), 1:nt(p))
Δ = Dict(i=>t for (i,t) in enumerate(zip(t_in, t_out)))
return Petri.Model(ns(p), Δ)
end
Petri.Model(p::Union{AbstractLabelledPetriNet, AbstractLabelledReactionNet}) = begin
snames = [sname(p, s) for s in 1:ns(p)]
tnames = [tname(p, t) for t in 1:nt(p)]
ts = TransitionMatrices(p)
t_in = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.input[i,:]) if v != 0]...), 1:nt(p))
t_out = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.output[i,:]) if v != 0]...), 1:nt(p))
Δ = LVector(;[(tnames[i]=>t) for (i,t) in enumerate(zip(t_in, t_out))]...)
return Petri.Model(collect(values(snames)), Δ)
end
end
end

6
test/Project.toml

@ -0,0 +1,6 @@
[deps]
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

2
test/runtests.jl

@ -1,6 +1,6 @@
using Test
using Petri
import Petri
using LabelledArrays
using AlgebraicPetri
using AlgebraicPetri.Epidemiology

Loading…
Cancel
Save