Skip to content

Commit a64f70d

Browse files
committed
Update Tests with new MonteCarlo version
1 parent 13e491a commit a64f70d

File tree

5 files changed

+77
-112
lines changed

5 files changed

+77
-112
lines changed

test/gerhard_energy_distribution.jl

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ steps = 1000
4343
burn = 0
4444
block = [0, 10]
4545
sampletimes = build_schedule(steps, burn, block)
46-
schedulers = [build_schedule(steps, 0, 1), sampletimes, sampletimes, [0, steps], build_schedule(steps, burn, steps ÷ 10)]
4746
callbacks = (callback_energy, callback_acceptance)
4847

4948
# NO SWAPS
@@ -53,33 +52,27 @@ displacement_parameters = ComponentArray(σ=0.05)
5352
pools = [(
5453
Move(Displacement(0, zero(box)), displacement_policy, displacement_parameters, 1 - pswap),
5554
) for _ in 1:M]
55+
56+
algorithm_list = (
57+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
58+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
59+
(algorithm=StoreTrajectories, scheduler=sampletimes),
60+
(algorithm=StoreLastFrames, scheduler=[steps]),
61+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
62+
)
63+
5664
## Empty List
5765
chains = deepcopy(chains_bkp)
5866
path = "data/test/particles/KA2D_distribution/N$N/T$temperature/pswap$pswap/M$M"
59-
algorithms = (
60-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
61-
StoreCallbacks(callbacks, path),
62-
StoreTrajectories(chains, path),
63-
StoreLastFrames(chains, path),
64-
PrintTimeSteps(),
65-
)
66-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
67+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
6768
run!(simulation)
6869

6970
## Linked List
7071
chains = deepcopy(chains_ll_bkp)
7172
path = "data/test/particles/KA2D_distribution_LL/N$N/T$temperature/pswap$pswap/M$M"
72-
algorithms = (
73-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
74-
StoreCallbacks(callbacks, path),
75-
StoreTrajectories(chains, path),
76-
StoreLastFrames(chains, path),
77-
PrintTimeSteps(),
78-
)
79-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
73+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
8074
run!(simulation)
8175

82-
8376
# SWAPS
8477
pswap = 0.2
8578
displacement_policy = SimpleGaussian()
@@ -91,30 +84,23 @@ pools = [(
9184
Move(DiscreteSwap(0, 0, (1, 3), (NA, NC)), swap_policy, swap_parameters, pswap / 2),
9285
Move(DiscreteSwap(0, 0, (2, 3), (NB, NC)), swap_policy, swap_parameters, pswap / 2),
9386
) for _ in 1:M]
87+
algorithm_list = (
88+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
89+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
90+
(algorithm=StoreTrajectories, scheduler=sampletimes),
91+
(algorithm=StoreLastFrames, scheduler=[steps]),
92+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
93+
)
9494
## Empty List
9595
chains = deepcopy(chains_bkp)
9696
path = "data/test/particles/KA2D_distribution/N$N/T$temperature/pswap$pswap/M$M"
97-
algorithms = (
98-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
99-
StoreCallbacks(callbacks, path),
100-
StoreTrajectories(chains, path),
101-
StoreLastFrames(chains, path),
102-
PrintTimeSteps(),
103-
)
104-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
97+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
10598
run!(simulation)
10699

107100
## Linked List
108101
chains = deepcopy(chains_ll_bkp)
109102
path = "data/test/particles/KA2D_distribution_LL/N$N/T$temperature/pswap$pswap/M$M"
110-
algorithms = (
111-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
112-
StoreCallbacks(callbacks, path),
113-
StoreTrajectories(chains, path),
114-
StoreLastFrames(chains, path),
115-
PrintTimeSteps(),
116-
)
117-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
103+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
118104
run!(simulation)
119105

120106

@@ -131,29 +117,21 @@ pools = [(
131117
Move(DiscreteSwap(0, 0, (1, 3), (NA, NC)), swap_AC_policy, swap_AC_parameters, pswap / 2),
132118
Move(DiscreteSwap(0, 0, (2, 3), (NB, NC)), swap_BC_policy, swap_BC_parameters, pswap / 2),
133119
) for _ in 1:M]
120+
algorithm_list = (
121+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
122+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
123+
(algorithm=StoreTrajectories, scheduler=sampletimes),
124+
(algorithm=StoreLastFrames, scheduler=[steps]),
125+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
126+
)
134127
## Empty List
135128
chains = deepcopy(chains_bkp)
136129
path = "data/test/particles/KA2D_distribution/N$N/T$temperature/ebswap$pswap/M$M"
137-
138-
algorithms = (
139-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
140-
StoreCallbacks(callbacks, path),
141-
StoreTrajectories(chains, path),
142-
StoreLastFrames(chains, path),
143-
PrintTimeSteps(),
144-
)
145-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
130+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
146131
run!(simulation)
147132

