Skip to content

ecowheataly_repast_model

ecowheataly_repast_model

EcoWHEATaly repast4py simulation model.

Main module orchestrating the agent-based model of Italian wheat production and international wheat markets. Initializes MPI communication, creates all agents (farms, policy maker, international buyers and producers), schedules recurring events, and runs the simulation loop.

Note

mpi4py depends on an MPI implementation. On macOS, install OpenMPI via Homebrew (not Conda).

farm_counter = 0 module-attribute

comm = MPI.COMM_WORLD module-attribute

rank = comm.Get_rank() module-attribute

international_producers_summary = None module-attribute

Model

EcoWHEATaly repast4py simulation model.

Coordinates all agents and scheduled events. On rank 0, manages international buyers and producers. On ranks > 0, manages Italian farms. The policy maker lives on rank 0 and is ghosted to other ranks for price and policy information sharing.

buyersInitializeBuyingStrategy()

Initialize buying strategies for all international buyers.

policyMakerUpdatePolicy()

Reset all policy payments to zero and synchronize across ranks.

performInternationalMarketsSessions()

Run market sessions for all international producers on rank 0.

Each producer finds its equilibrium price and exchanged quantities. Ghost agents are synchronized afterwards to propagate updated prices to farm ranks.

producersHarvestIfgatherMonth()

Trigger harvest for international producers if it is their gather month.

buyersCheckObtainedQuantitiesAndEvolveBuyingStrategy()

Update all buyers' demand strategies after a market session.

switchOnInternationalBuyersAnnealing()

Enable simulated annealing for all international buyers.

resetInternationalBuyersPercentageToMove()

Reset the demand-movement percentage for all buyers to 0.01.

resetInternationalBuyersAnnealingSpeed()

Reset the annealing speed for all buyers to 0.15.

resetInternationalBuyersDemandElasticity()

Reset the demand elasticity for all buyers to 2.0.

switchOffInternationalBuyersAnnealing()

Disable simulated annealing for all international buyers.

updateInternationalBuyersTransportCosts()

Increment transport costs for all international buyers.

updateInternationalBuyersDemandToMovePercentage()

Set the demand-movement percentage for all buyers to 0.01.

updateInternationalProducerStock()

Apply exogenous stock shocks to specific international producers.

interacting_with_ghosts()

Test ghost agent interaction across ranks (debug utility).

performItalianProductionSystemModel()

Run the Italian farm production cycle on ranks > 0.

For each farm: updates the wheat price from the policy maker ghost, decides production inputs, performs LCA impact assessment, and harvests.

updatePolicies()

Let each farm evaluate and potentially change its adopted policy.

recordFarmsData()

Log detailed per-farm data to the tabular CSV logger.

computeItalianProduction()

Aggregate farm-level data and compute total Italian production.

Each farm on ranks > 0 contributes to aggregate variables. An MPI reduction sums production, input usage, and policy acreage across all ranks. Results are stored for use by updateItalianProductionAndStock.

updateItalianProductionAndStock()

Update the Italian international producer with simulated output.

Before the switch-on tick, uses a fixed FAOSTAT-based production value. After that, uses the aggregated durum wheat production computed from the farm sub-model.

computeLCAindicators()

Compute aggregate LCA endpoint indicators using Brightway2.

On rank 0, updates the EcoWHEATaly Brightway2 database with aggregate Italian input quantities (tractor energy, nitrogen, herbicide, insecticide), runs the LCA calculation for ReCiPe 2016 endpoint categories, and writes DALY and species-year scores to the output CSV.

step()

Execute one simulation step for all farms (legacy scheduler hook).

log_international_data()

Write international prices, stocks, and sold quantities to CSV files.

log_agents()

Log per-farm data and aggregate statistics (legacy logger).

start()

Start the simulation by executing the scheduled event loop.

restore_agent(agent_data)

Deserialize an agent from its saved state tuple.

Called by repast4py during MPI synchronization to reconstruct agents (or their ghosts) on remote ranks.

Parameters:

Name Type Description Default
agent_data Tuple

Tuple produced by an agent's save() method.

required

Returns:

Type Description

A newly constructed agent instance of the appropriate type.

run()

Entry point: create the model and start the simulation.