Skip to content

Commit 43021fc

Browse files
committed
Fix test failures
1 parent 2598d19 commit 43021fc

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Distributions = "0.25"
2929
Graphs = "1"
3030
IterTools = "1.4"
3131
MetaGraphs = "0.7, 0.8"
32-
OMEinsum = "0.7, 0.8"
32+
OMEinsum = "0.7, 0.8, 0.9"
3333
PrettyTables = "2.2, 3"
3434
SimpleTraits = "0.9"
3535
SimpleValueGraphs = "0.4"
3636
SimpleWeightedGraphs = "1.2"
3737
Statistics = "1"
38-
TensorOperations = "3.2, 4"
38+
TensorOperations = "4"
3939
WhereTraits = "1"
4040
julia = "1.8"

src/subgraphs/layer.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ Return a random `Layer`.
189189
"""
190190
function Layer(
191191
name::Symbol,
192-
vertices::Vector{Union{V,N}},
192+
vertices::Union{Vector{MultilayerVertex{nothing}},Vector{Node}},
193193
ne::Int64,
194194
null_graph::G,
195195
weighttype::Type{U};
196196
default_vertex_metadata::Function=mv -> NamedTuple(),
197197
default_edge_weight::Function=(src, dst) -> nothing,
198198
default_edge_metadata::Function=(src, dst) -> NamedTuple(),
199199
allow_self_loops::Bool=false,
200-
) where {T<:Integer,U<:Real,G<:AbstractGraph{T},V<:MultilayerVertex{nothing},N<:Node}
200+
) where {T<:Integer,U<:Real,G<:AbstractGraph{T}}
201201
_nv = length(vertices)
202202
@assert(
203203
length(unique(vertices)) == _nv, "The argument `vertices` must be a unique list"
@@ -211,7 +211,7 @@ function Layer(
211211
"The number of required edges, $ne, is greater than the number of edges the provided graph supports i.e. $maxe"
212212
)
213213

214-
vertex_type = @isdefined(V) ? MultilayerVertex : Node
214+
vertex_type = eltype(vertices)
215215

216216
edge_list = NTuple{2,MultilayerVertex{nothing}}[] #MultilayerEdge
217217
fadjlist = Dict{vertex_type,Vector{vertex_type}}()
@@ -250,7 +250,7 @@ function Layer(
250250
end
251251

252252
# Add the edge to the edge list. Convert it to a MultilayerVertex if a list of Nodes was given as `vertices`
253-
if @isdefined(V)
253+
if vertex_type == MultilayerVertex{nothing}
254254
push!(edge_list, (rand_vertex_1, rand_vertex_2))
255255
else
256256
push!(edge_list, (MV(rand_vertex_1), MV(rand_vertex_2)))

src/tensorsfactorizations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function to_matrix(A, a, b; return_tensor_shape=false)
140140

141141
# Permute the indices of A to the right order
142142
perm = vcat(a, b)
143-
A = tensorcopy(A, collect(1:ndims(A)), perm)
143+
A = tensorcopy(collect(1:ndims(A)), A, perm)
144144
# The lists shp_a and shp_b list the dimensions of the bonds in a and b
145145
shp = size(A)
146146
shp_a = shp[1:length(a)]

test/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ SimpleValueGraphs = "b43c691f-cac2-5415-8122-396fe16a49fc"
1010
SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
1111
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1212
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
13+
14+
[compat]
15+
Agents = "6"

test/agents_jl_integration.jl

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@ graph = MultilayerGraph(all_layers_u, all_interlayers_u)
1111
new_value::Float64
1212
end
1313
# Instantiate the agent
14-
function EigenAgent(id, pos; initial_opinion::Float64)
15-
return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0)
16-
end
17-
# Define the agent-based model
18-
EigenABM = ABM(EigenAgent, GraphSpace(graph))
19-
# Add agents to the ABM so that agent i is located in vertex i
20-
for (i, mv) in enumerate(mv_vertices(graph))
21-
initial_opinion = 1.0
22-
add_agent!(i, EigenABM; initial_opinion=initial_opinion)
23-
end
14+
# function EigenAgent(; id, pos, initial_opinion::Float64)
15+
# return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0)
16+
# end
2417
# Define the individual-level dynamics (micro-dynamics)
2518
function agent_step!(agent::EigenAgent, model)
2619
agent.previous_value = agent.old_value
27-
return agent.new_value = sum([
20+
agent.new_value = sum([
2821
outneighbor_agent.old_value for
2922
outneighbor_agent in nearby_agents(agent, model; neighbor_type=:all)
3023
])
24+
return agent
3125
end
3226
# Define the system-level dynamics (macro-dynamics)
3327
function model_step!(model)
@@ -37,6 +31,20 @@ function model_step!(model)
3731
agent.old_value = agent.new_value
3832
end
3933
end
34+
# Define the agent-based model
35+
EigenABM = ABM(EigenAgent, GraphSpace(graph); agent_step!, model_step!)
36+
# Add agents to the ABM so that agent i is located in vertex i
37+
for (i, mv) in enumerate(mv_vertices(graph))
38+
initial_opinion = 1.0
39+
add_agent!(
40+
i,
41+
EigenAgent,
42+
EigenABM;
43+
previous_value=initial_opinion,
44+
old_value=initial_opinion,
45+
new_value=-1.0,
46+
)
47+
end
4048
# Set the rule to stop the model simulation
4149
function terminate(model, s)
4250
# println(s, typeof(s))
@@ -49,14 +57,12 @@ function terminate(model, s)
4957
end
5058
end
5159
# Simulate the model
52-
agent_data, _ = run!(
53-
EigenABM, agent_step!, model_step!, terminate; adata=[:new_value], when=terminate
54-
)
60+
agent_data, _ = run!(EigenABM, terminate; adata=[:new_value], when=terminate)
5561
# Compute the eigenvector centrality of the surrounding multilayer graph
5662
eig_centr_swm, err_swm = eigenvector_centrality(
57-
EigenABM.space.graph; weighted=false, tol=1e-18, norm="null"
63+
abmspace(EigenABM).graph; weighted=false, tol=1e-18, norm="null"
5864
)
5965

60-
for (val_1, val_2) in zip(eig_centr_swm, agent_data.new_value)
61-
@test val_1 val_2
66+
for a in allagents(EigenABM)
67+
@test a.new_value eig_centr_swm[a.id]
6268
end

0 commit comments

Comments
 (0)