Examples for HAMLET

Below are several examples on how to use HAMLET. Further examples can be found in the examples folder.

Basic Examples

Example 1: Creating a Simple Scenario

Purpose: Demonstrate how to set up a basic scenario with agents, grids, and markets.

Instructions: 1. Prepare YAML configuration files for agents, grids, and markets in the configs folder. 2. Use the Creator module to generate the scenario.

from hamlet import Creator

sim = Creator(path='../scenarios/basic', name='basic_scenario')
sim.new_scenario_from_configs()
  1. Verify the created files in the scenarios folder.

Example 2: Running a Simulation

Purpose: Show how to execute a basic simulation for the created scenario.

Instructions: 1. Ensure the scenario folder contains the necessary files. 2. Run the Executor module to simulate.

from hamlet import Executor

if __name__ == "__main__":  # required for multiprocessing
    executor = Executor(path_scenario="./scenarios/basic_scenario")
    executor.run()
  1. Check results in the results folder.

Example 3: Analyzing Results (not yet implemented)

Purpose: Illustrate how to visualize and interpret simulation results.

Instructions: 1. Use the Analyzer module to load results.

from hamlet.analyzer import ScenarioAnalyzer

analyzer = ScenarioAnalyzer(path_results="./results/basic_scenario")
analyzer.plot_virtual_feeder_flow()
  1. Generate additional plots or export data as needed.

Intermediate Examples

Example 4: Custom Agent Behaviors

Purpose: Show how to define and integrate custom agent strategies.

Instructions: 1. Modify the agent configuration file to include custom behavior parameters. 2. Update the Agent class in the Executor module to include custom logic. 3. Run the scenario and analyze the impact of the custom behavior.

Example 5: Market Dynamics

Purpose: Simulate and analyze different market clearing mechanisms.

Instructions: 1. Define market configurations with different market designs. 2. Use the Creator module to generate the scenario. 3. Compare results for different market setups using the Analyzer module.

Example 6: Grid Interaction

Purpose: Highlight the interaction between agents and grids.

Instructions: 1. Define a distributed energy system with specific grid constraints. 2. Create the scenario either directly or use the topology setup to assign agents to buses. 3. Simulate the scenario using the Executor module. 4. Analyze grid flows and bottlenecks using the Analyzer module.