Ejemplo n.º 1
0
def test_batch_run_with_params():
    batch_run(
        MockModel,
        {
            "variable_model_params": range(5),
            "variable_agent_params": ["H", "E", "L", "L", "O"],
        },
    )
Ejemplo n.º 2
0
def test_batch_run():
    result = batch_run(MockModel, {})
    assert result == [
        {
            "RunId": 0,
            "iteration": 0,
            "Step": 1000,
            "reported_model_param": 42,
            "AgentID": 0,
            "agent_id": 0,
            "agent_local": 250.0,
        },
        {
            "RunId": 0,
            "iteration": 0,
            "Step": 1000,
            "reported_model_param": 42,
            "AgentID": 1,
            "agent_id": 1,
            "agent_local": 250.0,
        },
        {
            "RunId": 0,
            "iteration": 0,
            "Step": 1000,
            "reported_model_param": 42,
            "AgentID": 2,
            "agent_id": 2,
            "agent_local": 250.0,
        },
    ]
Ejemplo n.º 3
0
def test_batch_run_no_agent_reporters():
    result = batch_run(MockModel, {"enable_agent_reporters": False})
    print(result)
    assert result == [{
        "RunId": 0,
        "iteration": 0,
        "Step": 1000,
        "enable_agent_reporters": False,
        "reported_model_param": 42,
    }]
Ejemplo n.º 4
0
    def run_model(self):
        for i in range(self.run_time):
            self.step()


# parameter lists for each parameter to be tested in batch run
br_params = {
    "init_people": [25, 100],
    "rich_threshold": [5, 10],
    "reserve_percent": 5,
}

if __name__ == "__main__":
    data = batch_run(
        BankReservesModel,
        br_params,
        model_reporters={"Rich": get_num_rich_agents},
        agent_reporters={"Wealth": "wealth"},
    )
    br_df = pd.DataFrame(data)
    br_df.to_csv("BankReservesModel_Data.csv")

    # The commented out code below is the equivalent code as above, but done
    # via the legacy BatchRunner class. This is a good example to look at if
    # you want to migrate your code to use `batch_run()` from `BatchRunner`.
    """
    br = BatchRunner(
        BankReservesModel,
        br_params,
        iterations=2,
        max_steps=1000,
        nr_processes=None,
Ejemplo n.º 5
0
def test_batch_run_single_core():
    batch_run(MockModel, {}, nr_processes=1, iterations=10)