Skip to content

Commit

Permalink
Merge pull request #121 from mariuzka/mk/fix_dummy_model_error
Browse files Browse the repository at this point in the history
Mk/fix dummy model error
  • Loading branch information
mariuzka authored Oct 30, 2024
2 parents 90455fd + fb649a5 commit ee77441
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pop2net/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self.model = model
self.seed = seed
self.rng = random.Random(seed)
self._dummy_model = p2n.Model()
self._dummy_model = p2n.Model(parameters=self.model.p)
self._temp_agent_attrs = ["_P2NTEMP_split_values", "_P2NTEMP_melt_location_weight"]

def _create_dummy_location(self, location_cls) -> p2n.Location:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_creator/test_parameter_transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import networkx as nx

import pop2net as p2n


def test_p_transfer():
"""Tests whether a MagicLocation can access the parameters p of the model
when the Creator is working."""

class TestLocation(p2n.MagicLocation):
def __init__(self, model: p2n.Model) -> None:
super().__init__(model)
self.nxgraph = nx.cycle_graph(n=self.p["n_agents"])

class TestModel(p2n.Model):
def setup(self):
self.creator = p2n.Creator(model=self)
self.creator.create_agents(n=self.p["n_agents"])
self.creator.create_locations(location_classes=[TestLocation])

params = {"n_agents": 100}

model = TestModel(parameters=params)
model.run(steps=3)

assert len(model.agents) == 100

0 comments on commit ee77441

Please sign in to comment.