Skip to content
SkillVault logo SkillVault
Free ChatGPT GPTs Claude Code Cursor

simpy

Process-based discrete-event simulation framework in Python. Use this skill when building simulations of systems with processes, queues, resources, and time-based events such as manufacturing systems, service operations, network traffic, logistics, or any system where entities interact with shared resources over time.

0 downloads 0 views Updated Oct 31, 2026 v1.0.0
simpy skill cover

Overview

Process-based discrete-event simulation framework in Python. Use this skill when building simulations of systems with processes, queues, resources, and time-based events such as manufacturing systems, service operations, network traffic, logistics, or any system where entities interact with shared resources over time.

Source: https://github.com/DenDen047/claude-scientific-skills · MIT LICENSE · © 2025 K-Dense Inc.

System prompt

The instruction block that defines the agent's role, rules and output format.

system-prompt.txt
# SimPy - Discrete-Event Simulation

## Overview

SimPy is a process-based discrete-event simulation framework based on standard Python. Use SimPy to model systems where entities (customers, vehicles, packets, etc.) interact with each other and compete for shared resources (servers, machines, bandwidth, etc.) over time.

**Core capabilities:**
- Process modeling using Python generator functions
- Shared resource management (servers, containers, stores)
- Event-driven scheduling and synchronization
- Real-time simulations synchronized with wall-clock time
- Comprehensive monitoring and data collection

## When to Use This Skill

Use the SimPy skill when:

1. **Modeling discrete-event systems** - Systems where events occur at irregular intervals
2. **Resource contention** - Entities compete for limited resources (servers, machines, staff)
3. **Queue analysis** - Studying waiting lines, service times, and throughput
4. **Process optimization** - Analyzing manufacturing, logistics, or service processes
5. **Network simulation** - Packet routing, bandwidth allocation, latency analysis
6. **Capacity planning** - Determining optimal resource levels for desired performance
7. **System validation** - Testing system behavior before implementation

**Not suitable for:**
- Continuous simulations with fixed time steps (consider SciPy ODE solvers)
- Independent processes without resource sharing
- Pure mathematical optimization (consider SciPy optimize)

## Quick Start

### Basic Simulation Structure

```python
import simpy

def process(env, name):
    """A simple process that waits and prints."""
    print(f'{name} starting at {env.now}')
    yield env.timeout(5)
    print(f'{name} finishing at {env.now}')

# Create environment
env = simpy.Environment()

# Start processes
env.process(process(env, 'Process 1'))
env.process(process(env, 'Process 2'))

# Run simulation
env.run(until=10)
```

### Resource Usage Pattern

```python
import simpy

def customer(env, name, resource):
    """Customer requests resource, uses it, then releases."""
    with resource.request() as req:
        yield req  # Wait for resource
        print(f'{name} got resource at {env.now}')
        yield env.timeout(3)  # Use resource
        print(f'{name} released resource at {env.now}')

env = simpy.Environment()
server = simpy.Resource(env, capacity=1)

env.process(customer(env, 'Customer 1', server))
env.process(customer(env, 'Customer 2', server))
env.run()
```

## Core Concepts

### 1. Environment

The simulation environment manages time and schedules events.

```python
import simpy

# Standard environment (runs as fast as possible)
env = simpy.Environment(initial_time=0)

# Real-time environment (synchronized with wall-clock)
import simpy.rt
env_rt = simpy.rt.RealtimeEnvironment(factor=1.0)

# Run simulation
env.run(until=100)  # Run until time 100
env.run()  # Run until no events remain
```

### 2. Processes

Processes are defined using Python generator functions (functions with `yield` statements).

```python
def my_process(env, param1, param2):
    """Process that yields events to pause execution."""
    print(f'Starting at {env.now}')

    # Wait for time to pass
    yield env.timeout(5)

    print(f'Resumed at {env.now}')

    # Wait for another event
    yield env.timeout(3)

    print(f'Done at {env.now}')
    return 'result'

# Start the process
env.process(my_process(env, 'value1', 'value2'))
```

### 3. Events

Events are the fundamental mechanism for process synchronization. Processes yield events and resume when those events are triggered.

**Common event types:**
- `env.timeout(delay)` - Wait for time to pass
- `resource.request()` - Request a resource
- `env.event()` - Create a custom event
- `env.process(func())` - Process as an event
- `event1 & event2` - Wait for all events (AllOf)
- `event1 | event2` - Wait for any event (AnyOf)

## Resources

SimPy provides several resource types for different scenarios. For comprehensive details, see `references/resources.md`.

### Resource Types Summary

| Resource Type | Use Case |
|---------------|----------|
| Resource | Limited capacity (servers, machines) |
| PriorityResource | Priority-based queuing |
| PreemptiveResource | High-priority can interrupt low-priority |
| Container | Bulk materials (fuel, water) |
| Store | Python object storage (FIFO) |
| FilterStore | Selective item retrieval |
| PriorityStore | Priority-ordered items |

### Quick Reference

```python
import simpy

env = simpy.Environment()

# Basic resource (e.g., servers)
resource = simpy.Resource(env, capacity=2)

# Priority resource
priority_resource = simpy.PriorityResource(env, capacity=1)

# Container (e.g., fuel tank)
fuel_tank = simpy.Container(env, capacity=100, init=50)

# Store (e.g., warehouse)
warehouse = simpy.Store(env, capacity=10)
```

## Common Simulation Patterns

### Pattern 1: Customer-Server Queue

```python
import simpy
import random

def customer(env, name, server):
    arrival = env.now
    with server.request() as req:
        yield req
        wait = env.now - arrival
        print(f'{name} waited {wait:.2f}, served at {env.now}')
        yield env.timeout(random.uniform(2, 4))

def customer_generator(env, server):
    i = 0
    while True:
        yield env.timeout(random.uniform(1, 3))
        i += 1
        env.process(customer(env, f'Customer {i}', server))

env = simpy.Environment()
server = simpy.Resource(env, capacity=2)
env.process(customer_generator(env, server))
env.run(until=20)
```

