Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Put everything in module: BROKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
f-ij committed Jul 24, 2022
1 parent e85ac8f commit 13c1669
Show file tree
Hide file tree
Showing 14 changed files with 521 additions and 394 deletions.
Binary file modified .DS_Store
Binary file not shown.
5 changes: 1 addition & 4 deletions Analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ push!(LOAD_PATH, pwd())

using FileIO, Images, LaTeXStrings, Dates, DataFrames, CSV
import Plots as pl
# include("IsingGraphs.jl")
using IsingGraphs

# include("SquareAdj.jl")
using SquareAdj

export dataToDF, tempSweep, MPlot, sampleCorrPeriodic, sampleCorrPeriodicDefects, corrFuncXY, dfMPlot, dataFolderNow, csvToDF, corrPlotDF, corrPlotDFSlices, corrPlotTRange
Expand Down Expand Up @@ -86,7 +83,7 @@ function tempSweep(g, TIs, M_array; TI = TIs[], TF = 13, TStep = 0.5, dpoints =
tpointi = time()
(lVec,corrVec) = corrF(g)
cldf = vcat(cldf, corrToDF((lVec,corrVec) , point, TIs[]) )
mdf = vcat(mdf,MToDF(last(M_array[]),point, TIs[]) )
mdf = vcat(mdf,MToDF(last(M_array),point, TIs[]) )

if saveImg
if !savelast || point == dpoints
Expand Down
18 changes: 0 additions & 18 deletions CreateF.jl

This file was deleted.

2 changes: 1 addition & 1 deletion Interaction/Interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function addRandomDefects!(g::IsingGraph,p)

for _ in 1:round(length(g.d.aliveList)*p/100)
idx = rand(g.d.aliveList)
setSpin!(g, idx, 0 , true)
setSpin!(g, idx, Int8(0) , true)
end

end
Expand Down
117 changes: 18 additions & 99 deletions IsingGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Random, Distributions, Observables, SquareAdj
using WeightFuncs

export AbstractIsingGraph, IsingGraph, CIsingGraph, reInitGraph!, coordToIdx, idxToCoord, ising_it, setSpins!, setSpin!, addDefects!, remDefects!, addDefect!, remDefect!,
connIdx, connW, initSqAdj, HFunc, HWeightedFunc, HMagFunc, HWMagFunc, setMIdxs!
connIdx, connW, initSqAdj, HFunc, HWeightedFunc, HMagFunc, HWMagFunc, setMIdxs!, setGHFunc!

# Aliases
const Edge = Pair{Int32,Int32}
Expand Down Expand Up @@ -78,55 +78,14 @@ CIsingGraph(N::Integer; weighted = false, weightFunc = defaultIsingWF, selfE = t
# Copy graph data to new one
IsingGraph(g::IsingGraph) = deepcopy(g)

function reInitGraph!(g::IsingGraph, state = typeof(g) == IsingGraph{Int8} ? initRandomState(g.size) : initRandomCState(g.size))
println("Reinitializing graph")
g.state = state
g.d.defects = false
g.d.aliveList = [1:g.size;]
g.d.defectBools = [false for x in 1:g.size]
g.d.defectList = []
g.d.mactive = false
g.d.mlist = zeros(g.size)
setGHFunc!(g)
end

# Initialization of state
export initRandomState
function initRandomState(size)::Vector{Int8}
return rand([-1,1],size)
end

""" Continuous """

# mutable struct CIsingGraph <: AbstractIsingGraph
# # Global graph props to be tracked for performance
# N::Int32
# size::Int32
# # Vertices and edges
# state::Vector{Float32}
# adj::Vector{Vector{Conn}}
# # Energy function
# d::IsingData

# CIsingGraph(N::Integer; state = initRandomCState(N^2), weighted = false, weightFunc = DefaultIsingWF, selfE = true) =
# ( h = new(
# N,
# N^2,
# state,
# selfE ? initSqAdjSelf(N, weightFunc = weightFunc) : initSqAdj(N, weightFunc = weightFunc)
# );
# h.d = IsingData(h,weighted);
# return h
# )

# end

# # Copy graph data to new one
# CIsingGraph(g::CIsingGraph) = deepcopy(g)

# reInitGraph!(g::CIsingGraph) = reInitGraph!(g, initRandomCState(g.size))


# Initialization of state
export initRandomCState
function initRandomCState(size)::Vector{Float32}
return 2 .* (rand(Float32,size) .- .5)
end
Expand Down Expand Up @@ -339,9 +298,9 @@ end
end
end

setSpin!(g::AbstractIsingGraph,i::Integer,j::Integer, brush::Real, clamp::Bool = false) = setSpins!(g, [coordToIdx(i,j,g.N)], brush, clamp)
setSpin!(g::AbstractIsingGraph, i::Integer, j::Integer, brush::Union{Int8,Float32}, clamp::Bool = false) = setSpins!(g, [coordToIdx(i,j,g.N)], brush, clamp)

setSpin!(g::AbstractIsingGraph, coord::Integer, brush::Real, clamp::Bool = false) = setSpins!(g,[coord],brush,clamp)
setSpin!(g::AbstractIsingGraph, idx::Integer, brush::Union{Int8,Float32}, clamp::Bool = false) = setSpins!(g,[idx],brush,clamp)

setSpins!(g::AbstractIsingGraph, tupls::Vector{Tuple{Int32,Int32}}, brush, clamp) = setSpins!(g, coordToIdx.(tupls,g.N), brush, clamp)

Expand Down Expand Up @@ -389,7 +348,8 @@ function HWMagFunc(g::AbstractIsingGraph,idx,state = g.state[idx])::Float32
return efactor -g.d.mlist[idx]
end

function setGHFunc!(g, shouldRun::Observable,isRunning::Ref)
function setGHFunc!(sim)
g = sim.g
if !g.d.weighted
if !g.d.mactive
g.d.hFuncRef = Ref(HFunc)
Expand All @@ -408,34 +368,35 @@ function setGHFunc!(g, shouldRun::Observable,isRunning::Ref)
end
end

branchSim(shouldRun,isRunning)
branchSim(sim)
end

""" Changing E functions """

function setMIdxs!(g,idxs,strengths,shouldRun::Observable,isRunning::Ref)
function setMIdxs!(sim,idxs,strengths)
g = sim.g
if length(idxs) != length(strengths)
error("Idxs and strengths lengths not the same")
return
end

shouldRun[] = false
sim.shouldRun[] = false
g.d.mactive = true
g.d.mlist[idxs] = strengths
# setGHFunc!(g)
g.d.hFuncRef = Ref(HWMagFunc)
while isRunning[]
while sim.isRunning[]
sleep(.1)
end
shouldRun[] = true
sim.shouldRun[] = true
end

function branchSim(shouldRun::Observable,isRunning::Ref)
shouldRun[] = false
while isRunning[]
function branchSim(sim)
sim.shouldRun[] = false
while sim.isRunning[]
sleep(.1)
end
shouldRun[] = true
sim.shouldRun[] = true
end


Expand Down Expand Up @@ -520,46 +481,4 @@ end
end


end


""" Old
macro varname(arg)
string(arg)
end
function getHMField!(g,idxs,strengths)
gname = @varname(g)
try
setMIdxs!(g,idxs,strengths)
catch
return
end
if g.d.weighted
println("Hamiltonian set to weighted + magnetic field")
eval(Meta.parse("DOLLARSIGN(gname).getE(g,idx,state = g.state[idx]) = HWeightedFunc(g,idx,state) + HMagFunc(g,idx,state)"))
else
println("Hamiltonian set to unweighted + magnetic field")
eval(Meta.parse("DOLLARSIGN(gname).getE(g,idx,state = g.state[idx]) = HFunc(g,idx,state) + HMagFunc(g,idx,state)"))
end
end
function setMIdxs!(g,idxs,strengths)
if length(idxs) != length(strengths)
error("Idxs and strengths lengths not the same")
return
end
for idx in idxs
g.d.mlist[idx] = strengths[idx]
end
end
"""
end
20 changes: 12 additions & 8 deletions IsingMetropolis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ using IsingGraphs
export updateMonteCarloIsing!, deltED, deltEC

# Discrete
@inline function deltED(Estate)
return -2*Estate
end


# Continuous
@inline function deltEC(efac,newstate,oldstate)
return efac*(newstate-oldstate)
end

function updateMonteCarloIsing!(g::IsingGraph{Int8}, T; getE::Function = HFunc, deltE::Function = deltED)

function updateMonteCarloIsing!(g::IsingGraph{Int8}, T; getE::Function = HFunc)

@inline function deltE(Estate)
return -2*Estate
end

beta = T>0 ? 1/T : Inf

Expand All @@ -33,7 +33,11 @@ function updateMonteCarloIsing!(g::IsingGraph{Int8}, T; getE::Function = HFunc,

end

function updateMonteCarloIsing!(g::IsingGraph{Float32}, T; getE::Function = HFunc, deltE::Function = deltEC)
function updateMonteCarloIsing!(g::IsingGraph{Float32}, T; getE::Function = HFunc)

@inline function deltE(efac,newstate,oldstate)
return efac*(newstate-oldstate)
end

@inline function sampleCState()
Float32(2*(rand()-.5))
Expand Down
Loading

0 comments on commit 13c1669

Please sign in to comment.