148133
## Linked List
149134
chains = deepcopy(chains_ll_bkp)
150135
path = "data/test/particles/KA2D_distribution_LL/N$N/T$temperature/ebswap$pswap/M$M"
151-
algorithms = (
152-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
153-
StoreCallbacks(callbacks, path),
154-
StoreTrajectories(chains, path),
155-
StoreLastFrames(chains, path),
156-
PrintTimeSteps(),
157-
)
158-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
159-
run!(simulation)
136+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
137+
run!(simulation)

test/molecules_test.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ schedulers = [build_schedule(steps, 0, 1), sampletimes, sampletimes, [0, steps],
6666
callbacks = (callback_energy, callback_acceptance)
6767

6868
path = "data/test/particles/Molecules/T$temperature/N$N/M$M/seed$seed"
69-
algorithms = (
70-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
71-
StoreCallbacks(callbacks, path),
72-
StoreTrajectories(chains, path),
73-
StoreLastFrames(chains, path),
74-
PrintTimeSteps(),
75-
)
76-
## Run the simulation :)
77-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
69+
algorithm_list = (
70+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
71+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
72+
(algorithm=StoreTrajectories, scheduler=sampletimes),
73+
(algorithm=StoreLastFrames, scheduler=[steps]),
74+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
75+
)
76+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
7877
run!(simulation)

test/runtests.jl

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ using DelimitedFiles
3838
burn = 0
3939
block = [0, 1, 2, 4, 8]
4040
sampletimes = build_schedule(steps, burn, block)
41-
schedulers = [build_schedule(steps, 0, 1), sampletimes, sampletimes, [0, steps], build_schedule(steps, burn, steps ÷ 10)]
4241
callbacks = (callback_energy, callback_acceptance)
4342

4443
# NO SWAPS
@@ -48,32 +47,23 @@ using DelimitedFiles
4847
pools = [(
4948
Move(Displacement(0, zero(box)), displacement_policy, displacement_parameters, 1 - pswap),
5049
) for _ in 1:M]
51-
52-
50+
algorithm_list = (
51+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
52+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
53+
(algorithm=StoreTrajectories, scheduler=sampletimes),
54+
(algorithm=StoreLastFrames, scheduler=[steps]),
55+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
56+
)
5357
## Empty List simulation
5458
chains_el = [deepcopy(system_el)]
5559
path_el = "data/noswap/empty_list/"
56-
algorithms = (
57-
Metropolis(chains_el, pools; sweepstep=N, seed=seed, parallel=false),
58-
StoreCallbacks(callbacks, path_el),
59-
StoreTrajectories(chains_el, path_el),
60-
StoreLastFrames(chains_el, path_el),
61-
PrintTimeSteps(),
62-
)
63-
simulation = Simulation(chains_el, algorithms, steps; schedulers=schedulers, path=path_el, verbose=true)
60+
simulation = Simulation(chains_el, algorithm_list, steps; path=path_el, verbose=true)
6461
run!(simulation)
6562

6663
## Linked List simulation
6764
chains_ll = [deepcopy(system_ll)]
6865
path_ll = "data/noswap/linked_list/"
69-
algorithms = (
70-
Metropolis(chains_ll, pools; sweepstep=N, seed=seed, parallel=false),
71-
StoreCallbacks(callbacks, path_ll),
72-
StoreTrajectories(chains_ll, path_ll),
73-
StoreLastFrames(chains_ll, path_ll),
74-
PrintTimeSteps(),
75-
)
76-
simulation = Simulation(chains_ll, algorithms, steps; schedulers=schedulers, path=path_ll, verbose=true)
66+
simulation = Simulation(chains_ll, algorithm_list, steps; path=path_ll, verbose=true)
7767
run!(simulation)
7868

7969
## Read energy data and compare
@@ -94,31 +84,23 @@ using DelimitedFiles
9484
Move(DiscreteSwap(0, 0, (1, 3), (NA, NC)), swap_policy, swap_parameters, pswap / 2),
9585
Move(DiscreteSwap(0, 0, (2, 3), (NB, NC)), swap_policy, swap_parameters, pswap / 2),
9686
) for _ in 1:M]
97-
87+
algorithm_list = (
88+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
89+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
90+
(algorithm=StoreTrajectories, scheduler=sampletimes),
91+
(algorithm=StoreLastFrames, scheduler=[steps]),
92+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
93+
)
9894
## Empty List simulation
9995
chains_el = [deepcopy(system_el)]
10096
path_el = "data/swap/empty_list/"
101-
algorithms = (
102-
Metropolis(chains_el, pools; sweepstep=N, seed=seed, parallel=false),
103-
StoreCallbacks(callbacks, path_el),
104-
StoreTrajectories(chains_el, path_el),
105-
StoreLastFrames(chains_el, path_el),
106-
PrintTimeSteps(),
107-
)
108-
simulation = Simulation(chains_el, algorithms, steps; schedulers=schedulers, path=path_el, verbose=true)
97+
simulation = Simulation(chains_el, algorithm_list, steps; path=path_el, verbose=true)
10998
run!(simulation)
11099

