Skip to content

Automatically choose batch size based on available memory#84

Merged
rafaelha merged 6 commits intomainfrom
rafaelha/estimate_batch_size
Mar 31, 2026
Merged

Automatically choose batch size based on available memory#84
rafaelha merged 6 commits intomainfrom
rafaelha/estimate_batch_size

Conversation

@rafaelha
Copy link
Copy Markdown
Collaborator

This should be a UX improvement. Previously, batch_size was always chosen as shots when not specified, and I have heard of multiple users crashing their kernel when requesting many shots.

Now, a simple memory model is used and Tsim chooses the batch size to approximately use half of the available memory.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1988 1931 97% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/tsim/sampler.py 96% 🟢
TOTAL 96% 🟢

updated for commit: ab094eb by action🐍

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves sampler UX by making batch_size default to an automatic value derived from an estimated per-sample memory footprint and currently available memory, reducing the chance of OOM crashes when requesting many shots.

Changes:

  • Add automatic batch size selection when batch_size is not provided.
  • Add unit test coverage for the new auto-batching behavior.
  • Add psutil dependency and update docs/README to reflect the new default behavior.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tsim/sampler.py Implements auto batch sizing based on available memory and an estimated per-sample footprint; updates sample() defaults/docs.
test/unit/test_sampler.py Adds a parametrized test to ensure auto-batching splits sampling into equal-sized batches.
pyproject.toml Adds psutil as a runtime dependency to query system available RAM on non-GPU platforms.
docs/demos/from_stim_to_tsim.ipynb Updates demo text to describe the new batch_size behavior.
README.md Adds documentation/coverage/arXiv/stars badges.
uv.lock Locks psutil and includes additional lockfile churn, including a registry/source change for griffe-kirin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-31 18:30 UTC

@rafaelha rafaelha merged commit d85cbcd into main Mar 31, 2026
10 checks passed
@rafaelha rafaelha deleted the rafaelha/estimate_batch_size branch March 31, 2026 18:24
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