Skip to content

Commit

Permalink
added Gatlab dependency
Browse files Browse the repository at this point in the history
theories up to monoidal working

all theories reporting for duty!

basic graphs work!

graphs working, progress on categoricalalgebra

fixing conflicting function declarations

choo choo that the sound of the integration train
  • Loading branch information
olynch committed Oct 10, 2023
1 parent 1874704 commit b625310
Show file tree
Hide file tree
Showing 49 changed files with 1,498 additions and 2,479 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ version = "0.15.5"

[deps]
ACSets = "227ef7b5-1206-438b-ac65-934d6da304b8"
AlgebraicInterfaces = "23cfdc9f-0504-424a-be1f-4892b28e2f0c"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
CompTime = "0fb5dd42-039a-4ca4-a1d7-89a96eae6d39"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
GATlab = "f0ffcf3b-d13a-433e-917c-cc44ccf5ead2"
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
Expand Down
14 changes: 6 additions & 8 deletions src/Catlab.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ module Catlab

using Reexport

include("gats/GATs.jl")
include("theories/Theories.jl")
include("categorical_algebra/ACSetsGATsInterop.jl")
include("graphs/Graphs.jl")
include("categorical_algebra/CategoricalAlgebra.jl")
include("wiring_diagrams/WiringDiagrams.jl")
include("graphics/Graphics.jl")
include("programs/Programs.jl")
# include("wiring_diagrams/WiringDiagrams.jl")
# include("graphics/Graphics.jl")
# include("programs/Programs.jl")

@reexport using .GATs
@reexport using .Theories
@reexport using .Graphs
@reexport using .CategoricalAlgebra
@reexport using .WiringDiagrams
@reexport using .Graphics
@reexport using .Programs
# @reexport using .WiringDiagrams
# @reexport using .Graphics
# @reexport using .Programs

end
47 changes: 32 additions & 15 deletions src/categorical_algebra/ACSetsGATsInterop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ using DataStructures: OrderedDict
using ACSets
import ACSets: Schema

using ...GATs, ...Theories
import ...GATs: Presentation
using GATlab
import GATlab: Presentation
using .ThCategory

using MLStyle

# Schema <-> presentation
#########################
Expand All @@ -22,6 +25,21 @@ function Schema(p::Presentation)
BasicSchema(obs,homs,attrtypes,attrs)
end

function Schema(c::GATContext)
obs, attrtypes = Symbol[], Symbol[]
homs, attrs = Tuple{Symbol, Symbol, Symbol}[], Tuple{Symbol, Symbol, Symbol}[]
for binding in p.scope
type = getvalue(binding)
@match (nameof(type.body.head), type.body.args...) begin
(:Ob,) => push!(obs, nameof(binding))
(:Hom, x, y) => push!(homs, nameof.((binding, x.body, y.body)))
(:AttrType,) => push!(attrtypes, nameof(binding))
(:Attr, x, y) => push!(attrs, nameof.((binding, x.body, y.body)))
end
end
BasicSchema(obs,homs,attrtypes,attrs)
end

