Skip to content

Commit

Permalink
update plot_states defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoffrin committed Mar 25, 2024
1 parent be92803 commit c193593
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ QuantumAnnealingAnalytics.jl Change Log
=======================================

### Staged
- Change `plot_states` to show all states by default (fix)
- Add ground energy shift option to hamiltonian energy plots
- Add Ising model graph plotting

Expand Down
16 changes: 10 additions & 6 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
function to plot the states present in a density matrix output by QuantumAnnealing.simulate
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...)
function plot_states(ρ; order=:numeric, spin_comp=ones(Int(log2(size(ρ)[1]))), num_states=0, 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.int_to_spin(x,pad=n), 0:2^n-1)
Expand Down Expand Up @@ -42,12 +42,16 @@ function plot_states(ρ; order=:numeric, spin_comp=ones(Int(log2(size(ρ)[1]))),
probs = [states[i].prob for i = 1:length(states)]
strings = map(x -> join(string.(x.spin_vec),"\n"), states)

num_states = min(num_states, length(states))
num_state_bars = length(states)
if num_states > 0
num_state_bars = min(num_states, num_state_bars)

Check warning on line 47 in src/plot.jl

View check run for this annotation

Codecov / codecov/patch

src/plot.jl#L47

Added line #L47 was not covered by tests
end
mm = Measures.mm
plt = Plots.bar(probs[1:num_states]; xticks = (1:num_states,strings[1:num_states]),
size = (900,600),bottom_margin=10mm, xlabel="spin state",
ylabel = "probability",title="State Probabilities of ρ",label="prob",
legend = :none, kwargs...)
plt = Plots.bar(probs[1:num_state_bars]; xticks = (1:num_state_bars,strings[1:num_state_bars]),
size = (900,600),bottom_margin=10mm, xlabel="spin state",
ylabel = "probability",title="State Probabilities of ρ",label="prob",
legend = :none, kwargs...
)
return plt
end

Expand Down

0 comments on commit c193593

Please sign in to comment.