Skip to content

Commit 340e766

Browse files
authored
Consistently apply snake_case (#301)
# Apply snake_case to keyword arguments ## Breaking changes - IDs for replicas and spectral states are swapped: replica ids defining the row in the matrix of `state_vectors` now are appended first and spectral ids second. If there is only a single replica, or a single spectral state, the respective ids are ommitted. ## Deprecations - in keyword arguments to `ProjectorMonteCarloProblem` - `maxlength` deprecated, replaced by `max_length` - `walltime` deprecated, replaced by `walltime` - `lomc!` now prints a deprecation warning ## Internal changes - fix random seeding of tests - minor docstring changes - remove `lomc!` from most tests
1 parent 77334e5 commit 340e766

18 files changed

+401
-218
lines changed

src/Hamiltonians/HubbardRealSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function Base.show(io::IO, h::HubbardRealSpace{C}) where C
266266
println(io, " u = ", Float64.(h.u), ",")
267267
end
268268
!isnothing(h.v) && println(io, " v = ", Float64.(h.v), ",")
269-
println(io, ")")
269+
print(io, ")")
270270
end
271271

272272
# Overload equality due to stored potential energy arrays.

src/fciqmc.jl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,11 @@ function advance!(algorithm::FCIQMC, report, state::ReplicaState, s_state::Singl
170170
end
171171

172172
if len == 0
173-
if length(state.spectral_states) > 1
174-
@error "population in single state $(s_state.id) is dead. Aborting."
175-
else
176-
@error "population is dead. Aborting."
177-
end
173+
@error "Population in state $(s_state.id) is dead. Aborting."
178174
return false
179175
end
180-
if len > state.maxlength[]
181-
if length(state.spectral_states) > 1
182-
@error "`maxlength` reached in single state $(s_state.id). Aborting."
183-
else
184-
@error "`maxlength` reached. Aborting."
185-
end
176+
if len > state.max_length[]
177+
@error "`max_length` reached in state $(s_state.id). Aborting."
186178
return false
187179
end
188180
return proceed # Bool

src/lomc.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ julia> address = BoseFS(1,2,3);
5555
5656
julia> hamiltonian = HubbardReal1D(address);
5757
58-
julia> df1, state = lomc!(hamiltonian; targetwalkers=500, laststep=100);
58+
julia> df1, state = @suppress lomc!(hamiltonian; targetwalkers=500, laststep=100);
5959
60-
julia> df2, _ = lomc!(state, df1; laststep=200, metadata=(;info="cont")); # Continuation run
60+
julia> df2, _ = @suppress lomc!(state, df1; laststep=200, metadata=(;info="cont")); # Continuation run
6161
6262
julia> size(df1)
6363
(100, 9)
@@ -118,6 +118,8 @@ function lomc!(
118118
maxlength = nothing,
119119
wm = nothing
120120
)
121+
@warn "The use of `lomc!` is deprecated. Use `ProjectorMonteCarloProblem` and `solve` instead."
122+
121123
if !isnothing(wm)
122124
@warn "The `wm` argument has been removed and will be ignored."
123125
end
@@ -156,7 +158,7 @@ function lomc!(
156158
replica_strategy = replica,
157159
reporting_strategy = r_strat,
158160
post_step_strategy = post_step,
159-
maxlength,
161+
max_length = maxlength,
160162
metadata,
161163
display_name = name,
162164
random_seed = false
@@ -193,15 +195,18 @@ function lomc!(
193195
end
194196

195197
function lomc!(::AbstractMatrix, v=nothing; kwargs...)
198+
@warn "The use of `lomc!` is deprecated. Use `ProjectorMonteCarloProblem` and `solve` instead."
196199
throw(ArgumentError("Using lomc! with a matrix is no longer supported. Use `MatrixHamiltonian` instead."))
197200
end
198201

199202
# methods for backward compatibility
200203
function lomc!(state::ReplicaState, df=DataFrame(); laststep=0, name="lomc!", metadata=nothing)
204+
@warn "The use of `lomc!` is deprecated. Use `ProjectorMonteCarloProblem` and `solve` instead."
205+
201206
if !iszero(laststep)
202207
state = @set state.simulation_plan.last_step = laststep
203208
end
204-
@unpack spectral_states, maxlength, step, simulation_plan,
209+
@unpack spectral_states, max_length, step, simulation_plan,
205210
reporting_strategy, post_step_strategy, replica_strategy = state
206211
first_replica = first(state) # SingleState
207212
@unpack hamiltonian = first_replica
@@ -213,7 +218,7 @@ function lomc!(state::ReplicaState, df=DataFrame(); laststep=0, name="lomc!", me
213218
replica_strategy,
214219
reporting_strategy,
215220
post_step_strategy,
216-
maxlength=maxlength[],
221+
max_length=max_length[],
217222
simulation_plan,
218223
metadata,
219224
display_name=name,

src/pmc_simulation.jl

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ Is returned by [`init(::ProjectorMonteCarloProblem)`](@ref) and solved with
66
77
Obtain the results of a simulation `sm` as a DataFrame with `DataFrame(sm)`.
88
9+
## Fields
10+
- `problem::ProjectorMonteCarloProblem`: The problem that was solved
11+
- `state::Rimu.ReplicaState`: The current state of the simulation
12+
- `report::Rimu.Report`: The report of the simulation
13+
- `modified::Bool`: Whether the simulation has been modified
14+
- `aborted::Bool`: Whether the simulation has been aborted
15+
- `success::Bool`: Whether the simulation has been completed successfully
16+
- `message::String`: A message about the simulation status
17+
- `elapsed_time::Float64`: The time elapsed during the simulation
18+
919
See also [`state_vectors`](@ref),
1020
[`ProjectorMonteCarloProblem`](@ref), [`init`](@ref), [`solve!`](@ref).
1121
"""
@@ -80,7 +90,7 @@ function PMCSimulation(problem::ProjectorMonteCarloProblem; copy_vectors=true)
8090
@unpack algorithm, hamiltonian, start_at, style, threading, simulation_plan,
8191
replica_strategy, initial_shift_parameters,
8292
reporting_strategy, post_step_strategy,
83-
maxlength, metadata, initiator, random_seed, spectral_strategy, minimum_size = problem
93+
max_length, metadata, initiator, random_seed, spectral_strategy, minimum_size = problem
8494

8595
reporting_strategy = refine_reporting_strategy(reporting_strategy)
8696

@@ -114,30 +124,33 @@ function PMCSimulation(problem::ProjectorMonteCarloProblem; copy_vectors=true)
114124
# set up the spectral_states
115125
wm = working_memory(vectors[1, 1])
116126
spectral_states = ntuple(n_replicas) do i
127+
replica_id = if n_replicas == 1
128+
""
129+
else
130+
"_$(i)"
131+
end
117132
SpectralState(
118133
ntuple(n_spectral) do j
119134
v = vectors[i, j]
120135
sp = shift_parameters[i, j]
121-
id = if n_replicas * n_spectral == 1
136+
spectral_id = if n_spectral == 1
122137
""
123-
elseif n_spectral == 1
124-
"_$(i)"
125138
else
126-
"_s$(j)_$(i)" # j is the spectral state index, i is the replica index
127-
end # we have to think about how to label the spectral states
139+
"_s$(j)" # j is the spectral state index, i is the replica index
140+
end
128141
SingleState(
129142
hamiltonian, algorithm, v, zerovector(v),
130143
wm isa PDWorkingMemory ? wm : working_memory(v), # reuse for PDVec
131-
sp, id
144+
sp, replica_id * spectral_id
132145
)
133-
end, spectral_strategy)
146+
end, spectral_strategy, replica_id)
134147
end
135148
@assert spectral_states isa NTuple{n_replicas, <:SpectralState}
136149

137150
# set up the initial state
138151
state = ReplicaState(
139152
spectral_states,
140-
Ref(maxlength),
153+
Ref(max_length),
141154
Ref(simulation_plan.starting_step),
142155
simulation_plan,
143156
reporting_strategy,
@@ -242,7 +255,7 @@ end
242255
243256
Advance the simulation by one step.
244257
245-
Calling [`solve!`](@ref) will advance the simulation until the last step or the walltime is
258+
Calling [`solve!`](@ref) will advance the simulation until the last step or the wall time is
246259
exceeded. When completing the simulation without calling [`solve!`](@ref), the simulation
247260
report needs to be finalised by calling [`Rimu.finalize_report!`](@ref).
248261
@@ -300,7 +313,7 @@ end
300313
solve(::ProjectorMonteCarloProblem)::PMCSimulation
301314
302315
Initialize and solve a [`ProjectorMonteCarloProblem`](@ref) until the last step is completed
303-
or the walltime limit is reached.
316+
or the wall time limit is reached.
304317
305318
See also [`init`](@ref), [`solve!`](@ref), [`step!`](@ref), [`Rimu.PMCSimulation`](@ref),
306319
and [`solve(::ExactDiagonalizationProblem)`](@ref).
@@ -310,16 +323,17 @@ CommonSolve.solve
310323
"""
311324
solve!(sm::PMCSimulation; kwargs...)::PMCSimulation
312325
313-
Solve a [`Rimu.PMCSimulation`](@ref) until the last step is completed or the walltime limit
326+
Solve a [`Rimu.PMCSimulation`](@ref) until the last step is completed or the wall time limit
314327
is reached.
315328
316-
To continue a previously completed simulation, set a new `last_step` or `walltime` using the
317-
keyword arguments. Optionally, changes can be made to the `replica_strategy`, the
329+
To continue a previously completed simulation, set a new `last_step` or `wall_time` using
330+
the keyword arguments. Optionally, changes can be made to the `replica_strategy`, the
318331
`post_step_strategy`, or the `reporting_strategy`.
319332
320333
# Optional keyword arguments:
321334
* `last_step = nothing`: Set the last step to a new value and continue the simulation.
322-
* `walltime = nothing`: Set the allowed walltime to a new value and continue the simulation.
335+
* `wall_time = nothing`: Set the allowed wall time to a new value and continue the
336+
simulation.
323337
* `reset_time = false`: Reset the `elapsed_time` counter and continue the simulation.
324338
* `empty_report = false`: Empty the report before continuing the simulation.
325339
* `replica_strategy = nothing`: Change the replica strategy. Requires the number of replicas
@@ -335,7 +349,7 @@ See also [`ProjectorMonteCarloProblem`](@ref), [`init`](@ref), [`solve`](@ref),
335349
"""
336350
function CommonSolve.solve!(sm::PMCSimulation;
337351
last_step = nothing,
338-
walltime = nothing,
352+
wall_time = nothing,
339353
reset_time = false,
340354
replica_strategy=nothing,
341355
post_step_strategy=nothing,
@@ -351,9 +365,9 @@ function CommonSolve.solve!(sm::PMCSimulation;
351365
report_metadata!(sm.report, "laststep", last_step)
352366
reset_flags = true
353367
end
354-
if !isnothing(walltime)
368+
if !isnothing(wall_time)
355369
state = sm.state
356-
sm.state = @set state.simulation_plan.walltime = walltime
370+
sm.state = @set state.simulation_plan.wall_time = wall_time
357371
reset_flags = true
358372
end
359373
if !isnothing(replica_strategy)
@@ -419,10 +433,10 @@ function CommonSolve.solve!(sm::PMCSimulation;
419433
name = get_metadata(sm.report, "display_name")
420434

421435
@withprogress name = while !sm.aborted && !sm.success
422-
if time() - starting_time > simulation_plan.walltime
436+
if time() - starting_time > simulation_plan.wall_time
423437
sm.aborted = true
424-
sm.message = "Walltime limit reached."
425-
@warn "Walltime limit reached. Aborting simulation."
438+
sm.message = "Wall time limit reached."
439+
@warn "Wall time limit reached. Aborting simulation."
426440
else
427441
step!(sm)
428442
end

0 commit comments

Comments
 (0)