function Presentation(::Type{S}) where S <: TypeLevelBasicSchema{Symbol}
Presentation(Schema(S))
end
Expand All @@ -34,17 +52,16 @@ function Presentation(::Type{<:StructACSet{S}}) where S <: TypeLevelBasicSchema{
Presentation(Schema(S))
end

function Presentation(s::BasicSchema{Symbol})
pres = Presentation(FreeSchema)
obs = OrderedDict(x => Ob(FreeSchema.Ob, x) for x in Schemas.objects(s))
attrtypes = OrderedDict(x => AttrType(FreeSchema.AttrType, x) for x in Schemas.attrtypes(s))
homs = [Hom(f, obs[d], obs[c]) for (f,d,c) in Schemas.homs(s)]
attrs = [Attr(f, obs[d], attrtypes[c]) for (f,d,c) in Schemas.attrs(s)]

foreach(gens -> add_generators!(pres, gens), (values(obs), homs, values(attrtypes), attrs))
return pres
end
# function Presentation(s::BasicSchema{Symbol})
# pres = Presentation(FreeSchema)
# obs = OrderedDict(x => Ob(FreeSchema.Ob, x) for x in Schemas.objects(s))
# attrtypes = OrderedDict(x => AttrType(FreeSchema.AttrType, x) for x in Schemas.attrtypes(s))
# homs = [Hom(f, obs[d], obs[c]) for (f,d,c) in Schemas.homs(s)]
# attrs = [Attr(f, obs[d], attrtypes[c]) for (f,d,c) in Schemas.attrs(s)]

# foreach(gens -> add_generators!(pres, gens), (values(obs), homs, values(attrtypes), attrs))
# return pres
# end

function DenseACSets.struct_acset(name::Symbol, parent, p::Presentation;
index::Vector=[], unique_index::Vector=[])
Expand Down Expand Up @@ -79,14 +96,14 @@ end
JSONACSets.generate_json_acset_schema(pres::Presentation) =
generate_json_acset_schema(Schema(pres))

JSONACSets.parse_json_acset_schema(::Type{Presentation{ThSchema,Symbol}},
JSONACSets.parse_json_acset_schema(::Type{Presentation},
data::AbstractDict) =
Presentation(parse_json_acset_schema(BasicSchema, data))
JSONACSets.parse_json_acset_schema(data) =
parse_json_acset_schema(Presentation{ThSchema,Symbol}, data)
parse_json_acset_schema(Presentation, data)

JSONACSets.read_json_acset_schema(fname::AbstractString) =
read_json_acset_schema(Presentation{ThSchema,Symbol}, fname)
read_json_acset_schema(Presentation, fname)

# ACSet <-> GAT exprs
#####################
Expand Down
7 changes: 5 additions & 2 deletions src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ using ACSets.Columns
using ACSets.DenseACSets: indices, unique_indices, attr_type, attrtype_type,
datatypes, constructor

using ...GATs, ...Graphs.BasicGraphs
using ...Theories: ThCategory, Hom, Ob, Attr, AttrType
using GATlab
using ...Graphs.BasicGraphs
using ...Theories
import ...Theories: ob, hom, dom, codom, compose, , id,
meet, , join, , top, ⊤, bottom, ⊥, ,

Expand Down Expand Up @@ -707,6 +708,8 @@ end
####################

@instance ThCategory{ACSet, ACSetTransformation} begin
@import Ob, Hom

dom::ACSetTransformation) = α.dom
codom::ACSetTransformation) = α.codom

Expand Down
3 changes: 2 additions & 1 deletion src/categorical_algebra/CatElements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export SchElements, AbstractElements, Elements, elements, inverse_elements

using DataStructures: OrderedDict

using ...GATs, ...Theories
using GATlab
using ...Theories
using ..CSets, ..FinSets, ..HomSearch

@present SchElements(FreeSchema) begin
Expand Down
27 changes: 9 additions & 18 deletions src/categorical_algebra/Categories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export Category, Cat, TypeCat, Functor, Transformation, dom, codom, compose, id,

using StructEquality

using ...GATs
import ...Theories: ThCategory2, ob, hom, dom, codom, compose, , , id,
composeH, *
using GATlab
import GATlab: op
import ...Theories: ThCategory2, ob, hom
import .ThCategory2: dom, codom, compose, , , id, composeH, *

# Categories
############
Expand Down Expand Up @@ -281,34 +282,24 @@ const IdIdTransformation{C<:Cat} = IdentityTransformation{C,C,IdentityFunctor{C}
codom(F::Functor) = F.codom
id(C::Cat) = IdentityFunctor(C)

function compose(F::Functor, G::Functor; strict::Bool=true)
!strict || codom(F) == dom(G) ||
error("Domain mismatch in composition $F$G")
function compose(F::Functor, G::Functor)
compose_id(F, G)
end

dom::Transformation) = α.dom
codom::Transformation) = α.codom
id(F::Functor) = IdentityTransformation(F)

function compose::Transformation, β::Transformation; strict::Bool=true)
!strict || codom(α) == dom(β) ||
error("Domain mismatch in vertical composition ")
function compose::Transformation, β::Transformation)
compose_id(α, β)
end
function composeH::Transformation, β::Transformation; strict::Bool=true)
!strict || codom_ob(α) == dom_ob(β) ||
error("Domain mismatch in horizontal composition * ")
function composeH::Transformation, β::Transformation)
composeH_id(α, β)
end
function composeH::Transformation, H::Functor; strict::Bool=true)
!strict || codom_ob(α) == dom(H) ||
error("Domain mismatch in whiskering * $H")
function composeH::Transformation, H::Functor)
composeH_id(α, H)
end
function composeH(F::Functor, β::Transformation; strict::Bool=true)
!strict || codom(F) == dom_ob(β) ||
error("Domain mismatch in whiskering $F * ")
function composeH(F::Functor, β::Transformation)
composeH_id(F, β)
end
end
Expand Down
5 changes: 3 additions & 2 deletions src/categorical_algebra/Chase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module Chase
export chase

