Scenario Comparison
A report of each job in an Experimenter Output.csv against one base job.
For each job it reports the value that the job shares with the base at the
compared times, the absolute and percent delta, and a rank by effect size.
The script reads the file that the application already wrote. It computes no
new simulation output. It reads the rows whose source_kind is job and
leaves out the saved_run rows. A name never decides which rows are which.
The app bundles this script as Scenario_Comparison.R and Scenario_Comparison.py. Type the bare file name as a Script’s File, or pick it with Bundled scripts… on a Script row. A copy beside the Experiment file runs in place of the bundled one. See Run your own R or Python. Back to the Scripts.
| File | Needs |
|---|---|
Scenario_Comparison.R | Rscript. Base R only, no package required |
Scenario_Comparison.py | python3, pandas and numpy. Install them with pip install pandas numpy |
The two agree to 1e-9 on the same input. The test suite checks this on every fixture.
Requirements
| Language | Needs |
|---|---|
| Python | Python 3.11 or later, with pandas and numpy. Install them with pip install pandas numpy. |
| R | R 4.3 or later. No package. |
The Excel workbook is optional. It needs openpyxl in Python, and openxlsx
or writexl in R.
The test suite runs on these versions in GitHub Actions. Older versions are not tested.
What It Computes
For each job other than the base, each shared variable, and each compared time:
Absolute delta, the value of the job minus the value of the base.
Percent delta, the absolute delta divided by the absolute value of the base, in percent. Dividing by the magnitude and not by the signed value keeps the sign equal to the direction of the change. A rise from -10 to -5 reads +50%, not -50%. A base value of zero leaves the percent delta blank. A zero denominator names no percentage, not a small or large one.
Rank, the position of the row within its own source and time, ordered by
|Percent_Delta| descending. A blank percent delta ranks last. It names no
effect size to compare against the others.
A (source, Variable, time) triple missing from either the base job or the compared job produces no row. A job need not carry every variable at every time.
The results go to Scenario_Comparison_<dataset>.csv beside Output.csv,
one row per triple scored, and Scenario_Comparison_<dataset>.html, the
same rows as a standalone page.
The Term “Scenario”
The report and the file name call a compared job a scenario. The computed
table names the column Source, not Scenario. It holds the source value
of Output.csv, unchanged. That is a job name, or the name of an
optimization group. The value column is Source_Value.
Sequences and Groups
A Sequence writes every member into one Output.csv and fills its
sequence column. It also fills the level column with the level of the
stage that wrote each row. A member can be a group, which fills the group
column. One source name, for example Alt, can then appear once in each
sequence, level or group. The script keeps these rows apart.
The report adds one column for each of these three that the file fills on
a job row. The order is Sequence, Level, Group, before Source. A
Sequence fills level on every row, so its report always has a Level
column.
Each compared source uses a base job by the first rule that applies:
- The base job with the same sequence, level and group.
- The one base job with the same sequence and group at a different level. This is the case for a stage at level 1 whose base ran at level 0.
- The one base job in the file. This is the case for an optimization group beside an ungrouped base.
Rule 2 can find more than one base job, or no rule finds one. Then the script stops and names each place that holds the base job.
Two rows with the same sequence, level, group, source, variable and time stop the script. It does not pick one of them.
Naming the Base Run
The script has to know which job in the file is the base. It reads that
name from EXPERIMENTER_BASE_RUN, then from the default, Base:
EXPERIMENTER_BASE_RUN=Reference Rscript Scenario_Comparison.R /path/to/Outputs/MyBatchIn an Experimenter Script step, write the variable with env. A Script step
starts the command without a shell, so NAME=value Rscript ... fails to
launch. The env form starts, and the step uses the copy of the script
that ships with the app, as it does without env. A copy of the script in
the folder of the Experiment takes precedence.
env EXPERIMENTER_BASE_RUN=Reference Rscript Scenario_Comparison.RThis is a different variable from EXPERIMENTER_COMPARISON_RUN, which
Experimenter sets on every Script run to name the observed saved run.
This script never reads a saved run. Its base is a second simulated job.
It therefore reads its own variable and not one with a different published
meaning.
A name that is not a job in the file stops the script with the message “no job named …” and lists the jobs. A saved-run name does not count. When the variable is unset, the script says so on its first line. Every other job in the file is a candidate scenario.
Choosing Variables and Times
By default, the report covers every variable that the base job and at least
one other job both carry. It uses the last time step that the file carries.
EXPERIMENTER_COMPARISON_VARIABLES and EXPERIMENTER_COMPARISON_TIMES
narrow either list. Each is a comma-separated list:
EXPERIMENTER_COMPARISON_TIMES=2030,2040 EXPERIMENTER_COMPARISON_VARIABLES="Core.Output,Core.Rate" \
Rscript Scenario_Comparison.R /path/to/Outputs/MyBatchIn a Script step, put env in front of both assignments, as shown under
“Naming the Base Run”.
A name or a time not in the file stops the script and lists what is. A comma
inside square brackets belongs to the name, so Pop[North, Young] selects one
element of a two-dimensional array.
What It Prints
One summary line. It holds the scenario-run count, the variable count, the compared-time count, and the files that the script wrote. Each of these cases stops the script with a message that names the problem:
- A missing or nonexistent output folder, a missing
Output.csv, or no rows to score. - A file that lacks
source,source_kind,variableorvalue. - An unknown column, or an unknown
source_kindvalue. - A
samplecolumn. - More than one dataset with none selected.
- A base job not in the file.
- No job other than the base. The message reads “holds no job other than the base run”.
- An unknown compared time or variable.
- No variable shared between the base job and a scenario job.
- No (source, Variable, time) combination with a value on both sides.
- A compared source with no base job beside it, and no rule that picks one base job.
- Two rows for the same sequence, level, group, source, variable and time.
The Excel Workbook
The Excel workbook is an optional output on both sides, never a requirement:
Scenario_Comparison.pywritesScenario_Comparison_<dataset>.xlsxonly whenopenpyxlimports. Its absence is silent. The CSV above already carries the same rows.Scenario_Comparison.Rwrites the workbook only whenopenxlsxorwritexlis already installed, tried in that order. Neither installed is not an error. The CSV that the script already wrote is the fallback.
Where It Runs
With no argument, the output folder comes from EXPERIMENTER_OUTPUT_DIR
and the time column from EXPERIMENTER_TIME_COLUMN. This is the shape that
an Experimenter Script step runs in. You can also give the folder of a
finished batch by hand as the first command-line argument. Then the script
finds the time column by elimination against the column set that
Experimenter publishes. The argument wins when you give both. It always
names the output folder here and never a Run. Every other script in this
library takes the same first argument.
The script reads Output.csv in either layout and prints the layout it
read. For a wide file, set EXPERIMENTER_TIME_COLUMN to name the time
column. The default name is Time.
Rscript Scenario_Comparison.R /path/to/Outputs/MyBatchIn a Chain
The script reads Output.csv and writes Scenario_Comparison_<dataset>.csv
into the same folder, with the HTML and workbook files beside it. To get one
CSV for every dataset of a sweep, run Collect_Datasets --stem Scenario_Comparison
after it. See the chaining rules.
Version Policy
The library README sets the format policy. The header of this file names the Experimenter version that it targets. The script checks every column before it computes anything. An unknown column stops the script with a message that names it. A version difference prints one line and does not stop the run.