111100
## Linked List simulation
112101
chains_ll = [deepcopy(system_ll)]
113102
path_ll = "data/swap/linked_list/"
114-
algorithms = (
115-
Metropolis(chains_ll, pools; sweepstep=N, seed=seed, parallel=false),
116-
StoreCallbacks(callbacks, path_ll),
117-
StoreTrajectories(chains_ll, path_ll),
118-
StoreLastFrames(chains_ll, path_ll),
119-
PrintTimeSteps(),
120-
)
121-
simulation = Simulation(chains_ll, algorithms, steps; schedulers=schedulers, path=path_ll, verbose=true)
103+
simulation = Simulation(chains_ll, algorithm_list, steps; path=path_ll, verbose=true)
122104
run!(simulation)
123105

124106
## Read energy data and compare

test/simple_test.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,16 @@ pools = [(
5757
chains = deepcopy(chains_bkp)
5858
path = "data/test/particles/KA2D_distribution/N$N/T$temperature/pswap$pswap/M$M"
5959
sampletimes = build_schedule(steps, burn, block)
60-
schedulers = [build_schedule(steps, 0, 1), sampletimes, sampletimes, [0, steps], build_schedule(steps, burn, steps ÷ 10)]
6160
callbacks = (callback_energy, callback_acceptance)
6261

63-
algorithms = (
64-
Metropolis(chains, pools; sweepstep=N, seed=seed, parallel=false),
65-
StoreCallbacks(callbacks, path),
66-
StoreTrajectories(chains, path),
67-
StoreLastFrames(chains, path),
68-
PrintTimeSteps(),
69-
)
70-
simulation = Simulation(chains, algorithms, steps; schedulers=schedulers, path=path, verbose=true)
62+
algorithm_list = (
63+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
64+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
65+
(algorithm=StoreTrajectories, scheduler=sampletimes),
66+
(algorithm=StoreLastFrames, scheduler=[steps]),
67+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
68+
)
69+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
7170
run!(simulation)
7271

7372
#displacement_action = Displacement(0, zero(box))

test/ss142d.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ density = 0.5
1717
box = @SVector fill(typeof(temperature)((N / density)^(1 / d)), d)
1818
position = [[box .* @SVector rand(rng, d) for i in 1:N] for m in 1:M]
1919
species = [shuffle!(rng, vcat(ones(Int, NA), 2ones(Int, NB))) for _ in 1:M]
20-
model = ParticlesMC.BHHP()
20+
model = BHHP()
2121
chains = [System(position[m], species[m], density, temperature, model) for m in 1:M]
2222
displacement_policy = SimpleGaussian()
2323
displacement_parameters = ComponentArray(σ=0.065)
@@ -30,9 +30,16 @@ steps = 10^6
3030
# block = [0, 1, 2, 4, 8, 16, 32, 64, 128]
3131
burn = 10^3
3232
block = [0, burn]
33-
sampletimes = scheduler(steps, burn, block)
34-
path = "data/test/particles/SS142D/T$temperature/N$N/M$M/steps$steps/seed$seed"
35-
simulation = Simulation(chains, pools, steps; sweepstep=N, sampletimes=sampletimes, seed=seed, store_trajectory=true, parallel=true, verbose=true, path=path)
3633
callbacks = (callback_energy, callback_acceptance)
37-
## Run the simulation
38-
run!(simulation, callbacks...)
34+
35+
path = "data/test/particles/SS142D/T$temperature/N$N/M$M/steps$steps/seed$seed"
36+
sampletimes = build_schedule(steps, burn, block)
37+
algorithm_list = (
38+
(algorithm=Metropolis, pools=pools, seed=seed, parallel=false, sweepstep=N),
39+
(algorithm=StoreCallbacks, callbacks=(callback_energy, callback_acceptance), scheduler=sampletimes),
40+
(algorithm=StoreTrajectories, scheduler=sampletimes),
41+
(algorithm=StoreLastFrames, scheduler=[steps]),
42+
(algorithm=PrintTimeSteps, scheduler=build_schedule(steps, burn, steps ÷ 10)),
43+
)
44+
simulation = Simulation(chains, algorithm_list, steps; path=path, verbose=true)
45+
run!(simulation)

0 commit comments

Comments
 (0)