-
Notifications
You must be signed in to change notification settings - Fork 2
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 BaseSeedable
class.
#39
Conversation
This is the base class for all objects that need to keep a random state. In particular, the interface provides the following features: - it is able to accept a random seed from the client; - it allows the client reset the random seed; - it provides a getter to the internal random generator; - it allows to sample a random seed (in the range [0, 2^32 - 1]).
This is a breaking change, since who used get_random_seed directly from black_it.utils.base would get an error. This must be documented in the release notes of the next release.
93b6c77
to
1e02c1d
Compare
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #39 +/- ##
==========================================
- Coverage 96.82% 96.79% -0.03%
==========================================
Files 30 31 +1
Lines 1512 1499 -13
==========================================
- Hits 1464 1451 -13
Misses 48 48
|
18a4c82
to
c7f1ad7
Compare
d91e1f8
to
bb2982f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I provide just a couple of comments
black_it/utils/seedable.py
Outdated
Initialize the sampler. | ||
|
||
Args: | ||
random_state: the internal state of the sampler, fixing this numbers the sampler behaves deterministically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this description could be changed to "[...] fixing this numbers the object (either a sampler or a scheduler) behaves deterministically"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It could be a calibrator too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right!
def _set_random_state(self, random_state: Optional[int]) -> None: | ||
"""Set the random state, private use.""" | ||
self.__random_state = random_state | ||
self.__random_generator = default_rng(self.random_state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this is a naive comment, but shouldn't this be self.__random_generator = default_rng(random_state)
? If we use self.random_state
in the argument I am not sure we would get the behaviour we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.random_state
is the property getter, that reads from self.__random_state
, which is set the line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this makes sense, thanks
Thanks to @AldoGl for the comment: #39 (comment)
Thanks to @AldoGl for the comment: #39 (comment)
45eda20
to
1e8f753
Compare
Proposed changes
This is the base class for all objects that need to keep a random state.
In particular, the interface provides the following features:
Fixes
n/a
Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply.develop
branch (left side). Also you should start your branch off ourdevelop
.Further comments
n/a