Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observables #278

Merged
merged 23 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d7e8da3
Allow Vector's of AbstractHamiltonian's in AllOverlaps
joachimbrand Jul 30, 2024
cc18663
allows_address_type replaces allowed_address_type in the AbstractHami…
joachimbrand Aug 13, 2024
3646bf1
valtype for AbstractHamiltonian and ProjectorMonteCarloProblem
joachimbrand Jul 29, 2024
e93bc88
fix docs
joachimbrand Aug 13, 2024
0cc547d
attempt to fix docs
joachimbrand Aug 14, 2024
597aa41
AbstractOperator
joachimbrand Aug 14, 2024
5a66016
use VectorInterface.scalartype for AbstractOperators (instead of Base…
joachimbrand Aug 15, 2024
0c24884
move dot_from_right to Interfaces.jl
joachimbrand Aug 15, 2024
c0e9b35
fix tests
joachimbrand Aug 15, 2024
c32e4f7
make correlators AbstractOperator
joachimbrand Aug 15, 2024
81dd162
fix docs
joachimbrand Aug 15, 2024
a9ba94a
docs
joachimbrand Aug 15, 2024
17e6bc3
fix error in test
joachimbrand Aug 15, 2024
e232626
test_operator_interface
joachimbrand Aug 17, 2024
b1b49b1
fix test
joachimbrand Aug 17, 2024
aa89674
test operator interface for G2RealSpace
joachimbrand Aug 18, 2024
80c8ba3
fix test
joachimbrand Aug 18, 2024
10990ae
changes to call structure of StringCorrelator
joachimbrand Aug 18, 2024
4138a88
fix docs
joachimbrand Aug 18, 2024
93d14ea
demote ParticleNumberOperator to AbstractHamiltonian;
joachimbrand Aug 18, 2024
ad7dd8f
make SingleParticleExcitation and TwoParticleExcitation AbstractOperator
joachimbrand Aug 19, 2024
fd93a21
Momentum is AbstractOperator
joachimbrand Aug 19, 2024
db0f2ed
Hamiltonian interface test for momentum
joachimbrand Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
valtype for AbstractHamiltonian and ProjectorMonteCarloProblem
error message if using complex Hamiltonian with ProjectorMonteCarloProblem
  • Loading branch information
joachimbrand committed Aug 19, 2024
commit 3646bf1aacff08caa2fd1af72bef969b6aa37058
1 change: 1 addition & 0 deletions src/Hamiltonians/correlation_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function Base.show(io::IO, g2::G2RealSpace{0,0})
end

LOStructure(::Type{<:G2RealSpace}) = IsDiagonal()
Base.valtype(::G2RealSpace) = Float64 # needed because eltype is a vector

num_offdiagonals(g2::G2RealSpace, _) = 0

Expand Down
3 changes: 2 additions & 1 deletion src/Interfaces/hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ See also [`Hamiltonians`](@ref Main.Hamiltonians), [`Interfaces`](@ref).
"""
abstract type AbstractHamiltonian{T} end

Base.eltype(::AbstractHamiltonian{T}) where {T} = T
Base.eltype(::AbstractHamiltonian{T}) where {T} = T # could be vector value
Base.valtype(h::AbstractHamiltonian) = eltype(h) # type of underlying scalar values

"""
allows_address_type(operator, addr_or_type)
Expand Down
7 changes: 7 additions & 0 deletions src/projector_monte_carlo_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ function ProjectorMonteCarloProblem(
post_step_strategy = (post_step_strategy,)
end

if !(eltype(hamiltonian)<: Real)
throw(ArgumentError("Only real-valued Hamiltonians are currently supported "*
"for ProjectorMonteCarloProblem. Please get in touch with the Rimu.jl " *
"developers if you need a complex-valued Hamiltonian!"))
end

return ProjectorMonteCarloProblem{n_replicas,num_spectral_states(spectral_strategy)}(
algorithm,
hamiltonian,
Expand All @@ -240,3 +246,4 @@ end

num_replicas(::ProjectorMonteCarloProblem{N}) where N = N
num_spectral_states(::ProjectorMonteCarloProblem{<:Any,S}) where {S} = S
Base.valtype(p::ProjectorMonteCarloProblem) = valtype(p.hamiltonian)
4 changes: 4 additions & 0 deletions test/Hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@ using Rimu.Hamiltonians: circshift_dot
@test eval(Meta.parse(repr(g2_2))) == g2_2
@test eval(Meta.parse(repr(g2_3))) == g2_3

@test valtype(g2_1) == Float64
@test valtype(g2_2) == Float64
@test valtype(g2_3) == Float64

@test_throws ArgumentError G2RealSpace(CubicGrid(3), 1, 0)
@test_throws ArgumentError G2RealSpace(CubicGrid(2, 2), 0, 0)
@test_throws ArgumentError G2RealSpace(CubicGrid(1, 2, 3), -1, 2)
Expand Down
6 changes: 6 additions & 0 deletions test/projector_monte_carlo_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using OrderedCollections: freeze
h = HubbardReal1D(BoseFS(1,3))
p = ProjectorMonteCarloProblem(h; threading=true)
@test p.hamiltonian == h
@test valtype(p.hamiltonian) == valtype(h)

@test Rimu.num_replicas(p) == 1
@test startswith(sprint(show, p), "ProjectorMonteCarloProblem with 1 replica(s)")
Expand Down Expand Up @@ -72,6 +73,11 @@ using OrderedCollections: freeze
@test state_vectors(sm)[1] === dv1
@test state_vectors(sm)[2] === dv2
@test_throws BoundsError sm.state.spectral_states[3]

# complex Hamiltonian
h = HubbardReal1D(BoseFS(1, 3); u=1.0 + 1.0im)
@test valtype(h) <: Complex
@test_throws ArgumentError ProjectorMonteCarloProblem(h)
end

@testset "PMCSimulation" begin
Expand Down