Overview
Variants are a way to codify multiple periods or horizon on the same network. Variants are mark with a # at the ends of properties (ex: headway#AM). Variants are added on the:
- Networks (PT and road)
- Parameters
- Model (parallel excecution)
Network
Network variants (such as period) can be added with # in the property (ex: headway#AM)
"index": "link_21611",
"trip_id": "Trip 1",
"a": "node_242202",
"b": "node_236804",
"link_sequence": 9,
"drop_off_type": 0,
"pickup_type": 0,
"headway": 402,
"headway#AM": 402,
"headway#PM": 804,
"route_type": "subway",
"route_color": "4CAF50",
"agency_id": "Quetzal",
"route_short_name": "route 1",
"route_width": 5,
"direction_id": 0,
"speed":20
"speed#AM": 20,
"speed#PM": 15,
"time":338
"time#AM": 338,
"time#PM": 450,
DANGER
Properties with variant MUST be added for every variant. If there is 2 variants, AM & PM, you we should have speed#AM and speed#PM or only Speed.
info (Road)
Road reversed properties MUST end with _r just like before ex: speed#AM, speed#AM_r
variants can be filtered in the edition dialog.
Every variant can be edited at once while filtering a single property (here 5 variants).
Stepfunction
You can add variants to the model (for example periods). Variants needs to be added to the params.json to described the choices and the selected one.
[
{
"variants": [
"AM",
"PM"
],
"choices": [
"AM",
"PM",
"MD",
"NI",
],
"multiple": true, // optional
"label": "periods", // optional
"model": "default" // optional
},
...
]
Parallel function execution is defined in the step-function.js. in the example below, each variants are map to the period argv of the notebook, but any name is possible.
Note
it is possible to pass only one variant or none to the Parallel Iterator. if none are passed, the steps are skipped.
"Parallel Iterator": {
"Type": "Map",
"InputPath": "$",
"ItemsPath": "$.variants",
"Parameters": {
"scenario_path_S3.$": "$.scenario_path_S3",
"metadata.$": "$.metadata",
"launcher_arg": {
"training_folder.$": "$.launcher_arg.training_folder",
"params.$": "$.launcher_arg.params",
// period.$ can be changed to any notebbok argv
"period.$": "$$.Map.Item.Value"
}
},
// all parallel steps defined here.
"Iterator": {
"StartAt": "Network Preparation",
"States": {
"Network Preparation": {
"Type": "Task",
...
"Next": "Road Model"
},
...
}
},
"End": true
}
import sys
import json
default = {'scenario': 'base', 'period': 'AM', 'training_folder': '../..'}
manual, argv = (True, default) if 'ipykernel' in sys.argv[0] else (False, dict(default, **json.loads(sys.argv[1])))
Parameters
variants can be added to each parameters in params.json in the web interface or manually in the json (adding #var at the end)
Note
The choice of variants are the one already defined in params.json
on the image above:
- show the buttons (2, 3, 4)
- add a variant to the parameter
- change the variant between the available choices
- delete a parameter's variant
[
{
"variants": [
"AM",
"PM"
],
"choices": [ // the choices
"AM",
"PM",
"MD",
"NI",
],
...
},
...
{
"text": "speed",
"value": 2.82,
"type": "Number",
"units": "km/h",
"hint": "Footpaths walking speed (acf)",
"rules": [
"required"
],
"name": "speed"
},
{
"text": "speed#AM",
"value": 2.82,
"type": "Number",
"units": "km/h",
"hint": "Footpaths walking speed (acf)",
"rules": [
"required"
],
"name": "speed#AM"
},
...
]
python utils
A function to correctly parse the variants in the parameters is available in pyhton
from quetzal.io.quenedi import read_parameters
var = excel.read_var(file=os.path.join(input_folder, 'parameters.xlsx'), scenario=scenario, period=period, return_ancestry=False)
if 'params' in argv.keys():
params = read_parameters(argv['params'], period=period)
var.update(params)
A function to correctly parse the networks is available in pyhton
from quetzal.io.quenedi import restrict_to_variant
restrict_to_variant(sm, period=period)