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

Duplicated code block setting random seed #101

Closed
dachengx opened this issue Jan 16, 2024 · 3 comments
Closed

Duplicated code block setting random seed #101

dachengx opened this issue Jan 16, 2024 · 3 comments
Assignees

Comments

@dachengx
Copy link
Contributor

The code similar to

        if self.deterministic_seed:
            hash_string = strax.deterministic_hash((self.run_id, self.lineage))
            seed = int(hash_string.encode().hex(), 16)
            self.rng = np.random.default_rng(seed = seed)
            log.debug(f"Generating random numbers from seed {seed}")
        else: 
            self.rng = np.random.default_rng()
            log.debug(f"Generating random numbers with seed pulled from OS")

has appeared multiple times like here:

if self.deterministic_seed:

It is better to put them into a mother class and plugins can inherit this function from the mother class.

@dachengx dachengx changed the title Duplicated code block Duplicated code block setting random seed Jan 16, 2024
@HenningSE
Copy link
Collaborator

Hey @dachengx, I like the idea and would make the code cleaner! I was wondering if we could potentially get some problems with e.g the S2PhotonPropagation plugin that is a child plugin of S2PhotonPropagationBase which in turn inherits from strax.DownChunkingPlugin.

We would need to define maybe fusePlugin and fuseDownChunkingPlugin. Then let all fuse plugins inherit from there and not from strax plugins. The plugins setting the random seed for nestpy & scipy would need a little different setup function.

@dachengx
Copy link
Contributor Author

Hey @HenningSE . I think that nested inheritance is OK.

@dachengx
Copy link
Contributor Author

dachengx commented Feb 1, 2024

MISSION ACCOMPLISHED #112

@dachengx dachengx closed this as completed Feb 1, 2024
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

No branches or pull requests

2 participants