Skip to content

Commit

Permalink
Add minimum_size keyword argument to ProjectorMonteCarloProblem
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-tay committed Nov 24, 2024
1 parent 522260a commit c8ffb31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/pmc_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mutable struct PMCSimulation
end

function _set_up_starting_vectors(
ham, start_at, n_replicas, n_spectral, style, initiator, threading, copy_vectors
ham, start_at, n_replicas, n_spectral, style, initiator, threading, copy_vectors, minimum_size
)
if start_at isa AbstractMatrix && size(start_at) == (n_replicas, n_spectral)
if eltype(start_at) <: Union{AbstractDVec, RMPI.MPIData} # already dvecs
Expand All @@ -36,8 +36,7 @@ function _set_up_starting_vectors(
)
end
elseif n_spectral > 1
basis = build_basis(ham; minimum_size=n_spectral*5)
basis = sort!(basis; by=x -> diagonal_element(ham, x))
basis = build_basis(ham; minimum_size)
trunc = BasisSetRepresentation(ham, basis; filter=Returns(false), sizelim=Inf)
vecs = eigvecs(Matrix(trunc))
if threading
Expand Down Expand Up @@ -81,7 +80,7 @@ function PMCSimulation(problem::ProjectorMonteCarloProblem; copy_vectors=true)
@unpack algorithm, hamiltonian, start_at, style, threading, simulation_plan,
replica_strategy, initial_shift_parameters,
reporting_strategy, post_step_strategy,
maxlength, metadata, initiator, random_seed, spectral_strategy = problem
maxlength, metadata, initiator, random_seed, spectral_strategy, minimum_size = problem

reporting_strategy = refine_reporting_strategy(reporting_strategy)

Expand All @@ -96,7 +95,7 @@ function PMCSimulation(problem::ProjectorMonteCarloProblem; copy_vectors=true)
start_at = isnothing(start_at) ? starting_address(hamiltonian) : start_at
vectors = _set_up_starting_vectors(
hamiltonian, start_at, n_replicas, n_spectral, style, initiator,
threading, copy_vectors
threading, copy_vectors, minimum_size
)
@assert vectors isa SMatrix{n_replicas, n_spectral}

Expand Down
8 changes: 7 additions & 1 deletion src/projector_monte_carlo_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ julia> size(DataFrame(simulation))
`true`, a random seed is generated. If set to number, this number is used as the seed.
The seed is used by `solve` such that `solve`ing the problem twice will yield identical
results. If set to `false`, no seed is used and results are not reproducible.
- `minimum_size = 2*num_spectral_states(spectral_strategy)`: The minimum size of the basis
used to construct starting vectors for simulations of spectral states, if `start_at`
is not provided.
See also [`init`](@ref), [`solve`](@ref).
"""
Expand All @@ -117,6 +120,7 @@ struct ProjectorMonteCarloProblem{N,S} # is not type stable but does not matter
maxlength::Int
metadata::LittleDict{String,String} # user-supplied metadata + display_name
random_seed::Union{Nothing,UInt64}
minimum_size::Int
end

function Base.show(io::IO, p::ProjectorMonteCarloProblem)
Expand Down Expand Up @@ -164,6 +168,7 @@ function ProjectorMonteCarloProblem(
reporting_strategy = ReportDFAndInfo(),
post_step_strategy = (),
spectral_strategy = GramSchmidt(),
minimum_size = 2*num_spectral_states(spectral_strategy),
maxlength = nothing,
metadata = nothing,
display_name = "PMCSimulation",
Expand Down Expand Up @@ -236,7 +241,8 @@ function ProjectorMonteCarloProblem(
spectral_strategy,
maxlength,
metadata,
random_seed
random_seed,
minimum_size
)
end

Expand Down

0 comments on commit c8ffb31

Please sign in to comment.