Quick Start
This page shows how to run the bundled OpenAI example, and then how to write a minimal custom simulation from scratch.
Running the OpenAI Example
Set your API key
export OPENAI_API_KEY="sk-..."
Set the log output path (optional)
export LOG_TXT_PATH="simulation.log"
Run the example
cd examples/openai python main.py
The script loads
config.json, registers the customSubsidyEvent, resets the environment, runs the simulation loop, and writes structured logs to the configured path.
Minimal Custom Simulation
The following snippet shows the core objects and the simulation loop that
Simulator manages internally:
import asyncio
import pathlib
from econsimulacra import Simulator, SimulationSummarizer
from econsimulacra.envs import Environment
from econsimulacra.logs import DictLogger
config_path = pathlib.Path("examples/openai/config.json")
logger = DictLogger()
simulator = Simulator(
config=config_path,
env_class=Environment,
logger=logger,
summarizer_class=SimulationSummarizer,
)
asyncio.run(simulator.simulate(seed=42))
Registering Custom Classes
Any custom Agent,
Event, or
Item subclass must be registered before the
simulation starts so that the environment can instantiate them by name:
from my_project import MyCustomAgent, MyCustomEvent
simulator.register_classes([MyCustomAgent, MyCustomEvent])
asyncio.run(simulator.simulate(seed=0))