Skip to content

Commit

Permalink
fix state types
Browse files Browse the repository at this point in the history
  • Loading branch information
lpawela committed Apr 24, 2024
1 parent dafe813 commit 967bd77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpinGlassNetworks"
uuid = "b7f6bd3e-55dc-4da6-96a9-ef9dbec6ac19"
authors = ["Anna Maria Dziubyna <[email protected]>", "Tomasz Śmierzchalski <[email protected]>", "Bartłomiej Gardas <[email protected]>", "Konrad Jałowiecki <[email protected]>", "Łukasz Pawela <[email protected]>", "Marek M. Rams <[email protected]>"]
version = "1.1.0"
version = "1.1.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
20 changes: 15 additions & 5 deletions src/spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export all_states,
@inline local_basis(d::Int) = union(-1, 1:d-1)
all_states(rank::Union{Vector,NTuple}) = Iterators.product(local_basis.(rank)...)

const State = Vector{Int}
const State = Vector{<:Integer}

"""
$(TYPEDSIGNATURES)
Expand All @@ -38,7 +38,11 @@ struct Spectrum
function Spectrum(energies, states, states_int)
new(energies, states, states_int)
end
function Spectrum(energies, states)
function Spectrum(energies, states::Matrix)
states_int = matrix_to_integers(states)
new(energies, Vector{eltype(states)}[eachcol(states)...], states_int)
end
function Spectrum(energies, states::Vector{<:State})
states_int = matrix_to_integers(states)
new(energies, states, states_int)
end
Expand All @@ -63,6 +67,12 @@ function matrix_to_integers(matrix::Vector{Vector{T}}) where {T}
div.((hcat(matrix...)' .+ 1), 2) * multipliers
end

function matrix_to_integers(matrix::Matrix)
nrows = size(matrix, 1)
multipliers = 2 .^ collect(0:nrows-1)
div.(matrix' .+ 1, 2) * multipliers
end

"""
energy(σ::Vector, ig::IsingGraph)
Expand All @@ -78,7 +88,7 @@ The energy is computed based on the interactions between spins and their associa
# Returns:
- `Vector{Float64}`: An array of energy values for each state.
"""
function energy::AbstractArray{State}, ig::IsingGraph)
function energy::AbstractArray{<:State}, ig::IsingGraph)
J, h = couplings(ig), biases(ig)
dot.(σ, Ref(J), σ) + dot.(Ref(h), σ)
end
Expand Down Expand Up @@ -204,9 +214,9 @@ function full_spectrum(ig::IsingGraph{T}; num_states::Int = 1) where {T}
end

function inter_cluster_energy(
cl1_states::Vector{State},
cl1_states::Vector{<:State},
J::Matrix{<:Real},
cl2_states::Vector{State},
cl2_states::Vector{<:State},
)
hcat(collect.(cl1_states)...)' * J * hcat(collect.(cl2_states)...)
end

2 comments on commit 967bd77

@lpawela
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105591

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.1 -m "<description of version>" 967bd7751f5aef1c5da33d07c9d52a5ba7ae1c13
git push origin v1.1.1

Please sign in to comment.