### Pattern 2: Producer-Consumer

```python
import simpy

def producer(env, store):
    item_id = 0
    while True:
        yield env.timeout(2)
        item = f'Item {item_id}'
        yield store.put(item)
        print(f'Produced {item} at {env.now}')
        item_id += 1

def consumer(env, store):
    while True:
        item = yield store.get()
        print(f'Consumed {item} at {env.now}')
        yield env.timeout(3)

env = simpy.Environment()
store = simpy.Store(env, capacity=10)
env.process(producer(env, store))
env.process(consumer(env, store))
env.run(until=20)
```

### Pattern 3: Parallel Task Execution

```python
import simpy

def task(env, name, duration):
    print(f'{name} starting at {env.now}')
    yield env.timeout(duration)
    print(f'{name} done at {env.now}')
    return f'{name} result'

def coordinator(env):
    # Start tasks in parallel
    task1 = env.process(task(env, 'Task 1', 5))
    task2 = env.process(task(env, 'Task 2', 3))
    task3 = env.process(task(env, 'Task 3', 4))

    # Wait for all to complete
    results = yield task1 & task2 & task3
    print(f'All done at {env.now}')

env = simpy.Environment()
env.process(coordinator(env))
env.run()
```

## Workflow Guide

### Step 1: Define the System

Identify:
- **Entities**: What moves through the system? (customers, parts, packets)
- **Resources**: What are the constraints? (servers, machines, bandwidth)
- **Processes**: What are the activities? (arrival, service, departure)
- **Metrics**: What to measure? (wait times, utilization, throughput)

### Step 2: Implement Process Functions

Create generator functions for each process type:

```python
def entity_process(env, name, resources, parameters):
    # Arrival logic
    arrival_time = env.now

    # Request resources
    with resource.request() as req:
        yield req

        # Service logic
        service_time = calculate_service_time(parameters)
        yield env.timeout(service_time)

    # Departure logic
    collect_statistics(env.now - arrival_time)
```

### Step 3: Set Up Monitoring

Use monitoring utilities to collect data. See `references/monitoring.md` for comprehensive techniques.

```python
from scripts.resource_monitor import ResourceMonitor

# Create and monitor resource
resource = simpy.Resource(env, capacity=2)
monitor = ResourceMonitor(env, resource, "Server")

# After simulation
monitor.report()
```

### Step 4: Run and Analyze

```python
# Run simulation
env.run(until=simulation_time)

# Generate reports
monitor.report()
stats.report()

# Export data for further analysis
monitor.export_csv('results.csv')
```

## Advanced Features

### Process Interaction

Processes can interact through events, process yields, and interrupts. See `references/process-interaction.md` for detailed patterns.

**Key mechanisms:**
- **Event signaling**: Shared events for coordination
- **Process yields**: Wait for other processes to complete
- **Interrupts**: Forcefully resume processes for preemption

### Real-Time Simulations

Synchronize simulation with wall-clock time for hardware-in-the-loop or interactive applications. See `references/real-time.md`.

```python
import simpy.rt

env = simpy.rt.RealtimeEnvironment(factor=1.0)  # 1:1 time mapping
# factor=0.5 means 1 sim unit = 0.5 seconds (2x faster)
```

### Comprehensive Monitoring

Monitor processes, resources, and events. See `references/monitoring.md` for techniques including:
- State variable tracking
- Resource monkey-patching
- Event tracing
- Statistical collection

## Scripts and Templates

### basic_simulation_template.py

Complete template for building queue simulations with:
- Configurable parameters
- Statistics collection
- Customer generation
- Resource usage
- Report generation

**Usage:**
```python
from scripts.basic_simulation_template import SimulationConfig, run_simulation

config = SimulationConfig()
config.num_resources = 2
config.sim_time = 100
stats = run_simulation(config)
stats.report()
```

### resource_monitor.py

Reusable monitoring utilities:
- `ResourceMonitor` - Track single resource
- `MultiResourceMonitor` - Monitor multiple resources
- `ContainerMonitor` - Track container levels
- Automatic statistics calculation
- CSV export functionality

**Usage:**
```python
from scripts.resource_monitor import ResourceMonitor

monitor = ResourceMonitor(env, resource, "My Resource")
# ... run simulation ...
monitor.report()
monitor.export_csv('data.csv')
```

## Reference Documentation

Detailed guides for specific topics:

- **`references/resources.md`** - All resource types with examples
- **`references/events.md`** - Event system and patterns
- **`references/process-interaction.md`** - Process synchronization
- **`references/monitoring.md`** - Data collection techniques
- **`references/real-time.md`** - Real-time simulation setup

## Best Practices

1. **Generator functions**: Always use `yield` in process functions
2. **Resource context managers**: Use `with resource.request() as req:` for automatic cleanup
3. **Reproducibility**: Set `random.seed()` for consistent results
4. **Monitoring**: Collect data throughout simulation, not just at the end
5. **Validation**: Compare simple cases with analytical solutions
6. **Documentation**: Comment process logic and parameter choices
7. **Modular design**: Separate process logic, statistics, and configuration

## Common Pitfalls

1. **Forgetting yield**: Processes must yield events to pause
2. **Event reuse**: Events can only be triggered once
3. **Resource leaks**: Use context managers or ensure release
4. **Blocking operations**: Avoid Python blocking calls in processes
5. **Time units**: Stay consistent with time unit interpretation
6. **Deadlocks**: Ensure at least one process can make progress

## Example Use Cases

- **Manufacturing**: Machine scheduling, production lines, inventory management
- **Healthcare**: Emergency room simulation, patient flow, staff allocation
- **Telecommunications**: Network traffic, packet routing, bandwidth allocation
- **Transportation**: Traffic flow, logistics, vehicle routing
- **Service operations**: Call centers, retail checkout, appointment scheduling
- **Computer systems**: CPU scheduling, memory management, I/O operations

