Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7c123aa
initial commit
quaquel Nov 18, 2025
e35ec91
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
bf7a3c4
additional warnings
quaquel Nov 18, 2025
c5e6224
shift agentset to rng
quaquel Nov 18, 2025
1305c82
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
f8c13a0
fixes for unit tests
quaquel Nov 18, 2025
6806049
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
8702cdf
Update model.py
quaquel Nov 18, 2025
fe75c58
Update util.py
quaquel Nov 18, 2025
f528b9d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
f788e0f
test fixes
quaquel Nov 18, 2025
4a4ae9a
update benchmark examples to use rng instead of seed
quaquel Nov 18, 2025
ec6d8ea
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
6402f0a
fix other examples and tests
quaquel Nov 18, 2025
930d405
Update model.py
quaquel Nov 18, 2025
831e5c5
Update test_examples_viz.py
quaquel Nov 18, 2025
6aefc7a
replace random/seed with rng in all spaces and some other places
quaquel Nov 18, 2025
08710e0
Update continuous_space.py
quaquel Nov 18, 2025
9915d9d
replace rng.choice with list[rng.integers(0, len(list)]
quaquel Nov 18, 2025
f9133ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2025
27b48ac
ongoing work
quaquel Nov 19, 2025
88f3999
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2025
5bdfa7e
some further tweaks to the example models
quaquel Nov 19, 2025
9c293ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2025
576fb39
ongoing
quaquel Nov 25, 2025
206eeef
Merge remote-tracking branch 'upstream/main' into deprecate_seed
quaquel Nov 25, 2025
a2ae615
Merge remote-tracking branch 'upstream/main' into deprecate_seed
quaquel Dec 9, 2025
4273992
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2025
ceda4f0
test with a rand method on model
quaquel Dec 9, 2025
ba04f14
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2025
a1c42d1
Update simulator.py
quaquel Dec 9, 2025
73a3a93
Update model.py
quaquel Dec 9, 2025
ce81412
Update model.py
quaquel Dec 10, 2025
5d4d9d2
Merge remote-tracking branch 'upstream/main' into deprecate_seed
quaquel Dec 11, 2025
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
Prev Previous commit
Next Next commit
ongoing work
  • Loading branch information
quaquel committed Nov 19, 2025
commit 27b48ac98113de6872132dd90f16896b5387408a
2 changes: 1 addition & 1 deletion docs/tutorials/9_batch_run.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
"version": "3.12.2"
},
"widgets": {
"state": {},
Expand Down
1 change: 1 addition & 0 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def __getitem__(self, i):
@property
def random(self) -> Random:
"""Return a seeded stdlib rng."""
warnings.warn("the use of random is deprecated, please use rng instead", FutureWarning, stacklevel=2)
return self.model.random

@property
Expand Down
3 changes: 1 addition & 2 deletions mesa/discrete_space/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class Cell:
"connections",
"coordinate",
"properties",
"random",
"rng",
"rng"
]

@deprecate_kwarg("random")
Expand Down
3 changes: 2 additions & 1 deletion mesa/discrete_space/cell_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CellCollection[T: Cell]:
Attributes:
cells (List[Cell]): The list of cells this collection represents
agents (List[CellAgent]) : List of agents occupying the cells in this collection
random (Random) : The random number generator
random (Random) : The random number generator, deprecated
rng (Random) : The random number generator

