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

Add boltzmann sampling functionality, closes #34 #35

Merged
merged 4 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QuantumAnnealing.jl Change Log
==============================

### Staged
- nothing
- Add Gibbs distribution

### v0.2.0
- Add a generic Magnus expansion solver for any order
Expand Down
7 changes: 7 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,10 @@ function print_z_state_probabilities(density::Matrix; limit=50, sort=false)
end
end
end

function distribution_gibbs(H::Function, s::Real, β::Real)
tr(A) = sum([A[i,i] for i=1:(size(A)[1])])
exp_ham = exp(-β * Matrix(H(s)))
exp_ham = exp_ham ./ tr(exp_ham)
return exp_ham
end
5 changes: 4 additions & 1 deletion test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ end
@test isapprox(H_10, [2.0 0.0 0.0 0.0; 0.0 -2.0 0.0 0.0; 0.0 0.0 -2.0 0.0; 0.0 0.0 0.0 2.0])
end

@testset "boltzmann sampling, 1 qubit" begin
@test isapprox(z_measure_probabilities(distribution_gibbs(one_spin_H, 0, 1)), [0.5, 0.5])
@test isapprox(z_measure_probabilities(distribution_gibbs(one_spin_H, 1, 100)), [0, 1])
end
end


Expand Down Expand Up @@ -213,4 +217,3 @@ end
end