Skip to content

Commit

Permalink
First pass at GATlab integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Oct 27, 2023
1 parent 7db7bd0 commit f7070f9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.2.1"
[deps]
ACSets = "227ef7b5-1206-438b-ac65-934d6da304b8"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
DataMigrations = "0c4ad18d-0c49-4bc2-90d5-5bca8f00d6ae"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Expand Down
7 changes: 4 additions & 3 deletions docs/src/lotka_volterra.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module LotkaVolterra

using Catlab, Catlab.Theories, Catlab.CategoricalAlgebra, Catlab.Graphs,
Catlab.Graphics, Catlab.WiringDiagrams, Catlab.Programs
using AlgebraicRewriting
using Random, Test, StructEquality
using Luxor

using Catlab
using DataMigrations: @acset_colim
using AlgebraicRewriting

Random.seed!(123);

using Catlab.Graphics.Graphviz: Attributes, Statement, Node
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite/PBPO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export PBPORule

using Catlab, Catlab.CategoricalAlgebra
import Catlab.CategoricalAlgebra: left, right
using Catlab.CategoricalAlgebra.CSets: backtracking_search, abstract_attributes
using Catlab.CategoricalAlgebra.HomSearch: backtracking_search, abstract_attributes

using StructEquality
using DataStructures: DefaultDict
Expand Down
4 changes: 2 additions & 2 deletions src/rewrite/Representable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Representable
export yoneda_cache, SchRule, SchRulel, SchRuler, SchRule, SchPBPO

using Catlab, Catlab.CategoricalAlgebra
using Catlab.CategoricalAlgebra.FunctorialDataMigrations: AbstractDataMigration
using ACSets.DenseACSets: constructor
using Catlab.Programs.DiagrammaticPrograms: AST

import ..Utils: Rule
import ..PBPO: PBPORule
Expand Down Expand Up @@ -73,7 +73,7 @@ genuine application conditions because we want to be able to apply the rule
even when the conditions don't hold. (We track them to be able to report user
errors.)
"""
function Rule(rule_schema::DataMigration, y; semantics=:DPO, kw...)
function Rule(rule_schema::AbstractDataMigration, y; semantics=:DPO, kw...)
rule = colimit_representables(rule_schema, y)
L, R, K = [rule_ob_map(rule, Symbol(x)) for x in "LRK"]
l = rule_hom_map(rule, :l, K, L)
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export Rule, ruletype,rewrite, rewrite_match, rewrite_full_output,

using Catlab, Catlab.Theories
using Catlab.CategoricalAlgebra
using Catlab.CategoricalAlgebra.CSets: backtracking_search
using Catlab.CategoricalAlgebra.HomSearch: backtracking_search
import Catlab.CategoricalAlgebra: left, right

using Random
Expand Down
17 changes: 9 additions & 8 deletions src/schedules/Theories.jl
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
module Theories

using Catlab, Catlab.Theories, Catlab.WiringDiagrams
using Catlab.Theories, Catlab.WiringDiagrams
import Catlab.Theories: Ob,Hom,id, create, compose, otimes, , , ∇,□, trace, munit, braid, dom, codom, mmerge
using Catlab.WiringDiagrams.MonoidalDirectedWiringDiagrams: implicit_mmerge


@signature ThTracedMonoidalWithBidiagonals{Ob,Hom} <: ThTracedMonoidalCategory{Ob,Hom} begin
@signature ThTracedMonoidalWithBidiagonals <: ThTracedMonoidalCategory begin
mmerge(A::Ob)::((A ⊗ A) A)
@op (∇) := mmerge
create(A::Ob)::(munit() A)
@op (□) := create
end

@syntax TM{ObExpr,HomExpr} ThTracedMonoidalWithBidiagonals begin
@symbolic_model TM{ObExpr,HomExpr} ThTracedMonoidalWithBidiagonals begin
otimes(A::Ob, B::Ob) = associate_unit(new(A,B), mzero)
otimes(f::Hom, g::Hom) = associate(new(f,g))
function compose(f, g)
function compose(f::Hom, g::Hom)
cf = codom(f); dg = dom(g)
if cf != dg println("$cf\n$dg") end
associate_unit(new(f,g; strict=true), id)
end
end
# compose(f::TM.Hom{S}, g::TM.Hom{T}) where {S,T} = compose(TM.Hom(f),TM.Hom(g))

mmerge(A::Ports{ThTracedMonoidalWithBidiagonals}, n::Int) = implicit_mmerge(A, n)
trace(X::Ports{ThTracedMonoidalWithBidiagonals}, A::Ports{ThTracedMonoidalWithBidiagonals},
B::Ports{ThTracedMonoidalWithBidiagonals}, f::WiringDiagram{ThTracedMonoidalWithBidiagonals}) = trace(X, f)
const ThT = ThTracedMonoidalWithBidiagonals.Meta.T

mmerge(A::Ports{ThT}, n::Int) = implicit_mmerge(A, n)
trace(X::Ports{ThT}, A::Ports{ThT}, B::Ports{ThT},
f::WiringDiagram{ThT}) = trace(X, f)

end # module
4 changes: 2 additions & 2 deletions src/schedules/Wiring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ function singleton(b::AgentBox)::Schedule
end


const WD = WiringDiagram{ThTracedMonoidalWithBidiagonals, StructACSet,
const WD = WiringDiagram{ThTracedMonoidalWithBidiagonals.Meta.T, StructACSet,
StructACSet, AgentBox}

# It would be nice if ⊗ and ⋅ preserved the type of WDs, then we could more
# strongly type our code.
struct Schedule
d::WiringDiagram{<:ThTracedMonoidalWithBidiagonals}
d::WiringDiagram{<:ThTracedMonoidalWithBidiagonals.Meta.T}
x::GATExpr
function Schedule(d,x)
wd = WiringDiagram{ThTracedMonoidalWithBidiagonals,Any,Any,Any}([],[])
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ACSets = "227ef7b5-1206-438b-ac65-934d6da304b8"
AlgebraicRewriting = "725a01d3-f174-5bbd-84e1-b9417bad95d9"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
DataMigrations = "0c4ad18d-0c49-4bc2-90d5-5bca8f00d6ae"
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down

0 comments on commit f7070f9

Please sign in to comment.