-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from skleinbo/makie
Makie
- Loading branch information
Showing
9 changed files
with
1,022 additions
and
74 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name = "Ising" | ||
authors = ["Stephan Kleinboelting <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e" | ||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964" | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a" | ||
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" | ||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" | ||
Observables = "510215fc-4207-5dde-b226-833fc4488ee2" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using Makie | ||
using GeometryTypes, AbstractPlotting, Colors | ||
import Observables | ||
using Observables: AbstractObservable, on, off, async_latest | ||
|
||
include("src/mcmc.jl"); | ||
include("src/visualization.jl") | ||
|
||
### GUI | ||
color1 = colorant"black" | ||
color2 = colorant"cornflowerblue" | ||
# s1, g_L = AbstractPlotting.textslider(16:16:512, "L") | ||
s2, g_mult = AbstractPlotting.textslider(-3.0:0.1:+2.0, start=-2.0, "speed [log]") | ||
|
||
s3, g_h = AbstractPlotting.textslider(-5f0:0.1f0:5f0, start=0f0,"field") | ||
s4, g_T = AbstractPlotting.textslider(0f0:0.005f0:5f0, "temperature") | ||
|
||
b1 = AbstractPlotting.button(Theme(raw = true, camera = campixel!),"Pause/Play" ) | ||
b2 = AbstractPlotting.button(Theme(raw = true, camera = campixel!),"Metropolis" ) | ||
|
||
b1_click = on(b1[end][:clicks]) do c | ||
run_signal[] = !run_signal[] | ||
end | ||
|
||
b2_click = on(b2[end][:clicks]) do c | ||
if algorithm[] == :metropolis | ||
algorithm[] = :wolff | ||
b2[end].input_args[end][] = "Wolff" | ||
else | ||
algorithm[] = :metropolis | ||
b2[end].input_args[end][] = "Metropolis" | ||
end | ||
end | ||
|
||
### Logic | ||
|
||
algorithm = Node(:metropolis) | ||
|
||
# Timey-Wimey | ||
frame_node = Node(0) | ||
run_signal = Node(false) | ||
BASE_FPS = Node(60) | ||
|
||
|
||
g_L = Node(128) | ||
# L = async_latest(g_L,1) # | ||
|
||
|
||
positions, square = get_primitives(g_L[]) | ||
config0 = frustratedConfiguration(g_L[]); | ||
cluster = zeros(Bool, g_L[],g_L[]); | ||
|
||
color_node = Node([RGB(0.,0.,0.) for j in 1:g_L[]^2]) | ||
|
||
render_map = lift(run_signal) do rs | ||
global simtask = @async begin | ||
if !rs | ||
@info "Render task ended." | ||
return nothing | ||
end | ||
while run_signal[] | ||
t1 = time() | ||
if algorithm[] == :metropolis | ||
metropolis_sweep!(config0, round(Int,10^g_mult[] * g_L[]^2), 1/g_T.val,g_h.val) | ||
elseif algorithm[] == :wolff | ||
wolff_sweep!(round(Int,10^g_mult[] * g_L[]^2), config0, cluster, 1/g_T[], g_h[]) | ||
end | ||
color_node[] = reshape(color_gen(config0, color1, color2),g_L[]^2) | ||
t2 = time() | ||
if (t2-t1) < 1/BASE_FPS[] | ||
sleep(1/BASE_FPS[] - (t2-t1)) | ||
end | ||
nothing | ||
end | ||
end | ||
end | ||
|
||
init_map = lift(g_L) do L | ||
run_signal[] = false | ||
|
||
global positions,square = get_primitives(L) | ||
global config0 = frustratedConfiguration(L); | ||
global cluster = zeros(Bool, L,L); | ||
|
||
empty!(color_node.listeners) | ||
color_node[] = reshape(color_gen(config0,color1, color2),L^2) | ||
|
||
global state_plot = Makie.meshscatter(reshape(positions,L^2); color=color_node, | ||
markersize=1,marker=GLNormalMesh(square), axis_type=axis2d!, camera=cam2d!, | ||
raw=true, shading=false | ||
) | ||
# state_plot.attributes[:padding][] = [0f0, 0f0, 0f0] | ||
# cam = cameracontrols(state_plot) | ||
# cam.area[] = HyperRectangle(-1.05f0, -1.05f0, 2.1f0,2.1f0) | ||
state_plot.theme.attributes[:backgroundcolor][] = :gray | ||
update_cam!(state_plot, FRect(-1,-1,2,2)) | ||
state_plot[end][:light] = Vec{3,Float32}[[1.0, 1.0, 1.0], [0.1, 0.1, 0.1], [0.9, 0.9, 0.9], [0.0, 0.0, -20.0]] | ||
|
||
global scene = vbox(hbox(s2,s3,s4,b2,b1),state_plot, parent=Scene(windowtitle="Ising")) | ||
on(scene.events.keyboardbuttons) do buttons | ||
if ispressed(scene, Keyboard.p) | ||
run_signal[] = !run_signal[] | ||
elseif ispressed(scene, Keyboard.c) | ||
update_cam!(state_plot, FRect(-1,-1,2,2)) | ||
elseif ispressed(scene, Keyboard.r) | ||
config0 = frustratedConfiguration(g_L[]); | ||
cluster = zeros(Bool, g_L[],g_L[]); | ||
elseif ispressed(scene, Keyboard.equal) | ||
g_mult[] = min(g_mult[]+0.1, 2.0) | ||
elseif ispressed(scene, Keyboard.minus) | ||
g_mult[] = max(g_mult[]-0.1, -3.0) | ||
end | ||
end | ||
on(scene.events.window_area) do wa | ||
update_cam!(state_plot, FRect(-1,-1,2,2)) | ||
end | ||
display(scene); | ||
# push!(run_signal, true) | ||
nothing | ||
end | ||
# |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.