User prompt template

Fill in the variables and send it to run the skill: {{variables}}

user-template.txt

Variables

Name Required Description Example

Full skill configuration

The standard .aiskill file in JSON and YAML.

simpy.aiskill (JSON)
{
  "format": "aiskill/v1",
  "skill": {
    "name": "simpy",
    "slug": "simpy",
    "version": "1.0.0",
    "description": "Process-based discrete-event simulation framework in Python. Use this skill when building simulations of systems with processes, queues, resources, and time-based events such as manufacturing systems, service operations, network traffic, logistics, or any system where entities interact with shared resources over time.",
    "category": "Research",
    "tags": [
      "research-science",
      "python"
    ],
    "platforms": [
      "chatgpt",
      "claude-code",
      "cursor"
    ],
    "tested_environment": "Agent Skills convention (SKILL.md) — works with Claude Code, Cursor, ChatGPT/Codex and compatible agents",
    "license": "MIT LICENSE"
  },
  "prompts": {
    "system": "# SimPy - Discrete-Event Simulation\r\n\r\n## Overview\r\n\r\nSimPy is a process-based discrete-event simulation framework based on standard Python. Use SimPy to model systems where entities (customers, vehicles, packets, etc.) interact with each other and compete for shared resources (servers, machines, bandwidth, etc.) over time.\r\n\r\n**Core capabilities:**\r\n- Process modeling using Python generator functions\r\n- Shared resource management (servers, containers, stores)\r\n- Event-driven scheduling and synchronization\r\n- Real-time simulations synchronized with wall-clock time\r\n- Comprehensive monitoring and data collection\r\n\r\n## When to Use This Skill\r\n\r\nUse the SimPy skill when:\r\n\r\n1. **Modeling discrete-event systems** - Systems where events occur at irregular intervals\r\n2. **Resource contention** - Entities compete for limited resources (servers, machines, staff)\r\n3. **Queue analysis** - Studying waiting lines, service times, and throughput\r\n4. **Process optimization** - Analyzing manufacturing, logistics, or service processes\r\n5. **Network simulation** - Packet routing, bandwidth allocation, latency analysis\r\n6. **Capacity planning** - Determining optimal resource levels for desired performance\r\n7. **System validation** - Testing system behavior before implementation\r\n\r\n**Not suitable for:**\r\n- Continuous simulations with fixed time steps (consider SciPy ODE solvers)\r\n- Independent processes without resource sharing\r\n- Pure mathematical optimization (consider SciPy optimize)\r\n\r\n## Quick Start\r\n\r\n### Basic Simulation Structure\r\n\r\n```python\r\nimport simpy\r\n\r\ndef process(env, name):\r\n    \"\"\"A simple process that waits and prints.\"\"\"\r\n    print(f'{name} starting at {env.now}')\r\n    yield env.timeout(5)\r\n    print(f'{name} finishing at {env.now}')\r\n\r\n# Create environment\r\nenv = simpy.Environment()\r\n\r\n# Start processes\r\nenv.process(process(env, 'Process 1'))\r\nenv.process(process(env, 'Process 2'))\r\n\r\n# Run simulation\r\nenv.run(until=10)\r\n```\r\n\r\n### Resource Usage Pattern\r\n\r\n```python\r\nimport simpy\r\n\r\ndef customer(env, name, resource):\r\n    \"\"\"Customer requests resource, uses it, then releases.\"\"\"\r\n    with resource.request() as req:\r\n        yield req  # Wait for resource\r\n        print(f'{name} got resource at {env.now}')\r\n        yield env.timeout(3)  # Use resource\r\n        print(f'{name} released resource at {env.now}')\r\n\r\nenv = simpy.Environment()\r\nserver = simpy.Resource(env, capacity=1)\r\n\r\nenv.process(customer(env, 'Customer 1', server))\r\nenv.process(customer(env, 'Customer 2', server))\r\nenv.run()\r\n```\r\n\r\n## Core Concepts\r\n\r\n### 1. Environment\r\n\r\nThe simulation environment manages time and schedules events.\r\n\r\n```python\r\nimport simpy\r\n\r\n# Standard environment (runs as fast as possible)\r\nenv = simpy.Environment(initial_time=0)\r\n\r\n# Real-time environment (synchronized with wall-clock)\r\nimport simpy.rt\r\nenv_rt = simpy.rt.RealtimeEnvironment(factor=1.0)\r\n\r\n# Run simulation\r\nenv.run(until=100)  # Run until time 100\r\nenv.run()  # Run until no events remain\r\n```\r\n\r\n### 2. Processes\r\n\r\nProcesses are defined using Python generator functions (functions with `yield` statements).\r\n\r\n```python\r\ndef my_process(env, param1, param2):\r\n    \"\"\"Process that yields events to pause execution.\"\"\"\r\n    print(f'Starting at {env.now}')\r\n\r\n    # Wait for time to pass\r\n    yield env.timeout(5)\r\n\r\n    print(f'Resumed at {env.now}')\r\n\r\n    # Wait for another event\r\n    yield env.timeout(3)\r\n\r\n    print(f'Done at {env.now}')\r\n    return 'result'\r\n\r\n# Start the process\r\nenv.process(my_process(env, 'value1', 'value2'))\r\n```\r\n\r\n### 3. Events\r\n\r\nEvents are the fundamental mechanism for process synchronization. Processes yield events and resume when those events are triggered.\r\n\r\n**Common event types:**\r\n- `env.timeout(delay)` - Wait for time to pass\r\n- `resource.request()` - Request a resource\r\n- `env.event()` - Create a custom event\r\n- `env.process(func())` - Process as an event\r\n- `event1 & event2` - Wait for all events (AllOf)\r\n- `event1 | event2` - Wait for any event (AnyOf)\r\n\r\n## Resources\r\n\r\nSimPy provides several resource types for different scenarios. For comprehensive details, see `references/resources.md`.\r\n\r\n### Resource Types Summary\r\n\r\n| Resource Type | Use Case |\r\n|---------------|----------|\r\n| Resource | Limited capacity (servers, machines) |\r\n| PriorityResource | Priority-based queuing |\r\n| PreemptiveResource | High-priority can interrupt low-priority |\r\n| Container | Bulk materials (fuel, water) |\r\n| Store | Python object storage (FIFO) |\r\n| FilterStore | Selective item retrieval |\r\n| PriorityStore | Priority-ordered items |\r\n\r\n### Quick Reference\r\n\r\n```python\r\nimport simpy\r\n\r\nenv = simpy.Environment()\r\n\r\n# Basic resource (e.g., servers)\r\nresource = simpy.Resource(env, capacity=2)\r\n\r\n# Priority resource\r\npriority_resource = simpy.PriorityResource(env, capacity=1)\r\n\r\n# Container (e.g., fuel tank)\r\nfuel_tank = simpy.Container(env, capacity=100, init=50)\r\n\r\n# Store (e.g., warehouse)\r\nwarehouse = simpy.Store(env, capacity=10)\r\n```\r\n\r\n## Common Simulation Patterns\r\n\r\n### Pattern 1: Customer-Server Queue\r\n\r\n```python\r\nimport simpy\r\nimport random\r\n\r\ndef customer(env, name, server):\r\n    arrival = env.now\r\n    with server.request() as req:\r\n        yield req\r\n        wait = env.now - arrival\r\n        print(f'{name} waited {wait:.2f}, served at {env.now}')\r\n        yield env.timeout(random.uniform(2, 4))\r\n\r\ndef customer_generator(env, server):\r\n    i = 0\r\n    while True:\r\n        yield env.timeout(random.uniform(1, 3))\r\n        i += 1\r\n        env.process(customer(env, f'Customer {i}', server))\r\n\r\nenv = simpy.Environment()\r\nserver = simpy.Resource(env, capacity=2)\r\nenv.process(customer_generator(env, server))\r\nenv.run(until=20)\r\n```\r\n\r\n### Pattern 2: Producer-Consumer\r\n\r\n```python\r\nimport simpy\r\n\r\ndef producer(env, store):\r\n    item_id = 0\r\n    while True:\r\n        yield env.timeout(2)\r\n        item = f'Item {item_id}'\r\n        yield store.put(item)\r\n        print(f'Produced {item} at {env.now}')\r\n        item_id += 1\r\n\r\ndef consumer(env, store):\r\n    while True:\r\n        item = yield store.get()\r\n        print(f'Consumed {item} at {env.now}')\r\n        yield env.timeout(3)\r\n\r\nenv = simpy.Environment()\r\nstore = simpy.Store(env, capacity=10)\r\nenv.process(producer(env, store))\r\nenv.process(consumer(env, store))\r\nenv.run(until=20)\r\n```\r\n\r\n### Pattern 3: Parallel Task Execution\r\n\r\n```python\r\nimport simpy\r\n\r\ndef task(env, name, duration):\r\n    print(f'{name} starting at {env.now}')\r\n    yield env.timeout(duration)\r\n    print(f'{name} done at {env.now}')\r\n    return f'{name} result'\r\n\r\ndef coordinator(env):\r\n    # Start tasks in parallel\r\n    task1 = env.process(task(env, 'Task 1', 5))\r\n    task2 = env.process(task(env, 'Task 2', 3))\r\n    task3 = env.process(task(env, 'Task 3', 4))\r\n\r\n    # Wait for all to complete\r\n    results = yield task1 & task2 & task3\r\n    print(f'All done at {env.now}')\r\n\r\nenv = simpy.Environment()\r\nenv.process(coordinator(env))\r\nenv.run()\r\n```\r\n\r\n## Workflow Guide\r\n\r\n### Step 1: Define the System\r\n\r\nIdentify:\r\n- **Entities**: What moves through the system? (customers, parts, packets)\r\n- **Resources**: What are the constraints? (servers, machines, bandwidth)\r\n- **Processes**: What are the activities? (arrival, service, departure)\r\n- **Metrics**: What to measure? (wait times, utilization, throughput)\r\n\r\n### Step 2: Implement Process Functions\r\n\r\nCreate generator functions for each process type:\r\n\r\n```python\r\ndef entity_process(env, name, resources, parameters):\r\n    # Arrival logic\r\n    arrival_time = env.now\r\n\r\n    # Request resources\r\n    with resource.request() as req:\r\n        yield req\r\n\r\n        # Service logic\r\n        service_time = calculate_service_time(parameters)\r\n        yield env.timeout(service_time)\r\n\r\n    # Departure logic\r\n    collect_statistics(env.now - arrival_time)\r\n```\r\n\r\n### Step 3: Set Up Monitoring\r\n\r\nUse monitoring utilities to collect data. See `references/monitoring.md` for comprehensive techniques.\r\n\r\n```python\r\nfrom scripts.resource_monitor import ResourceMonitor\r\n\r\n# Create and monitor resource\r\nresource = simpy.Resource(env, capacity=2)\r\nmonitor = ResourceMonitor(env, resource, \"Server\")\r\n\r\n# After simulation\r\nmonitor.report()\r\n```\r\n\r\n### Step 4: Run and Analyze\r\n\r\n```python\r\n# Run simulation\r\nenv.run(until=simulation_time)\r\n\r\n# Generate reports\r\nmonitor.report()\r\nstats.report()\r\n\r\n# Export data for further analysis\r\nmonitor.export_csv('results.csv')\r\n```\r\n\r\n## Advanced Features\r\n\r\n### Process Interaction\r\n\r\nProcesses can interact through events, process yields, and interrupts. See `references/process-interaction.md` for detailed patterns.\r\n\r\n**Key mechanisms:**\r\n- **Event signaling**: Shared events for coordination\r\n- **Process yields**: Wait for other processes to complete\r\n- **Interrupts**: Forcefully resume processes for preemption\r\n\r\n### Real-Time Simulations\r\n\r\nSynchronize simulation with wall-clock time for hardware-in-the-loop or interactive applications. See `references/real-time.md`.\r\n\r\n```python\r\nimport simpy.rt\r\n\r\nenv = simpy.rt.RealtimeEnvironment(factor=1.0)  # 1:1 time mapping\r\n# factor=0.5 means 1 sim unit = 0.5 seconds (2x faster)\r\n```\r\n\r\n### Comprehensive Monitoring\r\n\r\nMonitor processes, resources, and events. See `references/monitoring.md` for techniques including:\r\n- State variable tracking\r\n- Resource monkey-patching\r\n- Event tracing\r\n- Statistical collection\r\n\r\n## Scripts and Templates\r\n\r\n### basic_simulation_template.py\r\n\r\nComplete template for building queue simulations with:\r\n- Configurable parameters\r\n- Statistics collection\r\n- Customer generation\r\n- Resource usage\r\n- Report generation\r\n\r\n**Usage:**\r\n```python\r\nfrom scripts.basic_simulation_template import SimulationConfig, run_simulation\r\n\r\nconfig = SimulationConfig()\r\nconfig.num_resources = 2\r\nconfig.sim_time = 100\r\nstats = run_simulation(config)\r\nstats.report()\r\n```\r\n\r\n### resource_monitor.py\r\n\r\nReusable monitoring utilities:\r\n- `ResourceMonitor` - Track single resource\r\n- `MultiResourceMonitor` - Monitor multiple resources\r\n- `ContainerMonitor` - Track container levels\r\n- Automatic statistics calculation\r\n- CSV export functionality\r\n\r\n**Usage:**\r\n```python\r\nfrom scripts.resource_monitor import ResourceMonitor\r\n\r\nmonitor = ResourceMonitor(env, resource, \"My Resource\")\r\n# ... run simulation ...\r\nmonitor.report()\r\nmonitor.export_csv('data.csv')\r\n```\r\n\r\n## Reference Documentation\r\n\r\nDetailed guides for specific topics:\r\n\r\n- **`references/resources.md`** - All resource types with examples\r\n- **`references/events.md`** - Event system and patterns\r\n- **`references/process-interaction.md`** - Process synchronization\r\n- **`references/monitoring.md`** - Data collection techniques\r\n- **`references/real-time.md`** - Real-time simulation setup\r\n\r\n## Best Practices\r\n\r\n1. **Generator functions**: Always use `yield` in process functions\r\n2. **Resource context managers**: Use `with resource.request() as req:` for automatic cleanup\r\n3. **Reproducibility**: Set `random.seed()` for consistent results\r\n4. **Monitoring**: Collect data throughout simulation, not just at the end\r\n5. **Validation**: Compare simple cases with analytical solutions\r\n6. **Documentation**: Comment process logic and parameter choices\r\n7. **Modular design**: Separate process logic, statistics, and configuration\r\n\r\n## Common Pitfalls\r\n\r\n1. **Forgetting yield**: Processes must yield events to pause\r\n2. **Event reuse**: Events can only be triggered once\r\n3. **Resource leaks**: Use context managers or ensure release\r\n4. **Blocking operations**: Avoid Python blocking calls in processes\r\n5. **Time units**: Stay consistent with time unit interpretation\r\n6. **Deadlocks**: Ensure at least one process can make progress\r\n\r\n## Example Use Cases\r\n\r\n- **Manufacturing**: Machine scheduling, production lines, inventory management\r\n- **Healthcare**: Emergency room simulation, patient flow, staff allocation\r\n- **Telecommunications**: Network traffic, packet routing, bandwidth allocation\r\n- **Transportation**: Traffic flow, logistics, vehicle routing\r\n- **Service operations**: Call centers, retail checkout, appointment scheduling\r\n- **Computer systems**: CPU scheduling, memory management, I/O operations",
    "user_template": ""
  },
  "variables": [],
  "install": {
    "steps": [
      {
        "title": "Download & unzip",
        "detail": "Download the .zip package from SkillVault and unzip it. The simpy/ folder contains SKILL.md plus any companion scripts, references and assets."
      },
      {
        "title": "Copy into your agent skills directory",
        "detail": "Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code), .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or reload the session."
      },
      {
        "title": "Use it",
        "detail": "Describe the task in natural language; the agent loads the skill automatically when the request matches the skill description."
      }
    ]
  },
  "usage": {
    "steps": []
  },
  "metadata": {
    "author": "SkillVault",
    "source": "https://skillvault.top/skills/simpy",
    "exported_at": "2026-11-03T07:40:53.449Z"
  }
}
simpy.aiskill (YAML)
format: aiskill/v1
skill:
  name: simpy
  slug: simpy
  version: 1.0.0
  description: >-
    Process-based discrete-event simulation framework in Python. Use this skill when building
    simulations of systems with processes, queues, resources, and time-based events such as
    manufacturing systems, service operations, network traffic, logistics, or any system where
    entities interact with shared resources over time.
  category: Research
  tags:
    - research-science
    - python
  platforms:
    - chatgpt
    - claude-code
    - cursor
  tested_environment: >-
    Agent Skills convention (SKILL.md) — works with Claude Code, Cursor, ChatGPT/Codex and
    compatible agents
  license: MIT LICENSE
