Skip to content

Commit

Permalink
Updates for QA v0.2 (#18)
Browse files Browse the repository at this point in the history
* updates for latest function naming conventions and simulation interface
* prep for next release, v0.2
  • Loading branch information
ccoffrin authored Mar 28, 2022
1 parent 06815bb commit 237025b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ QuantumAnnealingAnalytics.jl Change Log
### Staged
- nothing

### v0.2.0
- Updates for QuantumAnnealing v0.2

### v0.1.0
- Initial release
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "QuantumAnnealingAnalytics"
uuid = "f4de928d-7c93-4858-9dcf-40bc6948a1da"
authors = ["Zach Morrell, Carleton Coffrin"]
repo = "https://github.com/lanl-ansi/QuantumAnnealingAnalytics.jl"
version = "0.1.0"
version = "0.2.0"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand All @@ -12,7 +12,7 @@ QuantumAnnealing = "4832667a-bab9-40a8-88f6-be9efce3ea89"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
QuantumAnnealing = "~0.1"
QuantumAnnealing = "~0.2"
Plots = "~1, ~0.29"
JSON = "~0.21, ~0.20, ~0.19, ~0.18"
julia = "1.6"
Expand Down
4 changes: 2 additions & 2 deletions src/base.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function spin_hamming_distance(spin_1, spin_2)
x = _QA.spin2int(spin_1)
y = _QA.spin2int(spin_2)
x = _QA.spin_to_int(spin_1)
y = _QA.spin_to_int(spin_2)

#Kernighan's Algorithm
diff_bits = xor(x,y)
Expand Down
14 changes: 7 additions & 7 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ kwargs are for Plots.bar
function plot_states(ρ; order=:numeric, spin_comp=ones(Int(log2(size(ρ)[1]))), num_states=16, ising_model=nothing, energy_levels=0, kwargs...)
state_probs = _QA.z_measure_probabilities(ρ)
n = Int(log2(length(state_probs)))
state_spin_vecs = map((x) -> _QA.int2spin(x,pad=n), 0:2^n-1)
state_spin_vecs = map((x) -> _QA.int_to_spin(x,pad=n), 0:2^n-1)

states = [(prob = state_probs[i], spin_vec = state_spin_vecs[i]) for i = 1:length(state_probs)]

sortby = nothing
if order == :numeric
sortby = (x) -> _QA.spin2int(x.spin_vec)
sortby = (x) -> _QA.spin_to_int(x.spin_vec)
elseif order == :hamming
if length(spin_comp) != n
error("invalid spin_comp length")
Expand All @@ -35,7 +35,7 @@ function plot_states(ρ; order=:numeric, spin_comp=ones(Int(log2(size(ρ)[1]))),
end

kept_states = _get_states(ising_model, energy_levels, n = n)
filter_function = (x) -> _QA.spin2int(x.spin_vec) in kept_states
filter_function = (x) -> _QA.spin_to_int(x.spin_vec) in kept_states
states = filter(filter_function, states)

states = sort(states, by=sortby)
Expand Down Expand Up @@ -73,7 +73,7 @@ function plot_ground_states_dwisc(dw::Dict{String,<:Any}; order=:numeric, spin_c

sortby = nothing
if order == :numeric
sortby = (x) -> _QA.spin2int(x["solution"])
sortby = (x) -> _QA.spin_to_int(x["solution"])
elseif order == :hamming
if spin_comp == []
spin_comp = ones(n)
Expand Down Expand Up @@ -125,7 +125,7 @@ function plot_states_dwisc(dw::Dict{String,<:Any}; order=:numeric, spin_comp=[],
n = length(states[1]["solution"])
sortby = nothing
if order == :numeric
sortby = (x) -> _QA.spin2int(x["solution"])
sortby = (x) -> _QA.spin_to_int(x["solution"])
elseif order == :hamming
if spin_comp == []
spin_comp = ones(n)
Expand Down Expand Up @@ -176,7 +176,7 @@ function plot_state_steps(state_steps; ising_model=nothing, energy_levels=0, kwa
kept_states = _get_states(ising_model, energy_levels, n = n)
kept_indices = kept_states .+ 1

int2braket(i) = _QA.spin2braket(_QA.int2spin(i,pad=n))
int2braket(i) = _QA.spin_to_braket(_QA.int_to_spin(i,pad=n))
labels = map(int2braket, reshape(kept_states,1,:))

plotted_states = plotted_states[kept_indices,:]
Expand Down Expand Up @@ -216,7 +216,7 @@ function plot_varied_time_simulations(ising_model::Dict, annealing_schedule::_QA
xlabel = "annealing time"
ylabel = "probability"

int2braket(i) = _QA.spin2braket(_QA.int2spin(i,pad=n))
int2braket(i) = _QA.spin_to_braket(_QA.int_to_spin(i,pad=n))
labels = map(int2braket, reshape(kept_states,1,:))
legend = :topleft
plt = Plots.plot(annealing_times, plotted_values; title=title, xlabel=xlabel, ylabel=ylabel, label=labels, legend=legend, xscale=xscale, kwargs...)
Expand Down
10 changes: 5 additions & 5 deletions test/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

@testset "plotting states from ising dict, 1q" begin
ising = Dict((1,) => 1)
ρ = simulate(ising, 100, AS_CIRCULAR, 100)
ρ = simulate(ising, 10, AS_CIRCULAR, silence=true)

@testset "single qubit plot, numeric sorting, no kwargs" begin
plt = plot_states(ρ, order=:numeric)
Expand Down Expand Up @@ -61,7 +61,7 @@ end

@testset "plotting states from ising dict, 2q" begin
ising = Dict((1,) => 1, (2,) => 1, (1,2) => -1)
ρ = simulate(ising, 100, AS_CIRCULAR, 100)
ρ = simulate(ising, 10, AS_CIRCULAR, silence=true)

@testset "two qubit plot, numeric sorting, no kwargs" begin
plt = plot_states(ρ,order=:numeric)
Expand Down Expand Up @@ -517,7 +517,7 @@ end
@testset "plotting single qubit state steps" begin
state_steps = []
ising = Dict((1,) => 1)
ρ = simulate(ising, 100, AS_CIRCULAR, 100, state_steps=state_steps)
ρ = simulate(ising, 10, AS_CIRCULAR, silence=true, state_steps=state_steps)

@testset "single qubit, no kwargs" begin
plt = plot_state_steps(state_steps)
Expand All @@ -534,7 +534,7 @@ end
@testset "plotting single qubit state steps" begin
state_steps = []
ising = Dict((1,) => 1, (2,) => 1, (1,2) => -1)
ρ = simulate(ising, 100, AS_CIRCULAR, 100, state_steps=state_steps)
ρ = simulate(ising, 10, AS_CIRCULAR, silence=true, state_steps=state_steps)

@testset "single qubit, no kwargs" begin
plt = plot_state_steps(state_steps)
Expand All @@ -558,7 +558,7 @@ end

@testset "plotting hamiltonian energy spectrum" begin
ising_model = Dict((1,) => 1, (2,) => -.25, (1,2) => -.9)
H(s) = transverse_ising_hamiltonian(ising_model, AS_CIRCULAR, s)
H(s) = hamiltonian_transverse_ising(ising_model, AS_CIRCULAR, s)
@testset "No parameters" begin
plt = plot_hamiltonian_energy_spectrum(H)
@test true
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using QuantumAnnealing
using JSON
using Test

@testset "QuantumAnnealing" begin
@testset "QuantumAnnealingAnalytics" begin

include("base.jl")

Expand Down

2 comments on commit 237025b

@ccoffrin
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 register v0.2.0

@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/57434

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 v0.2.0 -m "<description of version>" 237025b2f0c15f98bcd0809164df9da03966413a
git push origin v0.2.0

Please sign in to comment.