Skip to content

Improve expect implementation and tests - #383

Merged
mtfishman merged 1 commit into
mainfrom
expect_tests
Aug 25, 2026
Merged

mtfishman merged 1 commit into
mainfrom
expect_tests

Conversation

@emstoudenmire

@emstoudenmire emstoudenmire commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Improve implementation and tests of expect to ensure return value is a dictionary when no vertices passed and a vector when a vector of vertices is passed.

Call -> Returns

expect(ψ, "Sz")   -> OrderedDictionary{Tuple{Int,Int}, Float64} 
 Note: sz[(1,2)] works
expect(ψ, "Sz", [v3, v1, v2]) -> Vector{Float64} 
Note: in that exact order    
expect(ψ, "Sz", (v1, v2)) -> Tuple{Float64, Float64} (falls out for free) 
expect(ψ, Op("Sz", v))  -> Float64    

Two notes on the whole-network case:

The type is OrderedDictionary, not Dictionaries.Dictionary. vertices(ψ) is a
NamedGraphs.OrderedDictionaries.OrderedIndices, so map over it yields the matching OrderedDictionary — an
AbstractDictionary keyed by vertex, iterating in vertices(ψ) order.

Element types stay concrete — Float64, not Any. Going through Indices/Dictionary directly widens to Any because
Dictionaries.jl sizes the output by inference and expect's contract(...)[] doesn't infer; OrderedDictionary's map
doesn't have that problem.

…a dictionary when no vertices passed and a vector when a vector of vertices is passed.
@mtfishman

Copy link
Copy Markdown
Member

Looks good, thanks!

@mtfishman
mtfishman merged commit 3049849 into main Aug 25, 2026
16 checks passed
@mtfishman
mtfishman deleted the expect_tests branch August 25, 2026 16:26
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.

3 participants