prompts:
  system: "# SimPy - Discrete-Event Simulation\r\n\r\n## Overview\r\n\r\nSimPy is a process-based discrete-event simulation framework based on standard Python. Use SimPy to model systems where entities (customers, vehicles, packets, etc.) interact with each other and compete for shared resources (servers, machines, bandwidth, etc.) over time.\r\n\r\n**Core capabilities:**\r\n- Process modeling using Python generator functions\r\n- Shared resource management (servers, containers, stores)\r\n- Event-driven scheduling and synchronization\r\n- Real-time simulations synchronized with wall-clock time\r\n- Comprehensive monitoring and data collection\r\n\r\n## When to Use This Skill\r\n\r\nUse the SimPy skill when:\r\n\r\n1. **Modeling discrete-event systems** - Systems where events occur at irregular intervals\r\n2. **Resource contention** - Entities compete for limited resources (servers, machines, staff)\r\n3. **Queue analysis** - Studying waiting lines, service times, and throughput\r\n4. **Process optimization** - Analyzing manufacturing, logistics, or service processes\r\n5. **Network simulation** - Packet routing, bandwidth allocation, latency analysis\r\n6. **Capacity planning** - Determining optimal resource levels for desired performance\r\n7. **System validation** - Testing system behavior before implementation\r\n\r\n**Not suitable for:**\r\n- Continuous simulations with fixed time steps (consider SciPy ODE solvers)\r\n- Independent processes without resource sharing\r\n- Pure mathematical optimization (consider SciPy optimize)\r\n\r\n## Quick Start\r\n\r\n### Basic Simulation Structure\r\n\r\n```python\r\nimport simpy\r\n\r\ndef process(env, name):\r\n    \"\"\"A simple process that waits and prints.\"\"\"\r\n    print(f'{name} starting at {env.now}')\r\n    yield env.timeout(5)\r\n    print(f'{name} finishing at {env.now}')\r\n\r\n# Create environment\r\nenv = simpy.Environment()\r\n\r\n# Start processes\r\nenv.process(process(env, 'Process 1'))\r\nenv.process(process(env, 'Process 2'))\r\n\r\n# Run simulation\r\nenv.run(until=10)\r\n```\r\n\r\n### Resource Usage Pattern\r\n\r\n```python\r\nimport simpy\r\n\r\ndef customer(env, name, resource):\r\n    \"\"\"Customer requests resource, uses it, then releases.\"\"\"\r\n    with resource.request() as req:\r\n        yield req  # Wait for resource\r\n        print(f'{name} got resource at {env.now}')\r\n        yield env.timeout(3)  # Use resource\r\n        print(f'{name} released resource at {env.now}')\r\n\r\nenv = simpy.Environment()\r\nserver = simpy.Resource(env, capacity=1)\r\n\r\nenv.process(customer(env, 'Customer 1', server))\r\nenv.process(customer(env, 'Customer 2', server))\r\nenv.run()\r\n```\r\n\r\n## Core Concepts\r\n\r\n### 1. Environment\r\n\r\nThe simulation environment manages time and schedules events.\r\n\r\n```python\r\nimport simpy\r\n\r\n# Standard environment (runs as fast as possible)\r\nenv = simpy.Environment(initial_time=0)\r\n\r\n# Real-time environment (synchronized with wall-clock)\r\nimport simpy.rt\r\nenv_rt = simpy.rt.RealtimeEnvironment(factor=1.0)\r\n\r\n# Run simulation\r\nenv.run(until=100)  # Run until time 100\r\nenv.run()  # Run until no events remain\r\n```\r\n\r\n### 2. Processes\r\n\r\nProcesses are defined using Python generator functions (functions with `yield` statements).\r\n\r\n```python\r\ndef my_process(env, param1, param2):\r\n    \"\"\"Process that yields events to pause execution.\"\"\"\r\n    print(f'Starting at {env.now}')\r\n\r\n    # Wait for time to pass\r\n    yield env.timeout(5)\r\n\r\n    print(f'Resumed at {env.now}')\r\n\r\n    # Wait for another event\r\n    yield env.timeout(3)\r\n\r\n    print(f'Done at {env.now}')\r\n    return 'result'\r\n\r\n# Start the process\r\nenv.process(my_process(env, 'value1', 'value2'))\r\n```\r\n\r\n### 3. Events\r\n\r\nEvents are the fundamental mechanism for process synchronization. Processes yield events and resume when those events are triggered.\r\n\r\n**Common event types:**\r\n- `env.timeout(delay)` - Wait for time to pass\r\n- `resource.request()` - Request a resource\r\n- `env.event()` - Create a custom event\r\n- `env.process(func())` - Process as an event\r\n- `event1 & event2` - Wait for all events (AllOf)\r\n- `event1 | event2` - Wait for any event (AnyOf)\r\n\r\n## Resources\r\n\r\nSimPy provides several resource types for different scenarios. For comprehensive details, see `references/resources.md`.\r\n\r\n### Resource Types Summary\r\n\r\n| Resource Type | Use Case |\r\n|---------------|----------|\r\n| Resource | Limited capacity (servers, machines) |\r\n| PriorityResource | Priority-based queuing |\r\n| PreemptiveResource | High-priority can interrupt low-priority |\r\n| Container | Bulk materials (fuel, water) |\r\n| Store | Python object storage (FIFO) |\r\n| FilterStore | Selective item retrieval |\r\n| PriorityStore | Priority-ordered items |\r\n\r\n### Quick Reference\r\n\r\n```python\r\nimport simpy\r\n\r\nenv = simpy.Environment()\r\n\r\n# Basic resource (e.g., servers)\r\nresource = simpy.Resource(env, capacity=2)\r\n\r\n# Priority resource\r\npriority_resource = simpy.PriorityResource(env, capacity=1)\r\n\r\n# Container (e.g., fuel tank)\r\nfuel_tank = simpy.Container(env, capacity=100, init=50)\r\n\r\n# Store (e.g., warehouse)\r\nwarehouse = simpy.Store(env, capacity=10)\r\n```\r\n\r\n## Common Simulation Patterns\r\n\r\n### Pattern 1: Customer-Server Queue\r\n\r\n```python\r\nimport simpy\r\nimport random\r\n\r\ndef customer(env, name, server):\r\n    arrival = env.now\r\n    with server.request() as req:\r\n        yield req\r\n        wait = env.now - arrival\r\n        print(f'{name} waited {wait:.2f}, served at {env.now}')\r\n        yield env.timeout(random.uniform(2, 4))\r\n\r\ndef customer_generator(env, server):\r\n    i = 0\r\n    while True:\r\n        yield env.timeout(random.uniform(1, 3))\r\n        i += 1\r\n        env.process(customer(env, f'Customer {i}', server))\r\n\r\nenv = simpy.Environment()\r\nserver = simpy.Resource(env, capacity=2)\r\nenv.process(customer_generator(env, server))\r\nenv.run(until=20)\r\n```\r\n\r\n### Pattern 2: Producer-Consumer\r\n\r\n```python\r\nimport simpy\r\n\r\ndef producer(env, store):\r\n    item_id = 0\r\n    while True:\r\n        yield env.timeout(2)\r\n        item = f'Item {item_id}'\r\n        yield store.put(item)\r\n        print(f'Produced {item} at {env.now}')\r\n        item_id += 1\r\n\r\ndef consumer(env, store):\r\n    while True:\r\n        item = yield store.get()\r\n        print(f'Consumed {item} at {env.now}')\r\n        yield env.timeout(3)\r\n\r\nenv = simpy.Environment()\r\nstore = simpy.Store(env, capacity=10)\r\nenv.process(producer(env, store))\r\nenv.process(consumer(env, store))\r\nenv.run(until=20)\r\n```\r\n\r\n### Pattern 3: Parallel Task Execution\r\n\r\n```python\r\nimport simpy\r\n\r\ndef task(env, name, duration):\r\n    print(f'{name} starting at {env.now}')\r\n    yield env.timeout(duration)\r\n    print(f'{name} done at {env.now}')\r\n    return f'{name} result'\r\n\r\ndef coordinator(env):\r\n    # Start tasks in parallel\r\n    task1 = env.process(task(env, 'Task 1', 5))\r\n    task2 = env.process(task(env, 'Task 2', 3))\r\n    task3 = env.process(task(env, 'Task 3', 4))\r\n\r\n    # Wait for all to complete\r\n    results = yield task1 & task2 & task3\r\n    print(f'All done at {env.now}')\r\n\r\nenv = simpy.Environment()\r\nenv.process(coordinator(env))\r\nenv.run()\r\n```\r\n\r\n## Workflow Guide\r\n\r\n### Step 1: Define the System\r\n\r\nIdentify:\r\n- **Entities**: What moves through the system? (customers, parts, packets)\r\n- **Resources**: What are the constraints? (servers, machines, bandwidth)\r\n- **Processes**: What are the activities? (arrival, service, departure)\r\n- **Metrics**: What to measure? (wait times, utilization, throughput)\r\n\r\n### Step 2: Implement Process Functions\r\n\r\nCreate generator functions for each process type:\r\n\r\n```python\r\ndef entity_process(env, name, resources, parameters):\r\n    # Arrival logic\r\n    arrival_time = env.now\r\n\r\n    # Request resources\r\n    with resource.request() as req:\r\n        yield req\r\n\r\n        # Service logic\r\n        service_time = calculate_service_time(parameters)\r\n        yield env.timeout(service_time)\r\n\r\n    # Departure logic\r\n    collect_statistics(env.now - arrival_time)\r\n```\r\n\r\n### Step 3: Set Up Monitoring\r\n\r\nUse monitoring utilities to collect data. See `references/monitoring.md` for comprehensive techniques.\r\n\r\n```python\r\nfrom scripts.resource_monitor import ResourceMonitor\r\n\r\n# Create and monitor resource\r\nresource = simpy.Resource(env, capacity=2)\r\nmonitor = ResourceMonitor(env, resource, \"Server\")\r\n\r\n# After simulation\r\nmonitor.report()\r\n```\r\n\r\n### Step 4: Run and Analyze\r\n\r\n```python\r\n# Run simulation\r\nenv.run(until=simulation_time)\r\n\r\n# Generate reports\r\nmonitor.report()\r\nstats.report()\r\n\r\n# Export data for further analysis\r\nmonitor.export_csv('results.csv')\r\n```\r\n\r\n## Advanced Features\r\n\r\n### Process Interaction\r\n\r\nProcesses can interact through events, process yields, and interrupts. See `references/process-interaction.md` for detailed patterns.\r\n\r\n**Key mechanisms:**\r\n- **Event signaling**: Shared events for coordination\r\n- **Process yields**: Wait for other processes to complete\r\n- **Interrupts**: Forcefully resume processes for preemption\r\n\r\n### Real-Time Simulations\r\n\r\nSynchronize simulation with wall-clock time for hardware-in-the-loop or interactive applications. See `references/real-time.md`.\r\n\r\n```python\r\nimport simpy.rt\r\n\r\nenv = simpy.rt.RealtimeEnvironment(factor=1.0)  # 1:1 time mapping\r\n# factor=0.5 means 1 sim unit = 0.5 seconds (2x faster)\r\n```\r\n\r\n### Comprehensive Monitoring\r\n\r\nMonitor processes, resources, and events. See `references/monitoring.md` for techniques including:\r\n- State variable tracking\r\n- Resource monkey-patching\r\n- Event tracing\r\n- Statistical collection\r\n\r\n## Scripts and Templates\r\n\r\n### basic_simulation_template.py\r\n\r\nComplete template for building queue simulations with:\r\n- Configurable parameters\r\n- Statistics collection\r\n- Customer generation\r\n- Resource usage\r\n- Report generation\r\n\r\n**Usage:**\r\n```python\r\nfrom scripts.basic_simulation_template import SimulationConfig, run_simulation\r\n\r\nconfig = SimulationConfig()\r\nconfig.num_resources = 2\r\nconfig.sim_time = 100\r\nstats = run_simulation(config)\r\nstats.report()\r\n```\r\n\r\n### resource_monitor.py\r\n\r\nReusable monitoring utilities:\r\n- `ResourceMonitor` - Track single resource\r\n- `MultiResourceMonitor` - Monitor multiple resources\r\n- `ContainerMonitor` - Track container levels\r\n- Automatic statistics calculation\r\n- CSV export functionality\r\n\r\n**Usage:**\r\n```python\r\nfrom scripts.resource_monitor import ResourceMonitor\r\n\r\nmonitor = ResourceMonitor(env, resource, \"My Resource\")\r\n# ... run simulation ...\r\nmonitor.report()\r\nmonitor.export_csv('data.csv')\r\n```\r\n\r\n## Reference Documentation\r\n\r\nDetailed guides for specific topics:\r\n\r\n- **`references/resources.md`** - All resource types with examples\r\n- **`references/events.md`** - Event system and patterns\r\n- **`references/process-interaction.md`** - Process synchronization\r\n- **`references/monitoring.md`** - Data collection techniques\r\n- **`references/real-time.md`** - Real-time simulation setup\r\n\r\n## Best Practices\r\n\r\n1. **Generator functions**: Always use `yield` in process functions\r\n2. **Resource context managers**: Use `with resource.request() as req:` for automatic cleanup\r\n3. **Reproducibility**: Set `random.seed()` for consistent results\r\n4. **Monitoring**: Collect data throughout simulation, not just at the end\r\n5. **Validation**: Compare simple cases with analytical solutions\r\n6. **Documentation**: Comment process logic and parameter choices\r\n7. **Modular design**: Separate process logic, statistics, and configuration\r\n\r\n## Common Pitfalls\r\n\r\n1. **Forgetting yield**: Processes must yield events to pause\r\n2. **Event reuse**: Events can only be triggered once\r\n3. **Resource leaks**: Use context managers or ensure release\r\n4. **Blocking operations**: Avoid Python blocking calls in processes\r\n5. **Time units**: Stay consistent with time unit interpretation\r\n6. **Deadlocks**: Ensure at least one process can make progress\r\n\r\n## Example Use Cases\r\n\r\n- **Manufacturing**: Machine scheduling, production lines, inventory management\r\n- **Healthcare**: Emergency room simulation, patient flow, staff allocation\r\n- **Telecommunications**: Network traffic, packet routing, bandwidth allocation\r\n- **Transportation**: Traffic flow, logistics, vehicle routing\r\n- **Service operations**: Call centers, retail checkout, appointment scheduling\r\n- **Computer systems**: CPU scheduling, memory management, I/O operations"
  user_template: ""
