Skip to content

Commit

Permalink
md seed is initialized randomly if not specified (#651)
Browse files Browse the repository at this point in the history
* md seed is initialized randomly if not specified
  • Loading branch information
jnsLs authored Aug 15, 2024
1 parent 92461e1 commit 88312cc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/schnetpack/md/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import torch
import os
import shutil
import random

from datetime import datetime

import hydra
from hydra.core.hydra_config import HydraConfig
from omegaconf import DictConfig, OmegaConf
from omegaconf import DictConfig, OmegaConf, open_dict

import tempfile

Expand Down Expand Up @@ -101,8 +102,17 @@ def simulate(config: DictConfig):
precision = int2precision(config.precision)

# Set seed for random number generators in pytorch, numpy and python.random
seed = seed_everything(config.seed)
log.info("Using random seed {:d}".format(seed))
if config.seed is not None:
if isinstance(config.seed, int):
log.info(f"Seed with <{config.seed}>")
else:
raise ValueError("Seed must be an integer.")
else:
# choose seed randomly
with open_dict(config):
config.seed = random.randint(0, 2**32 - 1)
log.info(f"Seed randomly with <{config.seed}>")
seed_everything(seed=config.seed)

# ===========================================
# Initialize the system
Expand Down

0 comments on commit 88312cc

Please sign in to comment.