Skip to content

Commit

Permalink
Add support for initiator rule in default starting vector
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimbrand committed Jan 12, 2024
1 parent dcc4b60 commit 76788cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/lomc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,24 @@ end
default_starting_vector(
address=starting_address(hamiltonian);
style=IsStochasticInteger(),
initiator=NonInitiator(),
threading=nothing
)
Return a default starting vector for [`lomc!`](@ref). The default choice for the starting
vector is
```julia
v = PDVec(address => 10; style)
v = PDVec(address => 10; style, initiator)
```
if threading is available or
if threading is available, or otherwise
```julia
v = DVec(address => 10; style)
```
otherwise. See [`PDVec`](@ref), [`DVec`](@ref) and [`StochasticStyle`](@ref).
if `initiator == NonInitiator()`, and
```julia
v = InitiatorDVec(address => 10; style, initiator)
```
if not. See [`PDVec`](@ref), [`DVec`](@ref), [`InitiatorDVec`](@ref),
[`StochasticStyle`](@ref), and [`InitiatorRule`].
"""
function default_starting_vector(
hamiltonian::AbstractHamiltonian;
Expand All @@ -307,14 +312,17 @@ end
function default_starting_vector(address;
style=IsStochasticInteger(),
threading=nothing,
initiator=NonInitiator(),
)
if isnothing(threading)
threading = Threads.nthreads() > 1
end
if threading
v = PDVec(address => 10; style)
else
v = PDVec(address => 10; style, initiator)
elseif initiator isa NonInitiator
v = DVec(address => 10; style)
else
v = InitiatorDVec(address => 10; style, initiator)
end
return v
end
Expand All @@ -336,6 +344,8 @@ Alternatively, a `QMCState` can be passed in to continue a previous simulation.
* `address = starting_address(ham)` - set starting address for default `v` and `shift`.
* `style = IsStochasticInteger()` - set [`StochasticStyle`](@ref) for default `v`; unused
if `v` is specified.
* `initiator = NonInitiator()` - set [`InitiatorRule`](@ref) for default `v`; unused if `v`
is specified.
* `threading` - default is to use multithreading and
[MPI](https://juliaparallel.org/MPI.jl/latest/) if multiple threads are available. Set to
`true` to force [`PDVec`](@ref) for the starting vector, `false` for serial computation;
Expand Down Expand Up @@ -403,9 +413,9 @@ julia> metadata(df2, "hamiltonian") # some metadata is automatically added
be passed for merging with the report `df`.
The default choice for the starting vector is
`v = default_starting_vector(; address, style, threading)`.
See [`default_starting_vector`](@ref), [`PDVec`](@ref), [`DVec`](@ref), and
[`StochasticStyle`](@ref).
`v = default_starting_vector(; address, style, threading, initiator)`.
See [`default_starting_vector`](@ref), [`PDVec`](@ref), [`DVec`](@ref),
[`StochasticStyle`](@ref), and [`InitiatorRule`](@ref).
"""
function lomc!(ham, v; df=DataFrame(), name="lomc!", metadata=nothing, kwargs...)
state = QMCState(ham, v; kwargs...)
Expand All @@ -416,9 +426,10 @@ function lomc!(
style=IsStochasticInteger(),
threading=nothing,
address=starting_address(ham),
initiator=NonInitiator(),
kwargs...
)
v = default_starting_vector(address; style, threading)
v = default_starting_vector(address; style, threading, initiator)
return lomc!(ham, v; address, kwargs...) # pass address for setting the default shift
end
# For continuation, you can pass a QMCState and a DataFrame
Expand Down
3 changes: 3 additions & 0 deletions test/lomc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ using DataFrames

df, state = lomc!(H; laststep=100, style = IsDeterministic())
@test StochasticStyle(state.replicas[1].v) isa IsDeterministic

df, state = lomc!(H; laststep=1, threading=false, initiator=Initiator())
@test state.replicas[1].v isa InitiatorDVec
end

@testset "ShiftStrategy" begin
Expand Down

0 comments on commit 76788cc

Please sign in to comment.