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

Fix adding mutation as parent operator #262

Merged
merged 4 commits into from
Jun 7, 2024
Merged

Conversation

YamLyubov
Copy link
Collaborator

  • Mutation should be saved as a string to avoid problems with custom mutations serialisation
  • Bandits should store arm action mapping accordingly: key should be a string

@pep8speaks
Copy link

pep8speaks commented Jan 29, 2024

Hello @YamLyubov! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-06-05 10:17:55 UTC

examples/molecule_search/experiment.py Outdated Show resolved Hide resolved
@@ -25,7 +25,8 @@ def __init__(self,
super().__init__(actions=actions, enable_logging=enable_logging)
self.actions = list(actions)
self._indices = list(range(len(actions)))
self._arm_by_action = dict(zip(actions, self._indices))
# str because parent operator for mutation is stored as string for custom mutations serialisation
self._arm_by_action = dict(map(lambda x, y: (str(x), y), actions, self._indices))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Преобразование str(fun), если не ошибаюсь, в разных потоках для одной функции даст разные результаты. Если бандит будет работать в разных потоках (что возможно в будущем?), то это место для потенциальной ошибки.
Можно перебдеть и везде использовать __name__ и name. Проще всего сделат маппинг __name__ на name для Enum с типами мутаций.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Хотя, в целом, дело даже не в бандитах. Если индивиды будут готовиться в разных потоках (что будет, надеюсь, в ближайшем будущем), то при использовании str одна и та же функция мутации даст разные строки в разных потоках, что некорректно.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Это тоже поправила

Copy link
Collaborator

@kasyanovse kasyanovse Feb 13, 2024

Choose a reason for hiding this comment

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

Я тут вспомнил один грустный момент. У partial нет __name__, поэтому все упадет если функция мутации будет обёрнута в него.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Можно поступить не очень изящно: создать класс CustomMutation и оборачивать в него все кастомные мутации. Или динамически создавать Enum с мутациями, тогда у каждой мутации будет name.

@YamLyubov YamLyubov merged commit c05f65b into main Jun 7, 2024
6 checks passed
@YamLyubov YamLyubov deleted the mutation-parent-operator branch June 7, 2024 11: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.

3 participants