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

Use random.choices when selecting a task instead of random.choice #2651

Open
2 tasks done
bakhtos opened this issue Mar 25, 2024 · 3 comments
Open
2 tasks done

Use random.choices when selecting a task instead of random.choice #2651

bakhtos opened this issue Mar 25, 2024 · 3 comments

Comments

@bakhtos
Copy link

bakhtos commented Mar 25, 2024

Prerequisites

Description

According to current implementation/documentation, if weights are given to tasks, tasks are stored in the list duplicated by the amount given as weight, and then the task is selected from the list by using Python's random.choice.
This, however, has two shortcomings:

  • Inserting big weights can lead to unreasonably big datastructures
  • Only integers can be weights

It should be fairly easy to rewrite the gen_tasks_from_base_classes function and how it's output is handled in TaskSet class to store the weights separately and pass them together with the list of tasks to random.choices in gen_next_task.

This will allow to store arbitrarily large weights without duplicating tasks in integer or float as well as potentially enable the functionality to modify task weights at runtime by modifying the list storing the weights.

I could try to implement this with a PR if this change is desired.

@bakhtos bakhtos changed the title Use random.choiceswhen selecting a task instead of random.choice Use random.choices when selecting a task instead of random.choice Mar 25, 2024
@cyberw
Copy link
Collaborator

cyberw commented Mar 25, 2024

Sounds great! Looking forward to your PR!

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label May 25, 2024
@cyberw cyberw removed the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label May 25, 2024
@cyberw
Copy link
Collaborator

cyberw commented May 25, 2024

@bakhtos Any chance you’ll have time to take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants