Skip to content

Commit

Permalink
fix tests, kwarg address
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimbrand committed Nov 25, 2023
1 parent 18ca359 commit fe1b9c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/lomc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ function QMCState(
=nothing,
shift=nothing,
wm=nothing,
style=nothing,
targetwalkers=1000,
address=starting_address(hamiltonian),
params::FciqmcRunStrategy=RunTillLastStep(
laststep = 100,
shift = float(valtype(v))(diagonal_element(hamiltonian, first(keys(localpart(v)))))
shift = float(valtype(v))(diagonal_element(hamiltonian, address))
),
s_strat::ShiftStrategy=DoubleLogUpdate(; targetwalkers),
r_strat::ReportingStrategy=ReportDFAndInfo(),
Expand All @@ -169,8 +171,8 @@ function QMCState(
if threading nothing
@warn "Starting vector is provided. Ignoring `threading=$threading`."
end
if starting_address nothing
@warn "Starting vector is provided. Ignoring `starting_address=$starting_address`."
if style nothing
@warn "Starting vector is provided. Ignoring `style=$style`."
end
wm = isnothing(wm) ? working_memory(v) : wm

Expand Down Expand Up @@ -295,7 +297,7 @@ Alternatively, a `QMCState` can be passed in to continue a previous simulation.
* `targetwalkers = 1000` - target for the 1-norm of the coefficient vector.
* `style = IsStochasticInteger()` - set [`StochasticStyle`](@ref) for default `v`; unused
if `v` is specified.
* `starting_address = starting_address(ham)` - set starting address for default `v`; unused
* `address = starting_address(ham)` - set starting address for default `v`; unused
if `v` is specified.
* `threading = true` - use multithreading if available; unused if `v` is specified.
* `post_step::NTuple{N,<:PostStepStrategy} = ()` - extract observables (e.g.
Expand Down Expand Up @@ -352,7 +354,7 @@ julia> metadata(df2, "hamiltonian") # some metadata is automatically added
* `maxlength = 2 * s_strat.targetwalkers + 100` - upper limit on the length of `v`; when
reached, `lomc!` will abort
* `params::FciqmcRunStrategy = RunTillLastStep(laststep = 100, dτ = 0.01, shift =
diagonal_element(ham, first(keys(localpart(v))))` -
diagonal_element(ham, starting_address(ham))` -
basic parameters of simulation state, see [`FciqmcRunStrategy`](@ref). Parameter values
are overridden by explicit keyword arguments `laststep`, `dτ`, `shift`; is mutated.
* `wm` - working memory for re-use in subsequent calculations; is mutated.
Expand All @@ -379,15 +381,15 @@ function lomc!(
ham;
style=IsStochasticInteger(),
threading=true,
starting_address=starting_address(ham),
address=starting_address(ham),
kwargs...
)
if Threads.nthreads() > 1 && threading
v = PDVec(starting_address => 10; style)
v = PDVec(address => 10; style)
else
v = DVec(starting_address => 10; style)
v = DVec(address => 10; style)
end
return lomc!(ham, v; kwargs...)
return lomc!(ham, v; address, kwargs...) # pass address for setting the default shift
end
# For continuation, you can pass a QMCState and a DataFrame
function lomc!(state::QMCState, df=DataFrame(); laststep=0, name="lomc!", metadata=nothing)
Expand Down
8 changes: 4 additions & 4 deletions test/Hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ end
Lz = AxialAngularMomentumHO(S; addr)
Ly = AxialAngularMomentumHO(S; z_dim=2, addr)
Lx = AxialAngularMomentumHO(S; z_dim=1, addr)

Lz_vals = eigvals(Matrix(BasisSetRep(Lz)))
Ly_vals = eigvals(Matrix(BasisSetRep(Ly)))
Lx_vals = eigvals(Matrix(BasisSetRep(Lx)))
Expand Down Expand Up @@ -1467,8 +1467,8 @@ end
df = get_all_blocks(H; save_to_file = "test_block_df.arrow")
df_file = load_df("test_block_df.arrow")
@test df[!,[1,2,3,5]] == df_file[!,[1,2,3,5]]
# HOCartesianContactInteractions requires a valid energy restriction

# HOCartesianContactInteractions requires a valid energy restriction
@test_throws ArgumentError get_all_blocks(HOCartesianContactInteractions(addr; S))

# block_by_level = false
Expand All @@ -1492,7 +1492,7 @@ end

@test Hamiltonians.index((3,2,1)) == 1
@test Hamiltonians.index((5,4,3)) == 10
end
end

@testset "HO utilities" begin
S = (4,4)
Expand Down
2 changes: 1 addition & 1 deletion test/lomc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using DataFrames
add = BoseFS{5,2}((2,3))
H = HubbardReal1D(add; u=0.1)
dv = DVec(add => 1; style=IsStochasticInteger())
df, state = lomc!(H, v; laststep=0, shift=23.1, dτ=0.002)
df, state = lomc!(H, dv; laststep=0, shift=23.1, dτ=0.002)
@test state.replicas[1].params.== state.== 0.002
@test state.replicas[1].params.shift == state.shift == 23.1
state.= 0.004
Expand Down

0 comments on commit fe1b9c6

Please sign in to comment.