using FileIO
using Parameters

include("random_matrices.jl")
include("network_sims_gpu.jl")
include("LS_calculations.jl")

#------------------------------------------------------------------------------
# This is the part where we find which eta and network realization to

J_seeds = collect(5000:5019)
etas = collect(-1.0f0:0.1f0:1.0f0)

ind = parse(Int64, ARGS[1])
ps = [(eta, J_seed) for eta in etas, J_seed in J_seeds]
eta, J_seed = ps[ind]
#------------------------------------------------------------------------------

# Where the results will be saved
dir = "results1"

N = 3000
g = 1.5f0
s = 1f0

h0_seed = 6000
dh_seed = 7000
Q0_seed = 8000

J = generate_J(N, eta, seed=J_seed)
h = generate_nv(N, Float32, seed=h0_seed)
dh = generate_nv(N, Float32, seed=dh_seed)
Q = generate_ONB(N, Float32, seed=Q0_seed)

dt = 1f-2
t_bound = 2f3
t_ONS = 1f0
wait = 2f2


@time Lspec, max_LE = sim_lyapunov_gpu(J, g, h, dh, Q; s=s, dt=dt,
		t_bound=t_bound, t_ONS=t_ONS, wait=wait, return_max_LE=true,
		printstuff=false, p_factor=1e-3, scale_limit=100)

dimensionality = KY_attractor_dim(Lspec)
entropy_rate = KS_entropy_rate(Lspec)


fn = "Lspec_E$(ind)_N=$N,g=$g,eta=$eta,J_seed=$J_seed.jld2"
out = Dict{String,Any}()
@pack! out = N, g, eta, s, J_seed, h0_seed, dh_seed, Q0_seed, dt, t_bound,
		t_ONS, wait, Lspec, max_LE, dimensionality, entropy_rate

save(joinpath(dir, fn), out)
