Simulator


Play a scenario against an agent instead of the plant: starting data, a moving world and the trigger, inside XMPro.


ContributorXMPro
TypeAgent

The simulator plays a scenario against an agent instead of the plant. It loads the scenario’s starting data into Masterdata, moves its world forward every 10 seconds (readings drift, faults appear), and delivers the scenario’s trigger when it’s due, so you can watch the agent react in chat, in the action inbox and in its logs.

Every package has scenarios: 1,706 across the 145 packages, generated from each package’s acceptance cases. They are a generated starting set, not yet reviewed one by one.

What’s in simulator/

Path What it is
runtime/ The bridge (xmsim_xmpro.py), the simulator engine it uses (xmsim/), the tick script, the SQL setup and a Dockerfile for a Stream Host with Python
packs/<domain>/<package>/ Each package’s scenarios: scenarios.json (what happens and what should happen), inputs.json (starting data, world, faults) and deploy.json (the package scope and approvers a run sets up)
datastreams/Agent Library Simulator.xuc The stream that runs it: an Event Simulator ticking every 10 seconds into the Python agent

Install

  1. A Stream Host with Python 3.11 and pymssql. The XMPro Python agent loads Python in process, and the bridge talks to SQL Server with pymssql. For a Docker Stream Host, build the image in runtime/Dockerfile from the Stream Host image you run:

    docker build --build-arg STREAM_HOST_IMAGE=<your stream host image:tag> -t stream-host-python runtime
    

    Run your Stream Host from that image. Tested on the Linux Docker Stream Host of XMPro 5.1; a Windows Stream Host needs Python 3.11 and pymssql installed and the same environment variables as the Dockerfile, and has not been tested.

  2. Copy the files to the Stream Host so it sees runtime/ at /opt/xmsim/runtime and packs/ at /opt/xmsim/packs (in Docker, mount them read-only). PYTHONPATH must be /opt/xmsim/runtime (the Dockerfile sets it).

  3. The simulator’s SQL login and run log. Run runtime/xmsim-setup.sql in Masterdata once, as an administrator. It creates the login xmsim_sim and the tables xmsim.Run and xmsim.Frame. Put the password you gave it in a file on the Stream Host, for example /run/xmsim/sql_password.

  4. The run settings. Copy runtime/run.example.json to /opt/xmsim/run.json and set your SQL Server and the scenario to run. The password stays in its file, never in run.json.

  5. The stream. In Data Stream Designer, upload the Event Simulator (2.00) and Python agents if you don’t have them, import Agent Library Simulator.xuc (password Dem0nstr@t1on), point it at the Stream Host with Python, and leave it unpublished until you want a run.

The package you’re testing must be imported and running first, with its domain’s SQL loaded (see the import guide).

Run a scenario

  1. Pick a scenario from the package’s packs/<domain>/<package>/scenarios.json: its scenario_id, title and expected_plain say what it tests and what should happen.
  2. Set "scenario" in /opt/xmsim/run.json to that ID.
  3. Publish the Agent Library Simulator stream. Each start begins a new run; it ends by itself after the scenario’s duration_s.
  4. Watch the run:

    SELECT TOP 5 * FROM xmsim.Run ORDER BY started_at DESC;          -- setup: what it deployed, and any problems
    SELECT * FROM xmsim.Frame WHERE run_id = '<run_id>' ORDER BY frame;   -- one row per tick: writes, errors, the trigger
    
  5. When the trigger is a person asking the agent something (most supply chain scenarios), the frame shows ask the agent: ...: type that question in the agent’s chat.
  6. Compare what the agent did with the scenario’s expected_plain.
  7. Unpublish the stream when you’re done.

A scenario’s starting data replaces the demo rows it shares keys with, so the agent sees the scenario’s state. Run the domain’s demo data script again to put the demo back.

MIT License For assistance or requests, please contact support@xmpro.com