Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreza committed Jun 2, 2024
1 parent b64a837 commit 628a25b
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 308 deletions.
8 changes: 0 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ authors = ["Andre Souza <[email protected]>"]
version = "0.1.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
MarkovChainHammer = "38c40fd0-bccb-4723-b30d-b2caea0ad8d9"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
ParallelKMeans = "42b8e9d4-006b-409a-8472-7f34b3fb58af"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
Expand All @@ -27,12 +22,9 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
[compat]
Documenter = "0.27"
DocumenterTools = "0.1"
GLMakie = "0.9"
GraphMakie = "0.5"
IncompleteLU = "0.2"
LinearSolve = "2.22"
MarkovChainHammer = "0.0"
NetworkLayout = "0.4"
ParallelKMeans = "1.1"
PrecompileTools = "1.2"
ProgressBars = "1.5"
Expand Down
7 changes: 7 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
MarkovChainHammer = "38c40fd0-bccb-4723-b30d-b2caea0ad8d9"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
StateSpacePartitions = "5427e241-e665-444a-8288-8739a7fd2cc0"
6 changes: 3 additions & 3 deletions examples/noisy_lorenz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ include("timestepping_utils.jl")
include("visualization_utils.jl")
Random.seed!(1234)

dt = 0.001
iterations = 10^8
dt = 0.01
iterations = 10^5

trajectory = zeros(3, iterations)
trajectory[:, 1] .= [14.0, 20.0, 27.0]
Expand All @@ -19,4 +19,4 @@ method = Tree(false, 0.001)
state_space_partitions = StateSpacePartition(trajectory; method = method)

length(union(state_space_partitions.partitions))
# visualize_koopman_mode(trajectory, state_space_partitions.partitions, colormap1 = :balance, mode = 4)
visualize_koopman_mode(trajectory, state_space_partitions.partitions, colormap1 = :balance, mode = 4)
146 changes: 0 additions & 146 deletions src/Architectures.jl

This file was deleted.

29 changes: 9 additions & 20 deletions src/StateSpacePartitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ export StateSpacePartition
using ProgressBars
using Reexport, PrecompileTools

include("Architectures.jl")
include("Trees/Trees.jl")

using .Architectures
using .Trees

# import StateSpacePartitions.Trees: unstructured_tree, UnstructuredTree, determine_partition, Tree
Expand All @@ -18,11 +16,8 @@ struct StateSpacePartition{E, P}
end

function StateSpacePartition(trajectory;
architecture = CPU(),
method = Tree(),
chunk_size = size(trajectory)[2],
cells = nothing,
chunked = false,
override = false)

@info "determine partitioning function "
Expand All @@ -34,27 +29,21 @@ function StateSpacePartition(trajectory;
@error "cells must be an integer"
end

embedding = determine_partition(trajectory, method; override = override, architecture)
embedding = determine_partition(trajectory, method; override = override)
partitions = zeros(Int64, size(trajectory)[2])

if chunked
@info "computing (chunked) partition trajectory"
chunked_partitions = ChunkedArray(partitions, architecture; chunk_size)
chunked_trajectory = ChunkedArray(trajectory, architecture; chunk_size)
embedding(chunked_partitions, chunked_trajectory)
return StateSpacePartition(embedding, chunked_partitions)
else
@info "computing partition trajectory"
for (i, state) in ProgressBar(enumerate(eachcol(trajectory)))
partitions[i] = embedding(state)
end
return StateSpacePartition(embedding, partitions)
@info "computing partition trajectory"
for (i, state) in ProgressBar(enumerate(eachcol(trajectory)))
partitions[i] = embedding(state)
end
return nothing

return StateSpacePartition(embedding, partitions)
end

# Utility Functions

include("inverse_iteration.jl")
include("coarsen.jl")
include("markov_chain_hammer_extensions.jl")
include("tree_extensions.jl")

end # module StateSpacePartitions
1 change: 1 addition & 0 deletions src/Trees/Trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ Tree(bool::Bool, args::Any) = Tree(Val(bool), args)

include("unstructured.jl")
include("binary.jl")
include("coarsen.jl")

end # module Tree
33 changes: 0 additions & 33 deletions src/Trees/binary.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using KernelAbstractions: @kernel, @index
using KernelAbstractions.Extras.LoopInfo: @unroll

export extract_coarse_guess

struct BinaryTree{S, T}
centers::S
levels::T
Expand All @@ -17,35 +13,6 @@ function (embedding::BinaryTree)(current_state)
return local_index(global_index, embedding.levels)
end

function (embedding::BinaryTree)(partitions, states)
worksize = total_length(states)
workgroup = min(length(partitions), 256)

arch = architecture(partitions)
args = (partitions, states, embedding.centers, Val(embedding.levels))

launch_chunked_kernel!(arch, workgroup, worksize, _compute_binary_embedding!, args)

return nothing
end

@kernel function _compute_binary_embedding!(partitions, states, centers, ::Val{levels}) where levels
p = @index(Global, Linear)

@inbounds begin
state = states[:, p]

global_index = 1

@unroll for _ in 1:levels
new_index = argmin([norm(state - center) for center in centers[global_index]])
global_index = child_global_index(new_index, global_index)
end

partitions[p] = local_index(global_index, levels)
end
end

# binary tree index juggling
local_index(global_index, levels) = global_index - 2^levels + 1 # markov index from [1, 2^levels]
child_global_index(new_index, global_parent_index) = 2 * global_parent_index + new_index - 1
Expand Down
6 changes: 0 additions & 6 deletions src/coarsen.jl → src/Trees/coarsen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,3 @@ function isancestor(ancestor, child, G)
end
return nothing
end

# Binary Tree
function coarsen(ssp::StateSpacePartition{S, A}, levels) where {S <: BinaryTree, A}
partitions = ssp.partitions
return (partitions .- 1) 2^levels .+ 1
end
Loading

0 comments on commit 628a25b

Please sign in to comment.