Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Access to Current Index for Sampler #2076

Open
samdporter opened this issue Feb 13, 2025 · 2 comments · May be fixed by #2079
Open

Add Access to Current Index for Sampler #2076

samdporter opened this issue Feb 13, 2025 · 2 comments · May be fixed by #2079
Assignees
Labels
enhancement New feature or request

Comments

@samdporter
Copy link
Contributor

samdporter commented Feb 13, 2025

Description

It would be useful if the current index of a Sampler instance could be accessed multiple times within an iteration without changing. For example, when both an SGFunction and a Preconditioner depend on the choice of subset and need to reference the same index.

Right now, I think that this can be done with:

current_index = algorithm.f.data_passes_indices[-1]

as long as the random samplers have a fixed seed. However, this feels like an unnecessary workaround rather than accessing the sampler itself

Possible Solutions

  • Adding a current_index property to Sampler
    This would store the last sampled index and allow multiple accesses within the same iteration.

  • Modifying Sampler.next() to accept algorithm.iteration
    This would ensure the index remains consistent when accessed multiple times within the same iteration but, I guess, would require some changes to the way stochastic functions work.

Either approach would make it easier to ensure consistency when using stochastic samplers.

Cheers

Sam

Environment

24.2.1.dev11+gab65d759.d20241129 gab65d759 3.10.12 (main, Jan 17 2025, 14:35:34) [GCC 11.4.0] linux

edit: a simpler way to get the current index, typo

@samdporter samdporter added the enhancement New feature or request label Feb 13, 2025
@MargaretDuff
Copy link
Member

Thanks, @samdporter - this issue is interesting and something we recently encountered with PD3O (#2021).

@MargaretDuff MargaretDuff self-assigned this Feb 13, 2025
@github-project-automation github-project-automation bot moved this to Todo in CIL work Feb 14, 2025
@MargaretDuff MargaretDuff removed the status in CIL work Feb 14, 2025
@MargaretDuff MargaretDuff moved this to Todo in CIL work Feb 14, 2025
@MargaretDuff
Copy link
Member

Discussed in the stochastic catch-up meeting today. Decided on:

  • Adding a current_index property to Sampler. This would store the last sampled index and allow multiple accesses within the same iteration.
  • The sampler saving the number of times it has been called and then using a property "get_previous_samples" or similar, recalculate all previous samples

@MargaretDuff MargaretDuff moved this from Todo to In Review in CIL work Feb 20, 2025
@MargaretDuff MargaretDuff moved this from In Review to Blocked in CIL work Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Blocked
2 participants