using ACSets.DenseACSets: datatypes
using ...GATs, ...Theories
using GATlab
using ...Theories
using ..CSets, ..HomSearch, ..FinSets, ..FinCats, ..Limits, ..FreeDiagrams
using ..FinCats: FinCatPresentation
import ..Limits: universal
Expand Down Expand Up @@ -467,7 +468,7 @@ end
Preserves the original name of the inputs if it is unambiguous, otherwise
disambiguates with index in original input. E.g. (A,B)⊔(B,C) → (A,B#1,B#2,C)
"""
function coproduct_fincat(Xs::AbstractVector{<: FinCatPresentation{ThSchema}}; kw...)
function coproduct_fincat(Xs::AbstractVector{<:FinCatPresentation{ThSchema.Meta.T}}; kw...)
Xps = [X.presentation for X in Xs]
# Collect all generators and identify conflicting names
cnflobs, cnflats, cnflhoms, cnflattrs = map([:Ob,:AttrType,:Hom,:Attr]) do x
Expand Down
2 changes: 1 addition & 1 deletion src/categorical_algebra/CommutativeDiagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export SquareDiagram, SquareOb, SquareHom, ob, hom, dom, codom, src, tgt,
using StaticArrays: StaticVector, SVector
using StructEquality

using ...GATs
using GATlab
using ...Theories: ThDoubleCategory
import ...Theories: ob, hom, dom, codom, src, tgt, top, bottom,
compose, id, pcompose, pid, , *
Expand Down
4 changes: 2 additions & 2 deletions src/categorical_algebra/Diagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export Diagram, SimpleDiagram, DiagramHom, id, op, co,

using StructEquality

using ...GATs
using GATlab
import ...Theories: dom, codom, id, compose, , , munit
using ...Theories: ThCategory, composeH, FreeSchema
import ..Categories: ob_map, hom_map, op, co
Expand Down Expand Up @@ -309,4 +309,4 @@ isnothing(dom_shape) ? DiagramHom{op}([Pair(j, f)], d, d′) :
DiagramHom{op}(Dict(only(ob_generators(dom(diagram(d′)))) => Pair(j, f)),d,d′)
end

end
end
25 changes: 12 additions & 13 deletions src/categorical_algebra/FinCats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ using StaticArrays: SVector
using DataStructures: IntDisjointSets, in_same_set, num_groups

using ACSets
using ...GATs
import ...GATs: equations
using GATlab
import GATlab: equations
using ...Theories: ThCategory, ThSchema, ThPointedSetCategory, ThPointedSetSchema,
ObExpr, HomExpr, AttrExpr, AttrTypeExpr, FreeSchema, FreePointedSetCategory, zeromap
import ...Theories: dom, codom, id, compose, ,
using ...Graphs
import ...Graphs: edges, src, tgt, enumerate_paths
@reexport using ..Categories
import ..Categories: CatSize, ob, hom, ob_map, hom_map, component, op

# Categories
############

Expand Down Expand Up @@ -305,18 +304,18 @@ function FinCatPresentation(pres::Presentation{T}) where T
S = pres.syntax
FinCatPresentation{T,S.Ob,S.Hom}(pres)
end
function FinCatPresentation(pres::Presentation{ThSchema})
function FinCatPresentation(pres::Presentation{ThSchema.Meta.T})
S = pres.syntax
Ob = Union{S.Ob, S.AttrType}
Hom = Union{S.Hom, S.Attr, S.AttrType}
FinCatPresentation{ThSchema,Ob,Hom}(pres)
FinCatPresentation{ThSchema.Meta.T,Ob,Hom}(pres)
end

function FinCatPresentation(pres::Presentation{ThPointedSetSchema})
function FinCatPresentation(pres::Presentation{ThPointedSetSchema.Meta.T})
S = pres.syntax
Ob = Union{S.Ob, S.AttrType}
Hom = Union{S.Hom, S.Attr, S.AttrType}
FinCatPresentation{ThPointedSetSchema,Ob,Hom}(pres)
FinCatPresentation{ThPointedSetSchema.Meta.T,Ob,Hom}(pres)
end
"""
Computes the graph generating a finitely
Expand All @@ -328,12 +327,12 @@ in the resulting graph.
presentation(C::FinCatPresentation) = C.presentation

ob_generators(C::FinCatPresentation) = generators(presentation(C), :Ob)
ob_generators(C::Union{FinCatPresentation{ThSchema},FinCatPresentation{ThPointedSetSchema}}) = let P = presentation(C)
ob_generators(C::Union{FinCatPresentation{ThSchema.Meta.T},FinCatPresentation{ThPointedSetSchema.Meta.T}}) = let P = presentation(C)
vcat(generators(P, :Ob), generators(P, :AttrType))
end

hom_generators(C::FinCatPresentation) = generators(presentation(C), :Hom)
hom_generators(C::Union{FinCatPresentation{ThSchema},FinCatPresentation{ThPointedSetSchema}}) = let P = presentation(C)
hom_generators(C::Union{FinCatPresentation{ThSchema.Meta.T},FinCatPresentation{ThPointedSetSchema.Meta.T}}) = let P = presentation(C)
vcat(generators(P, :Hom), generators(P, :Attr))
end
equations(C::FinCatPresentation) = equations(presentation(C))
Expand All @@ -348,7 +347,7 @@ hom_generator_name(C::FinCatPresentation, f::GATExpr{:generator}) = first(f)

ob(C::FinCatPresentation, x::GATExpr) =
gat_typeof(x) == :Ob ? x : error("Expression $x is not an object")
ob(C::Union{FinCatPresentation{ThSchema},FinCatPresentation{ThPointedSetSchema}}, x::GATExpr) =
ob(C::Union{FinCatPresentation{ThSchema.Meta.T},FinCatPresentation{ThPointedSetSchema.Meta.T}}, x::GATExpr) =
gat_typeof(x) (:Ob, :AttrType) ? x :
error("Expression $x is not an object or attribute type")

Expand All @@ -357,12 +356,12 @@ hom(C::FinCatPresentation, fs::AbstractVector) =
mapreduce(f -> hom(C, f), compose, fs)
hom(C::FinCatPresentation, f::GATExpr) =
gat_typeof(f) == :Hom ? f : error("Expression $f is not a morphism")
hom(::Union{FinCatPresentation{ThSchema},FinCatPresentation{ThPointedSetSchema}}, f::GATExpr) =
hom(::Union{FinCatPresentation{ThSchema.Meta.T},FinCatPresentation{ThPointedSetSchema.Meta.T}}, f::GATExpr) =
gat_typeof(f) (:Hom, :Attr, :AttrType) ? f :
error("Expression $f is not a morphism or attribute")

id(C::FinCatPresentation{ThSchema}, x::AttrTypeExpr) = x
compose(C::FinCatPresentation{ThSchema}, f::AttrTypeExpr, g::AttrTypeExpr) =
id(C::FinCatPresentation{ThSchema.Meta.T}, x::AttrTypeExpr) = x
compose(C::FinCatPresentation{ThSchema.Meta.T}, f::AttrTypeExpr, g::AttrTypeExpr) =
(f == g) ? f : error("Invalid composite of attribute type identities: $f != $g")

function Base.show(io::IO, C::FinCatPresentation)
Expand Down
2 changes: 1 addition & 1 deletion src/categorical_algebra/FinRelations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export BoolRig, FinRel, FinRelation, FinRelationCallable, FinRelationMatrix,
import Base: +, *
using StructEquality

using ...GATs
using GATlab
using ...Theories: ThDistributiveBicategoryRelations
import ...Theories: dom, codom, id, compose, , , dagger, dunit, dcounit,
otimes, , munit, braid, oplus, , mzero, swap,
Expand Down
5 changes: 3 additions & 2 deletions src/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import Tables, PrettyTables

using ACSets
@reexport using ..Sets
using ...GATs, ...Theories, ...Graphs
using GATlab
using ...Theories, ...Graphs
using ..FinCats, ..FreeDiagrams, ..Limits, ..Subobjects
import ...Theories: Ob, meet, , join, , top, ⊤, bottom, ⊥, , dom, codom,
compose
Expand Down Expand Up @@ -1464,4 +1465,4 @@ join(A::SubFinSet{Int}, B::SubFinSet{Int}, ::SubOpBoolean) =
top(X::FinSet{Int}, ::SubOpBoolean) = SubFinSet(trues(length(X)))
bottom(X::FinSet{Int}, ::SubOpBoolean) = SubFinSet(falses(length(X)))

end
end
5 changes: 3 additions & 2 deletions src/categorical_algebra/FreeDiagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ using StructEquality
using StaticArrays: StaticVector, SVector

using ACSets
using ...GATs, ...Theories, ...Graphs, ..FinCats
import ...Theories: ob, hom, dom, codom
using GATlab
using ...Theories, ...Graphs, ..FinCats
import AlgebraicInterfaces: ob, hom, dom, codom
import ..FinCats: FreeCatGraph, FinDomFunctor, collect_ob, collect_hom

# Diagram interface
Expand Down
4 changes: 2 additions & 2 deletions src/categorical_algebra/FunctorialDataMigrations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ using MLStyle: @match

using ACSets
using ACSets.DenseACSets: constructor, datatypes
using ...GATs
using GATlab
using ...Theories: ob, hom, dom, codom, attr, AttrTypeExpr,
using ..Categories, ..FinCats, ..Limits, ..Diagrams, ..FinSets, ..CSets, ..HomSearch
using ...Graphs, ..FreeDiagrams
import ..Categories: ob_map, hom_map
import ...GATs: functor
import GATlab: functor
using ..FinCats: make_map, mapvals, presentation_key
using ..Chase: collage, crel_type, pres_to_eds, add_srctgt, chase
using ..FinSets: VarSet
Expand Down
Loading

0 comments on commit b625310

Please sign in to comment.