Input Sources
An input source is where an input’s data comes from: a file the CLI uploads, or a data fetcher that pd4castr runs on a schedule. Most inputs have one input source. When the same input comes from more than one data provider, you can give it several input sources. pd4castr then starts runs for each input source as that input source’s data arrives.
Each input source has a key, such as aemo or nz. The keys become the values
of a model axis called a source-binding axis, so people
viewing the model choose which input source’s runs to see the same way they
choose any axis value.
When to Use Several Input Sources
Give an input several input sources when one model should forecast from the same kind of data published by different data providers, and each data provider’s data arrives on its own schedule. Demand data from AEMO and from a New Zealand data provider is one example: the same model logic applies to both, and a new AEMO file shouldn’t wait for the next New Zealand file.
Partitioning an input by an axis solves a different problem. It splits one file by the values in one of its columns, and each run reads its own rows of that file. Several input sources supply separate files that arrive at different times, and each new file starts runs of its own.
Example: Demand from Two Data Providers
This model has a demand input with two input sources, aemo and nz, and a
holidays input with one:
{
"axes": [
{
"key": "demand_source",
"label": "Demand source",
"type": "string",
"valuesFrom": { "kind": "source-binding" },
"default": "aemo"
}
],
"inputs": [
{
"key": "demand",
"trigger": "WAIT_FOR_LATEST_FILE",
"uploadFileFormat": "json",
"targetFileFormat": "json",
"axes": { "demand_source": { "kind": "source-binding" } },
"sources": {
"aemo": {
"fetcher": {
"type": "AEMO_MMS",
"checkInterval": 300,
"config": {
"checkQuery": "queries/demand-check.sql",
"fetchQuery": "queries/demand-fetch.sql"
}
}
},
"nz": { "file": "data/nz-demand.json" }
}
},
{
"key": "holidays",
"file": "data/holidays.csv",
"trigger": "USE_MOST_RECENT_FILE",
"uploadFileFormat": "csv",
"targetFileFormat": "csv"
}
]
}Once the model is published:
- Each time the AEMO data fetcher writes a new
demandfile, pd4castr starts runs for theaemoinput source. - When the CLI uploads
data/nz-demand.jsonat a publish, the new file starts runs for thenzinput source. To send New Zealand files between publishes, givenzits own storage location. - Your container reads the
demandfile from theINPUT_DEMAND_URLenvironment variable, as it reads any input. In anaemorun it holds the AEMO file, and in annzrun it holds the New Zealand file.INPUT_HOLIDAYS_URLholds the same holidays file in both. - The app shows a “Demand source” checklist with
aemoandnz, withaemochecked. Checkingnzas well shows both input sources’ runs side by side.
Setting Up Input Sources
- On the input, replace
fileorfetcherwith asourcesmap. Each entry holds afileor afetcher, keyed by its input source key. - Choose input source keys made of lowercase letters, digits,
_, and-, starting with a letter or digit. The app’s checklist shows the keys as they are, so choose keys people will recognise. - Declare a source-binding axis in the model’s
axesarray, with"type": "string"and"valuesFrom": { "kind": "source-binding" }. It takes its values from thesourceskeys, so it lists none of its own. - Set the axis’s
defaultto the input source people see first. The default is required when thesourcesmap has more than one entry. - Connect the input to the axis by adding
"axes": { "<axis_key>": { "kind": "source-binding" } }to the input.
The configuration file reference lists every field an input source entry takes. When you fill them in:
- Give every input source’s files the same columns. Your container reads them all from one environment variable and can’t tell which input source a file came from.
- Keep one
targetFileFormaton the input: the format your container receives. When an input source’s files arrive in a different format from the input’suploadFileFormat, set that input source’s ownuploadFileFormat, and pd4castr converts its files totargetFileFormat. An input source without its ownuploadFileFormatuses the input’s. The default input source can’t be converted, so its files must arrive intargetFileFormat. In the example, the AEMO data fetcher writes JSON, so the input declares"uploadFileFormat": "json". A Parquet file from New Zealand would need"uploadFileFormat": "parquet"on thenzinput source. storageLocationmoves from the input to each input source that needs one. An input source without one uses pd4castr’s shared storage location. An input source declared withfileneeds its own storage location to receive files between publishes. One declared withfetchernever needs one.
A model can’t have more than one source-binding axis. Several inputs can connect to it, and each of them must declare the same input source keys. An input with several input sources can’t also be partitioned by another axis.
A dataset can be partitioned by the source-binding axis, using a column that holds input source keys. The column must hold every input source key, including any you add later.
How Input Sources Start Runs
pd4castr runs the model for each input source as if that input source had its
own copy of the model, under the usual
trigger rules. pd4castr
starts runs for an input source once every input has a file and every
WAIT_FOR_LATEST_FILE input has a new file since that input source’s last run.
pd4castr counts files for an input source this way:
- For an input with several input sources, only the input source’s own files count.
- When a new file arrives for an input with one input source, it counts for every input source.
The files of an input with one input source count for every input source, so
that input’s trigger type sets how often each input source can start runs.
Suppose holidays in the example above updates once a day:
- With
USE_MOST_RECENT_FILE, each input source starts runs as soon as itsdemandfile arrives, using the newest holidays file. - With
WAIT_FOR_LATEST_FILE, each input source also waits for a holidays file newer than its last run.aemoandnzthen start runs at most once a day each, however often theirdemandfiles arrive.
Each trigger for an input source starts the same set of runs a trigger starts on
any model: one run per variant of your other axes, plus one per variant for each
sensitivity, as
How axes change your runs
describes. Those runs share one run datetime, the runDatetime value that
labels a set of runs in the app and the API. When a
custom run datetime query
reads an input with several input sources, it reads the file of the input source
the runs belong to.
A model can start at most 200 runs per trigger. Input sources’ data can arrive at the same moment, so at publish the CLI adds up every input source’s runs and checks the total against that limit. In the example above, with two sensitivities added, each input source starts 1 + 2 = 3 runs, and the CLI counts 6.
On a model in the
ON_DEMAND run mode, the app’s
“Run model” button runs the model for the default input source. To run it for
another input source, use the API, as the next section shows.
Viewing an Input Source’s Runs
People choose an input source wherever they choose an axis value:
- In the app, the source-binding axis shows as a checklist of input source keys, with the default checked. Checking another input source shows its run at the selected run datetime. When it has no run at that datetime, the app shows its newest run.
- In the API, Trigger a model run,
List runs for a model, and
Get the latest run take
axis=<axis_key>:<input_source_key>. Without it, triggering and the latest run use the default input source, and the run list includes every input source’s runs. - In the Python SDK, pass the input source key like any axis value, as in
axes={"demand_source": "nz"}. See Fetch an axis variant.
Testing and Publishing
pd4castr fetch and pd4castr test both use the default input source, the one
the axis’s default picks:
pd4castr fetchwrites the default input source’s data totest_input/when that input source is a data fetcher. It skips every other input source, and skips the input when its default input source is a file.pd4castr testruns your model on the default input source’s file.
pd4castr publish uploads every input source’s file, then starts one set of
runs for the default input source. On an AUTOMATIC model, each uploaded file
is also a new file for its own input source, so it can start that input source’s
runs under the rules in
How input sources start runs.
Changing Input Sources Later
When you update a model’s current revision in place, you can add an input source, or remove one other than the default. Publish a new revision to change the default input source, or to turn a static axis, one that lists its own values, into a source-binding axis or back. Giving a published model its first input with several input sources adds a source-binding axis, so that also needs a new revision. Changing axes on a published model explains why.
When you remove an input source, pd4castr stops starting runs for it. The app no longer offers it, so its earlier runs drop out of view. The API’s run list still includes them when you don’t filter by axis.
When a publish changes a data fetcher’s check or fetch query, pd4castr fetches that input source’s data again, as it does for any fetched input.