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 value for random seed if input seed parameter #101

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concordia/environment/game_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(
self._randomise_initiative = randomise_initiative
self._player_observes_event = player_observes_event
self._players_act_simultaneously = players_act_simultaneously
self._seed = seed or random.getrandbits(63)
self._seed = seed if seed is not None else random.getrandbits(63)
self._rng = random.Random(seed)

if isinstance(action_spec, agent_lib.ActionSpec):
Expand Down
2 changes: 1 addition & 1 deletion concordia/environment/scenes/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
self._key_question = key_question
self._max_steps = max_steps
self._current_steps = 0
self._seed = seed or random.getrandbits(63)
self._seed = seed if seed is not None else random.getrandbits(63)
self._verbose = verbose

def name(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def sample_parameters(
seed: int | None = None,
) -> reality_show.WorldConfig:
"""Sample parameters of the setting and the backstory for each player."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)
rng = random.Random(seed)
shuffled_male_names = list(rng.sample(MALE_NAMES, len(MALE_NAMES)))
shuffled_female_names = list(rng.sample(FEMALE_NAMES, len(FEMALE_NAMES)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def sample_parameters(
seed: int | None = None,
) -> reality_show.WorldConfig:
"""Sample parameters of the setting and the backstory for each player."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)
rng = random.Random(seed)

shuffled_male_names = list(rng.sample(MALE_NAMES, len(MALE_NAMES)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

def sample_parameters(seed: int | None = None):
"""Samples a set of parameters for the world configuration."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)

config = haggling.WorldConfig(
year=YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

def sample_parameters(seed: int | None = None):
"""Samples a set of parameters for the world configuration."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)

config = haggling_multi_item.WorldConfig(
year=YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def sample_parameters(
seed: int | None = None,
):
"""Sample parameters of the setting and the backstory for each player."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)
rng = random.Random(seed)
poor_work_conditions = tuple(
rng.sample(
Expand Down
2 changes: 1 addition & 1 deletion examples/modular/environment/modules/pre_state_villages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ def sample_parameters(
seed: int | None = None,
):
"""Returns a config dict for the simulation."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)
rng = random.Random(seed)
shuffled_village_names = list(
rng.sample(VILLAGE_NAMES, len(VILLAGE_NAMES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def sample_parameters(seed: int | None = None):
"""Samples a set of parameters for the world configuration."""
pubs = random.sample(list(PUB_PREFERENCES.keys()), NUM_PUBS)
pub_preferences = {k: PUB_PREFERENCES[k] for k in pubs}
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)

config = pub_coordination.WorldConfig(
year=YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def sample_parameters(seed: int | None = None):
"""Samples a set of parameters for the world configuration."""
pubs = random.sample(list(PUB_PREFERENCES.keys()), NUM_PUBS)
pub_preferences = {k: PUB_PREFERENCES[k] for k in pubs}
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)

config = pub_coordination.WorldConfig(
year=YEAR,
Expand Down
2 changes: 1 addition & 1 deletion examples/modular/environment/modules/vegbrooke_haggling.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

def sample_parameters(seed: int | None = None):
"""Samples a set of parameters for the world configuration."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)

config = haggling.WorldConfig(
year=YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

def sample_parameters(seed: int | None = None):
"""Samples a set of parameters for the world configuration."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)

config = haggling_multi_item.WorldConfig(
year=YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def sample_parameters(
seed: int | None = None,
):
"""Sample parameters of the setting and the backstory for each player."""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)
rng = random.Random(seed)
nearby_town = rng.choice(TOWN_NAMES)
poor_work_conditions = tuple(
Expand Down
2 changes: 1 addition & 1 deletion examples/modular/environment/utils/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_time_and_place_module(
like the names of individual characters, which must be resampled for each
run of the simulation.
"""
seed = seed or random.getrandbits(63)
seed = seed if seed is not None else random.getrandbits(63)
rng = random.Random(seed)
if time_and_place_module is None:
time_and_place_module = rng.choice(default_time_and_place_modules)
Expand Down