File size: 5,214 Bytes
29fc4be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
diff --git a/test/categorical_algebra/CatElements.jl b/test/categorical_algebra/CatElements.jl
index 21b9ef184..2363f4efb 100644
--- a/test/categorical_algebra/CatElements.jl
+++ b/test/categorical_algebra/CatElements.jl
@@ -1,6 +1,63 @@
 module TestCatElements
 using Test
 using Catlab.GATs, Catlab.Theories, Catlab.Graphs, Catlab.CategoricalAlgebra
+import Catlab.CategoricalAlgebra.CSets: ACSetTransformation
+import ACSets
+import ACSets: ACSet, acset_schema, add_parts!, codom_parts, dom_parts,
+  has_part, has_subpart, incident, IntParts, nparts, parts, set_subpart!,
+  subpart
+
+struct WrappedGraph <: ACSet{IntParts}
+  data::Graph
+end
+WrappedGraph() = WrappedGraph(Graph())
+
+acset_schema(::WrappedGraph) = acset_schema(Graph())
+nparts(g::WrappedGraph, p::Symbol) = nparts(g.data, p)
+parts(g::WrappedGraph, p::Symbol) = parts(g.data, p)
+add_parts!(g::WrappedGraph, p::Symbol, n::Int) = add_parts!(g.data, p, n)
+set_subpart!(g::WrappedGraph, part::Int, f::Symbol, val) =
+  set_subpart!(g.data, part, f, val)
+subpart(g::WrappedGraph, f::Symbol) = subpart(g.data, f)
+subpart(g::WrappedGraph, part, f::Symbol) = subpart(g.data, part, f)
+subpart(g::WrappedGraph, names::Tuple{Vararg{Symbol}}) = subpart(g.data, names)
+subpart(g::WrappedGraph, part, names::Tuple{Vararg{Symbol}}) =
+  subpart(g.data, part, names)
+dom_parts(g::WrappedGraph, f::Symbol) = dom_parts(g.data, f)
+codom_parts(g::WrappedGraph, f::Symbol) = codom_parts(g.data, f)
+has_part(g::WrappedGraph, p::Symbol) = has_part(g.data, p)
+has_subpart(g::WrappedGraph, f::Symbol) = has_subpart(g.data, f)
+incident(g::WrappedGraph, part, f::Symbol) = incident(g.data, part, f)
+incident(g::WrappedGraph, part, names::Tuple{Vararg{Symbol}}) =
+  incident(g.data, part, names)
+ACSetTransformation(components, X::WrappedGraph, Y::WrappedGraph) =
+  ACSetTransformation(components, X.data, Y.data)
+
+@testset "Custom ACSet category-of-elements APIs" begin
+  arr = path_graph(Graph, 2)
+  wrapped_arr = WrappedGraph(arr)
+  @test elements(wrapped_arr) == elements(arr)
+
+  wrapped_two_edge = WrappedGraph(path_graph(Graph, 3))
+  el_wrapped_two_edge = elements(wrapped_two_edge)
+  @test nparts(el_wrapped_two_edge, :El) == 5
+  @test nparts(el_wrapped_two_edge, :Arr) == 4
+
+  round_trip_wrapped = inverse_elements(el_wrapped_two_edge, WrappedGraph())
+  @test nparts(round_trip_wrapped, :V) == 3
+  @test nparts(round_trip_wrapped, :E) == 2
+  @test subpart(round_trip_wrapped, :src) == [1, 2]
+  @test subpart(round_trip_wrapped, :tgt) == [2, 3]
+
+  graph_two_edge = path_graph(Graph, 3)
+  graph_hom = homomorphism(arr, graph_two_edge; initial=(V=[1, 2], E=[1]))
+  el_hom = elements(graph_hom)
+  inv_wrapped_hom = inverse_elements(el_hom, WrappedGraph())
+  @test nparts(dom(inv_wrapped_hom), :E) == 1
+  @test nparts(codom(inv_wrapped_hom), :E) == 2
+  @test collect(force(inv_wrapped_hom)[:V]) == [1, 2]
+  @test collect(force(inv_wrapped_hom)[:E]) == [1]
+end
 
 arr = @acset Graph begin
   V = 2
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+set -uo pipefail
+cd /testbed
+
+
+set -e
+pkg_instantiate() {
+  if ! julia --project=. -e 'using Pkg; Pkg.instantiate()' > /tmp/fixture_pkg_instantiate.log 2>&1; then
+    cat /tmp/fixture_pkg_instantiate.log
+    return 1
+  fi
+}
+
+pkg_instantiate
+ACSETS_DIR=$(julia --project=. -e 'using ACSets; println(dirname(dirname(pathof(ACSets))))')
+sed -i 's/abstract type SimpleACSet{PT} <: ACSet{PT} end/abstract type SimpleACSet{PT<:PartsType} <: ACSet{PT} end/' "$ACSETS_DIR/src/DenseACSets.jl"
+sed -i 's/struct DynamicACSet{PT} <: SimpleACSet{PT}/struct DynamicACSet{PT<:PartsType} <: SimpleACSet{PT}/' "$ACSETS_DIR/src/DenseACSets.jl"
+rm -rf /root/.julia/compiled/v1.10/ACSets /root/.julia/compiled/v1.10/Catlab
+
+
+instantiate() {
+  pkg_instantiate
+}
+
+case "${1:-}" in
+  base)
+    instantiate
+    awk '
+      /^@testset "Custom ACSet category-of-elements APIs" begin$/ { skip=1; next }
+      skip && /^end$/ { skip=0; next }
+      !skip { print }
+    ' test/categorical_algebra/CatElements.jl > /tmp/cat_elements_base.jl
+    julia --project=. /tmp/cat_elements_base.jl
+    ;;
+  new)
+    instantiate
+    printf '%s\n' 'module FixtureDynamicCatElements' > /tmp/cat_elements_dynamic.jl
+    printf '%s\n' 'using Test' >> /tmp/cat_elements_dynamic.jl
+    printf '%s\n' 'using Catlab.GATs, Catlab.Theories, Catlab.Graphs, Catlab.CategoricalAlgebra' >> /tmp/cat_elements_dynamic.jl
+    set +e
+    awk '
+      /^import Catlab.CategoricalAlgebra.CSets: ACSetTransformation$/ { capture=1 }
+      capture && /^arr = @acset Graph begin$/ { found=1; exit }
+      capture { print }
+      END { if (!found) exit 3 }
+    ' test/categorical_algebra/CatElements.jl >> /tmp/cat_elements_dynamic.jl
+    awk_status=$?
+    set -e
+    printf '%s\n' 'end # module' >> /tmp/cat_elements_dynamic.jl
+    if [ "$awk_status" -ne 0 ]; then
+      echo "Custom ACSet testset not found in CatElements test file"
+      exit "$awk_status"
+    fi
+    julia --project=. /tmp/cat_elements_dynamic.jl
+    ;;
+  *)
+    echo "usage: $0 base|new"
+    exit 2
+    ;;
+esac