Notes:
A `UserWarning` is issued if `random=None`. You can resolve this warning by explicitly
Expand Down
2 changes: 1 addition & 1 deletion mesa/discrete_space/voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __init__(
self._validate_parameters()

self._cells = {
i: cell_klass(self.centroids_coordinates[i], capacity, rng=self.random)
i: cell_klass(self.centroids_coordinates[i], capacity, rng=self.rng)
for i in range(len(self.centroids_coordinates))
}

Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/epstein_civil_violence/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(
self.max_iters = max_iters

self.grid = mesa.discrete_space.OrthogonalVonNeumannGrid(
(width, height), capacity=1, torus=True, random=self.random
(width, height), capacity=1, torus=True, rng=self.rng
)

model_reporters = {
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/pd_grid/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
"""
super().__init__(rng=rng)
self.activation_order = activation_order
self.grid = OrthogonalMooreGrid((width, height), torus=True, random=self.random)
self.grid = OrthogonalMooreGrid((width, height), torus=True, rng=self.rng)

if payoffs is not None:
self.payoff = payoffs
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/advanced/sugarscape_g1mt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(

# initiate mesa grid class
self.grid = OrthogonalVonNeumannGrid(
(self.width, self.height), torus=False, random=self.random
(self.width, self.height), torus=False, rng=self.rng
)
# initiate datacollector
self.datacollector = mesa.DataCollector(
Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/basic/boltzmann_wealth_model/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def give_money(self):
cellmates = [a for a in self.cell.agents if a is not self]

if cellmates: # Only give money if there are other agents present
other = cellmates[self.rng.integers(0, len(cellmates))]
other = cellmates[0] if len(cellmates)==1 else cellmates[self.rng.integers(0, len(cellmates))]
other.wealth += 1
self.wealth -= 1

Expand Down
6 changes: 4 additions & 2 deletions mesa/examples/basic/conways_game_of_life/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ def __init__(self, width=50, height=50, initial_fraction_alive=0.2, rng=None):
"""Create a new playing area of (width, height) cells."""
super().__init__(rng=rng)
# Use a simple grid, where edges wrap around.
self.grid = OrthogonalMooreGrid((width, height), capacity=1, torus=True)
self.grid = OrthogonalMooreGrid((width, height), capacity=1, torus=True, rng=rng)

# Place a cell at each location, with some initialized to
# ALIVE and some to DEAD.
random_floats = self.rng.uniform(0, 1, size=(width, height))

for cell in self.grid.all_cells:
Cell(
self,
cell,
init_state=Cell.ALIVE
if self.random.random() < initial_fraction_alive
if random_floats[cell.coordinate] < initial_fraction_alive
else Cell.DEAD,
)

Expand Down
2 changes: 1 addition & 1 deletion mesa/examples/basic/virus_on_network/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
def try_to_infect_neighbors(self):
for agent in self.cell.neighborhood.agents:
if (agent.state is State.SUSCEPTIBLE) and (
self.random.random() < self.virus_spread_chance
self.rng.random() < self.virus_spread_chance
):
agent.state = State.INFECTED

Expand Down
6 changes: 3 additions & 3 deletions mesa/examples/basic/virus_on_network/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
super().__init__(rng=rng)
prob = avg_node_degree / num_nodes
graph = nx.erdos_renyi_graph(n=num_nodes, p=prob)
self.grid = Network(graph, capacity=1, random=self.random)
self.grid = Network(graph, capacity=1, rng=self.rng)

self.initial_outbreak_size = (
initial_outbreak_size if initial_outbreak_size <= num_nodes else num_nodes
Expand Down Expand Up @@ -69,8 +69,8 @@ def __init__(

# Infect some nodes
infected_nodes = CellCollection(
self.random.sample(list(self.grid.all_cells), self.initial_outbreak_size),
random=self.random,
self.rng.choice(list(self.grid.all_cells), size=self.initial_outbreak_size),
rng=self.rng,
)
for a in infected_nodes.agents:
a.state = State.INFECTED
Expand Down
4 changes: 2 additions & 2 deletions mesa/experimental/meta_agents/meta_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def evaluate_combination(
Optional[Tuple[AgentSet, float]]: The evaluated group and its value,
or None.
"""
group_set = AgentSet(candidate_group, random=model.random)
group_set = AgentSet(candidate_group, rng=model.rng)
if evaluation_func:
value = evaluation_func(group_set)
return group_set, value
Expand Down Expand Up @@ -287,7 +287,7 @@ def __init__(
name (str, optional): The name of the MetaAgent. Defaults to "MetaAgent".
"""
super().__init__(model)
self._constituting_set = AgentSet(agents or [], random=model.random)
self._constituting_set = AgentSet(agents or [], rng=model.rng)
self.name = name

# Add ref to meta_agent in constituting_agents
Expand Down
Loading