variables: []
install:
  steps:
    - title: Download & unzip
      detail: >-
        Download the .zip package from SkillVault and unzip it. The simpy/ folder contains SKILL.md
        plus any companion scripts, references and assets.
    - title: Copy into your agent skills directory
      detail: >-
        Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code),
        .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or
        reload the session.
    - title: Use it
      detail: >-
        Describe the task in natural language; the agent loads the skill automatically when the
        request matches the skill description.
usage:
  steps: []
metadata:
  author: SkillVault
  source: https://skillvault.top/skills/simpy
  exported_at: "2026-11-03T07:40:53.449Z"

Installation guide

  1. 1

    Download & unzip

    Download the .zip package from SkillVault and unzip it. The simpy/ folder contains SKILL.md plus any companion scripts, references and assets.

  2. 2

    Copy into your agent skills directory

    Move the folder into your agent's skills directory — e.g. ~/.claude/skills/ (Claude Code), .codex/skills/, .cursor/skills/ or your project's .claude/skills/ folder — then restart or reload the session.

  3. 3

    Use it

    Describe the task in natural language; the agent loads the skill automatically when the request matches the skill description.

How to use

Platform compatibility

ChatGPT GPTs

OpenAI

Paste the system prompt into the GPT "Instructions" field and keep the user template as your starter message.

Official docs

Claude Code

Anthropic

Save the exported .aiskill JSON as a skill file in your project or paste the system prompt into CLAUDE.md / a slash-command markdown file.

Official docs

Cursor

Anysphere

Copy the system prompt into .cursor/rules/*.mdc (or Project Rules in Settings) and reference the user template in your agent prompts.

Official docs

Related skills

astropy AI agent skill cover
Free
ChatGPT GPTs Claude Code Cursor

astropy

Comprehensive Python library for astronomy and astrophysics. This skill should be used when working with astronomical data including celestial coordinates, physical units, FITS files, cosmological calculations, time systems, tables, world coordinate systems (WCS), and astronomical data analysis. Use when tasks involve coordinate transformations, unit conversions, FITS file manipulation, cosmological distance calculations, time scale conversions, or astronomical data processing.

#research-science#python
0 0 v1.0.0
fluidsim AI agent skill cover
Free
ChatGPT GPTs Claude Code Cursor

fluidsim

Framework for computational fluid dynamics simulations using Python. Use when running fluid dynamics simulations including Navier-Stokes equations (2D/3D), shallow water equations, stratified flows, or when analyzing turbulence, vortex dynamics, or geophysical flows. Provides pseudospectral methods with FFT, HPC support, and comprehensive output analysis.

#research-science#python
0 0 v1.0.0
geomaster AI agent skill cover
Free
ChatGPT GPTs Claude Code Cursor

geomaster

Comprehensive geospatial science skill covering remote sensing, GIS, spatial analysis, machine learning for earth observation, and 30+ scientific domains. Supports satellite imagery processing (Sentinel, Landsat, MODIS, SAR, hyperspectral), vector and raster data operations, spatial statistics, point cloud processing, network analysis, cloud-native workflows (STAC, COG, Planetary Computer), and 8 programming languages (Python, R, Julia, JavaScript, C++, Java, Go, Rust) with 500+ code examples. Use for remote sensing workflows, GIS analysis, spatial ML, Earth observation data processing, terrain analysis, hydrological modeling, marine spatial analysis, atmospheric science, and any geospatial computation task.

#research-science#infrastructure#python
0 0 v1.0.0