Skip to content

Add Fock distribution bar chart visualization#238

Open
Aniket-umass wants to merge 3 commits into
qojulia:masterfrom
Aniket-umass:makie-fock-distribution
Open

Add Fock distribution bar chart visualization#238
Aniket-umass wants to merge 3 commits into
qojulia:masterfrom
Aniket-umass:makie-fock-distribution

Conversation

@Aniket-umass

@Aniket-umass Aniket-umass commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Fock distribution bar chart visualization

Adds a fockdistributionplot recipe to the Makie extension, visualizing the
Fock-state (number-state) occupation probabilities P(n) of a quantum state as a
bar chart. This mirrors QuTiP's plot_fock_distribution and complements the
existing Bloch sphere (spin) and Wigner (phase-space) plotters, extending
visualization coverage to the Fock basis.

What it does

  • For a Ket, plots P(n) = |⟨n|ψ⟩|².
  • For a density operator, plots the diagonal P(n) = ⟨n|ρ|n⟩.
  • Default styling matches QuTiP: translucent green bars, y-axis fixed to [0, 1]
    (toggle with unit_y_range=false), x = "Fock number", y = "Occupation probability".

API

  • fockdistributionplot(state; kwargs...) / fockdistributionplot!(ax, state; kwargs...)
  • fockdistributionplot_axis([ax,] state; kwargs...) -> (Figure, Axis, Plot)
  • Attributes: color, alpha, width; axis kwarg: unit_y_range.

When no Makie backend is loaded, calling these gives a normal MethodError
with a hint to load one (via Base.Experimental.register_error_hint).

Tests

test/test_fock_plotting.jl (tag :plotting) covers return types, rendering of
coherent / number / thermal states, custom attributes, the unit_y_range
toggle, and Observable reactivity.

Notes

  • No Project.toml changes — reuses the Makie weakdep/extension already in place.

Example:-
Screenshot 2026-06-22 at 11 24 48 PM

Comment thread ext/QuantumOpticsBaseMakieExt.jl Outdated
Comment on lines +159 to +161
color = :green,
alpha = 0.6,
width = 0.8,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would stick to Makie defaults here, especially color

@Aniket-umass

Copy link
Copy Markdown
Contributor Author

Hello Stefan,
WeakDepHelpers forces julia version 1.12, hence using it would mean the 1.10 jobs in the CI workflow will go red.

@Krastanov

Copy link
Copy Markdown
Member

You can proceed with adding support for julia 1.10 to WeakDepHelpers

@Aniket-umass

Copy link
Copy Markdown
Contributor Author

I have added the support for WeakDepHelpers. Once that PR is merged, the failed tests will pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants