Skip to content

Make ObserveGlobal sampling deterministic #7

Description

@hutchpd

Problem

PartialObserve appears to use stable ordering when sampling outcomes, but ObserveGlobal appears to iterate over probability sums without the same deterministic ordering.

This may cause seeded randomness to produce different results depending on dictionary iteration order.

Why this matters

The project has replay/convergence/determinism concepts, so seeded observations should behave predictably.

Unstable ordering can make tests flaky and make replay behaviour harder to reason about.

Suggested approach

Apply a stable ordering in ObserveGlobal before sampling outcomes, similar to the ordering already used in PartialObserve.

For example, order basis states by their bit/index representation before accumulating probabilities.

Acceptance criteria

  • ObserveGlobal produces the same result for the same seed and same wavefunction across repeated runs.
  • Existing observation behaviour is preserved except for improved determinism.
  • A regression test is added for stable seeded global observation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions