Skip to content

Defining Scenarios

Scenarios are situations where your agent needs to behave differently to succeed.

Here are some examples of scenarios:

AgentScenarios
Drone Controlwindy, long distance from charger, low battery level
Autonomous Drivingcity, highway, high traffic
Cybersecurity Network Optimizationnormal traffic, usage spike from promotion, cyber attack
Process Controlprocess startup, steady-state, process shutdown
Machine Controlbreak in period, normal, end of machine life

Scenario Parameters

Scenarios are like sections of the space your agent will explore for decisions (actions) that bring it closer to the goals of successfully completing the task. These sections can be defined by groups of variables and variable ranges.

Discrete Variables

Discrete variables are categories that describe a particular scenario. For each scenario, there is likely a perceptor in the agent (a machine learning model for example) that inputs the sensors, processes the sensor values, and outputs the discrete variable category.

Continuous Variables

Continuous variables are numbers. When they are used to define a scenario that one number value defines the section of the space that your agent will explore for decisions.

Sometimes a scenario is better defined by a range of continuous values than by a single continuous value. In that case, the scenario would be defined by a continouous variable range.

Examples

Here are some examples of how scenarios can be defined in different ways:

AgentDiscrete VariablesContinuous Variable ValuesContinuous Variable Ranges
Drone Controlwindy, far_from_charger, low_batterywindspeed=20 (knots)windspeed between 20-40 (knots)
Autonomous Drivingcity, highway, high_trafficvehicle_speed=65 (miles per hour)vehicle_speed between 65-85 (miles per hour)
Cybersecurity Network Optimizationnormal, high_traffic, cyberattacksite_traffic=0 (clicks per second)site_traffic between 100-150 (clicks per second)
Process Controlstartup, steady_state, shutdownproduct_thickness=50 (milimeters)product_thickness between 49.94-50.06 (milimeters)
Machine Controlbreak-in, normal, wearing_outrpm=280 (revolutions per minute)rpm between 250-295 (revolutions per minute)

Coding Scenarios

Code each scenario as a Python dictionary with each variable (discrete, continuous, or continuous range) as a key, value pair. Discrete variables should look like this: "state1": "category", continuous variables should look like this: "state1": 0, and continuous ranges should look like this: "state1": [0,5].

Here are two of several scenarios in the agent that controls the demo-sim:

python

increment_scenarios = [
    {
        "state1": 0,
    },
    {
        "state1": -25,
    },
    {
        "state1": 25,
    },
]

decrement_scenarios = [
    {
        "state1": 0,
    },
    {
        "state1": -25,
    },
    {
        "state1": 25,
    },
]

target_scenarios = [
    {
        "state1": 0,
    },
    {
        "state1": -25,
    },
    {
        "state1": 25,
    },
]

Creating a Scenario Definition File (Optional)

A cleaner agent.py file helps keep your agent organized. So, we recommend creating a separate file (e.g. scenarios.py) to contain the scenario definitions. Alternatively, you can include the scenario definitions in the agent Python file.

python

from composabl import Scenario

increment_scenarios = [
    {
        "state1": 0,
    },
    {
        "state1": -25,
    },
    {
        "state1": 25,
    },
]

decrement_scenarios = [
    {
        "state1": 0,
    },
    {
        "state1": -25,
    },
    {
        "state1": 25,
    },
]

target_scenarios = [
    {
        "state1": 0,
    },
    {
        "state1": -25,
    },
    {
        "state1": 25,
    },
]

Unlike with sensors and perceptors, we don't add scenarios to the agent at this stage. That's because scenarios are added to specific skills rather than the agent as a whole. The reason for this is that not all skills need to perform in all scenarios. For example, a drone may need to fly and land in extremely windy conditions. But it may not need to learn the takeoff skill in this scenario, because it would not be cleared for takeoff under these conditions.

You'll learn how to add scenarios to skills in the next section.