diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c3074c8..f82efd1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,8 +18,8 @@ jobs: fail-fast: false matrix: version: - - '1.8' - #- 'nightly' + - '1' + - '1.10' os: - ubuntu-latest - macOS-latest @@ -71,4 +71,4 @@ jobs: using Documenter: DocMeta, doctest using MultilayerGraphs DocMeta.setdocmeta!(MultilayerGraphs, :DocTestSetup, :(using MultilayerGraphs); recursive=true) - doctest(MultilayerGraphs)' \ No newline at end of file + doctest(MultilayerGraphs)' diff --git a/Project.toml b/Project.toml index 3ac6c99..7d78814 100644 --- a/Project.toml +++ b/Project.toml @@ -29,12 +29,12 @@ Distributions = "0.25" Graphs = "1" IterTools = "1.4" MetaGraphs = "0.7, 0.8" -OMEinsum = "0.7, 0.8" +OMEinsum = "0.7, 0.8, 0.9" PrettyTables = "2.2, 3" SimpleTraits = "0.9" SimpleValueGraphs = "0.4" SimpleWeightedGraphs = "1.2" Statistics = "1" -TensorOperations = "3.2, 4" +TensorOperations = "4" WhereTraits = "1" julia = "1.8" diff --git a/src/subgraphs/layer.jl b/src/subgraphs/layer.jl index 66d31c2..f070148 100644 --- a/src/subgraphs/layer.jl +++ b/src/subgraphs/layer.jl @@ -189,7 +189,7 @@ Return a random `Layer`. """ function Layer( name::Symbol, - vertices::Vector{Union{V,N}}, + vertices::Union{Vector{MultilayerVertex{nothing}},Vector{Node}}, ne::Int64, null_graph::G, weighttype::Type{U}; @@ -197,7 +197,7 @@ function Layer( default_edge_weight::Function=(src, dst) -> nothing, default_edge_metadata::Function=(src, dst) -> NamedTuple(), allow_self_loops::Bool=false, -) where {T<:Integer,U<:Real,G<:AbstractGraph{T},V<:MultilayerVertex{nothing},N<:Node} +) where {T<:Integer,U<:Real,G<:AbstractGraph{T}} _nv = length(vertices) @assert( length(unique(vertices)) == _nv, "The argument `vertices` must be a unique list" @@ -211,7 +211,7 @@ function Layer( "The number of required edges, $ne, is greater than the number of edges the provided graph supports i.e. $maxe" ) - vertex_type = @isdefined(V) ? MultilayerVertex : Node + vertex_type = eltype(vertices) edge_list = NTuple{2,MultilayerVertex{nothing}}[] #MultilayerEdge fadjlist = Dict{vertex_type,Vector{vertex_type}}() @@ -250,7 +250,7 @@ function Layer( end # Add the edge to the edge list. Convert it to a MultilayerVertex if a list of Nodes was given as `vertices` - if @isdefined(V) + if vertex_type == MultilayerVertex{nothing} push!(edge_list, (rand_vertex_1, rand_vertex_2)) else push!(edge_list, (MV(rand_vertex_1), MV(rand_vertex_2))) diff --git a/src/tensorsfactorizations.jl b/src/tensorsfactorizations.jl index f0ddf2b..a92319d 100644 --- a/src/tensorsfactorizations.jl +++ b/src/tensorsfactorizations.jl @@ -140,7 +140,7 @@ function to_matrix(A, a, b; return_tensor_shape=false) # Permute the indices of A to the right order perm = vcat(a, b) - A = tensorcopy(A, collect(1:ndims(A)), perm) + A = tensorcopy(collect(1:ndims(A)), A, perm) # The lists shp_a and shp_b list the dimensions of the bonds in a and b shp = size(A) shp_a = shp[1:length(a)] diff --git a/test/Project.toml b/test/Project.toml index 4cf4c10..83ecd80 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -10,3 +10,6 @@ SimpleValueGraphs = "b43c691f-cac2-5415-8122-396fe16a49fc" SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +Agents = "6" diff --git a/test/agents_jl_integration.jl b/test/agents_jl_integration.jl index 3e1ab1c..672ac43 100644 --- a/test/agents_jl_integration.jl +++ b/test/agents_jl_integration.jl @@ -11,23 +11,17 @@ graph = MultilayerGraph(all_layers_u, all_interlayers_u) new_value::Float64 end # Instantiate the agent -function EigenAgent(id, pos; initial_opinion::Float64) - return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0) -end -# Define the agent-based model -EigenABM = ABM(EigenAgent, GraphSpace(graph)) -# Add agents to the ABM so that agent i is located in vertex i -for (i, mv) in enumerate(mv_vertices(graph)) - initial_opinion = 1.0 - add_agent!(i, EigenABM; initial_opinion=initial_opinion) -end +# function EigenAgent(; id, pos, initial_opinion::Float64) +# return EigenAgent(id, pos, initial_opinion, initial_opinion, -1.0) +# end # Define the individual-level dynamics (micro-dynamics) function agent_step!(agent::EigenAgent, model) agent.previous_value = agent.old_value - return agent.new_value = sum([ + agent.new_value = sum([ outneighbor_agent.old_value for outneighbor_agent in nearby_agents(agent, model; neighbor_type=:all) ]) + return agent end # Define the system-level dynamics (macro-dynamics) function model_step!(model) @@ -37,6 +31,20 @@ function model_step!(model) agent.old_value = agent.new_value end end +# Define the agent-based model +EigenABM = ABM(EigenAgent, GraphSpace(graph); agent_step!, model_step!) +# Add agents to the ABM so that agent i is located in vertex i +for (i, mv) in enumerate(mv_vertices(graph)) + initial_opinion = 1.0 + add_agent!( + i, + EigenAgent, + EigenABM; + previous_value=initial_opinion, + old_value=initial_opinion, + new_value=-1.0, + ) +end # Set the rule to stop the model simulation function terminate(model, s) # println(s, typeof(s)) @@ -49,14 +57,12 @@ function terminate(model, s) end end # Simulate the model -agent_data, _ = run!( - EigenABM, agent_step!, model_step!, terminate; adata=[:new_value], when=terminate -) +agent_data, _ = run!(EigenABM, terminate; adata=[:new_value], when=terminate) # Compute the eigenvector centrality of the surrounding multilayer graph eig_centr_swm, err_swm = eigenvector_centrality( - EigenABM.space.graph; weighted=false, tol=1e-18, norm="null" + abmspace(EigenABM).graph; weighted=false, tol=1e-18, norm="null" ) -for (val_1, val_2) in zip(eig_centr_swm, agent_data.new_value) - @test val_1 ≈ val_2 +for a in allagents(EigenABM) + @test a.new_value ≈ eig_centr_swm[a.id] end