Skip to content

Make EnhancedOccupancy seeds reproducible - #191

Open
danielgaskins wants to merge 2 commits into
google:copybara_pushfrom
danielgaskins:fix/enhanced-occupancy-stable-seeds
Open

danielgaskins wants to merge 2 commits into
google:copybara_pushfrom
danielgaskins:fix/enhanced-occupancy-stable-seeds

Conversation

@danielgaskins

@danielgaskins danielgaskins commented Sep 20, 2026 •

Copy link
Copy Markdown

Fixes #190

EnhancedOccupancy used Python's randomized string hashes to seed worker assignments, behavior, daily schedules, and weekend decisions. Starting a new Python process could change the results of the same simulation.

This uses stable 32-bit seeds derived from SHA-256. Schedules differ from the old hash-based ones and stay repeatable across restarts. Tests check the seed value and run the same model in separate interpreters with different Python hash seeds.

All 13 occupancy tests pass with python -m unittest smart_control.simulator.enhanced_occupancy_test -q. Pyink, isort, and whitespace checks pass.

  • Tests pass
  • No documentation changes are needed for this bug fix

@s2t2

s2t2 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

@danielgaskins could you please elaborate on the issue that this PR is solving?

Also, I would welcome @amcberkes comments and review on this PR.

@danielgaskins

Copy link
Copy Markdown
Author

The issue is that Python's string hash() changes between processes, and this model uses it to seed its random generators.

I reran the 20-person office example in the new cross-process test with PYTHONHASHSEED=1 and 2. On the old code, the worker counts changed from 10 weekday / 6 regular-weekend / 4 occasional-weekend workers to 8 / 4 / 8, and the hourly occupancy changed too. This branch gives 9 / 7 / 4 and the same hourly profile in both runs.

The schedules differ from the old hash-based ones, but restarting Python no longer changes them. I added a test that starts two separate interpreters and compares the worker counts and weekday/weekend profiles. All 13 occupancy tests pass.

This branch has not been deployed

No deployments
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.

EnhancedOccupancy results change across Python processes

2 participants