#Where data comes from and where it goes
A program reads data from inputs and writes its results to outputs. An input is written the same way whatever gives it its data, reading = input("reading", t : 4): stored data that already exists (a table, a file, a database), data made on request at each point the program asks (an AI model, a web API), or rows given over time while the program runs (sent by another program, replayed from a file, or a clock's ticks). The deployment says which each input is, never the program. The same program runs in two places: in the playground, where everything you give it lives in the browser page, and in a deployment, the elucid8 command on your computer or server, where data comes from files and other programs. This page takes stored inputs, inputs answered on demand, inputs given rows over time and outputs in turn, and says what each looks like in the playground, where inputs and outputs are on the Data In/Out tab, and in a deployment.
A program may read any number of inputs and have any number of outputs, in the playground and in a deployment.
#Stored inputs
Stored data already exists, and the program reads it: a table, a file, a database. Such data is often called a data source. In a program it is an input, reading = input("reading", t : 4): it is read from the channel "reading", and names its dimensions and how far each goes (inf for data with no end); input("rate"), naming none, is one value. Where the data comes from is not in the program: in the playground it is the input's card, in a deployment its entry in deploy.json.
-- Stored data: four readings, each with its time; t = 2 has no row.
reading = input("reading", t : 4)
clicks = input("clicks", t : 4)
-- table reading = t,value,ts; 0,3,1000; 1,1,2000; 3,1,4000
-- table clicks = t,value; 0,5; 3,2
-- fill clicks = 0
-- expect reading[t = 1] = 1, at time 2000 ms
-- expect reading[t = 2] = error missing: input reading has no data at this point
-- expect clicks[t = 1] = 0
-- expect clicks[t = 3] = 2
- A missing row is missing data: an error of kind
missing, at time 0 (on an input whose times come from a coordinate, that coordinate's time), and anything computed from it says so; along a dimension declaredinf, past the input's last row along it there is no data yet, and it is eod (inside a finite bound or list a point with no row is missing data). "fill": {"missing": 0}in the input's entry reads a missing row (or an empty cell) as 0, for data where no row means nothing happened (no clicks that minute); any number,true,falseor a text may be the fill. Past the last row along a dimension declaredinfa point is still eod. Here-- fill clicks = 0says so forclicks.- Rows may carry timestamps, in a
tscolumn: the time each value became known, in milliseconds. Stored data's timestamps are always the data's own (a time column, or a time for each coordinate set indeploy.json), and 0 where the data give none: never the time the file was read, so the same data give the same answers whenever the program runs. Every value computed from them carries the latest time among the data it read (Values and timestamps). - A file holds a column per dimension and a
valuecolumn, in CSV, JSON lines, Apache Parquet or Apache Arrow, so a table written by pandas, Polars or DuckDB is read as it is (Parquet and Arrow). From 0.20.0, the Download page offers a sample of every format, each with a program that reads it and its expected answer. A file without a column for one of the input's dimensions makes every point of the input eod, andelucid8 checksays which column is missing. - A table with a column per field (
t,temperature,humidity) is read with the input's"wide":{"from": "readings.csv", "wide": "quantity"}readsreadings = input("readings", t : inf, quantity : {"temperature", "humidity"}), each row a point per column, the column's name its coordinate alongquantity. A file with no column for its rows takes each row's position instead, with"row"(A file with a column per coordinate). - Data that names things (stock symbols, sensor ids) is read through a map from each name to its number: the program sees numbers, and the results come back with the names (Names instead of numbers).
| In the playground | In a deployment | |
|---|---|---|
| Where the data is | in the page: a table you type or paste, Load file… (CSV or JSON lines, up to 5 MB, read in the page), a formula over the coordinates, or an example's built-in data | a file per input: CSV, JSON lines, or an Apache Parquet or Arrow file as pandas, Polars and DuckDB write them (Data files); or a program that serves the rows through the connector protocol (a database, an API) |
| When it changes | you edit it and press Update: a new version | a new file, or several files listed as versions of one input; under elucid8 serve, advance brings a new version, or rows appended to the last one (The long-running service) |
#Inputs answered on demand
Some data is made on request: at each point the program asks an outside program, such as an AI model or a web API, and the answer is data stamped with the time it arrived. Such a program is often called a data service. In a program it is an input too, asked by navigation: echo = input("echo", n : inf) is over a dimension n, and echo[n = reading] asks it, at each t, for its answer at n = reading. Only the deployment says that echo is answered on demand:
-- Answered on demand: echo answers with what it is asked; slow_echo takes too long.
reading = input("reading", t : 4)
echo = input("echo", n : inf)
answer = echo[n = reading]
slow_echo = input("slow_echo", n : inf)
slow = slow_echo[n = reading]
-- table reading = t,value,ts; 0,3,1000; 1,1,2000; 2,4,3000; 3,1,4000
-- service echo: answers formula x1; takes 5 ms; deadline 20 ms
-- service slow_echo: answers formula x1; takes 30 ms; deadline 20 ms
-- expect answer[t = 1] = 1, at time 2005 ms
-- expect slow[t = 1] = error late from slow_echo[n = 1]: late (2030 ms > deadline 2020 ms), at time 2020 ms
- A question starts at the time of the data it is asked with (here 2000 ms at t = 1), and its answer is stamped with the time it arrived.
- A late or failed answer is an error that says why: never a number made up in its place. A program that must decide anyway tests for it,
if iserror(risk) then … else …. - The deadline (how long an answer may take), what to try again and whether to reuse answers are the input's settings, not part of the program: on its card in the playground, and in
deploy.jsonin a deployment (Data services).
The playground makes no network calls, so the programs that answer its inputs stand in for real ones. A simulated program answers a sum, a score or a formula, optionally with a delay and a failure rate (a sum, a mean or the largest of the coordinates it is asked at; a score from 0 to 100; a formula over them). In the playground a new one answers the sum of its inputs after 5 ms and never fails; in deploy.json it is {"builtin": "simulated", …}, its latencyMs must be given (0 answers at once), and it never fails unless failRate is set.
| In the playground | In a deployment | |
|---|---|---|
| What answers | sum_service (adds the coordinates it is asked at, after the delay on its card) and simulated programs you set on an input's card; no network calls | the same built-ins (sum_service, simulated, anomaly_detector), a recording of earlier answers replayed, or a real program you run, through the input protocol (Command reference), which may call an AI model or an API |
| Its settings | on its card: Takes and Deadline, and under More settings failures, retries and reuse | its entry in deploy.json: deadlineMs, retry and reuse |
#Inputs given rows over time
A program kept running by elucid8 serve takes new data while it runs, and answers every question with the data it has so far (The long-running service). An input with no end along t holds what has arrived:
-- Readings that keep arriving, and the mean of the last five.
reading = input("reading", t : inf)
avg5 = mean reading over (t : #t - 4 .. #t) end
-- table reading = t,value; 0,0; 1,2; 2,4; 3,6; 4,8; 5,10; 6,12
-- expect avg5[t = 0] = 0
-- expect avg5[t = 6] = 8
Its rows can arrive in three ways, each set in the input's entry in deploy.json; the program is the same whichever it is:
- Sent by another program, as they are produced: a sensor's script, a Python program, another service sends each row to the service (
POST /inputs/reading/rows, oradvancewith rows). The input's entry is its first file, or none. - Replayed from a file you have, one
tat a time:{"from": {"builtin": "replay", "file": "history.csv", "every": "1s"}}gives the service the file's rows fort= 0 when it starts, then the nextt's rows each second; with"loop": trueit starts again after the last, everytmoved on, so the data keep growing. - A clock, a row a tick, for a program that only needs time to pass (a sine wave, a schedule):
{"from": {"builtin": "clock", "every": "100ms"}}gives a row att= 0, 1, 2, …, its value and its timestamp the tick's time in milliseconds;"until"ends it after a number of ticks, and"start"sets the time of tick 0.
With the readings in history.csv and this deploy.json:
{
"format": "elucid8-deploy/2",
"inputs": { "reading": { "from": { "builtin": "replay", "file": "history.csv", "every": "1s" } } }
}
elucid8 check says what the input is given:
input "reading": history.csv replayed: one t's rows every 1000 ms, 6 coordinates in order; over t (whole numbers); a missing point is missing data (eod past the last row along t); elucid8 serve gives it its rows over time, elucid8 run cannot read it
- The rows of a replay or a clock are the service's own: rows sent to that input are refused, and
elucid8 run, which computes once and cannot wait, refuses such a program; give the input a file instead. - Questions and subscriptions follow the data however it arrives:
total[t = last]asks for the last, a subscription (orwatchinelucid8 repl) is told each change, and the eLucid8 Player follows it live (Tutorial, section 12).
| In the playground | In a deployment | |
|---|---|---|
| How rows arrive | the data you give the input, all at once; ◀ ▶ and Play step through them | elucid8 serve: rows sent by another program, a replay of a file, or a clock |
#Outputs
An output writes a value as records: one row per point, a column per dimension and one for the value (and its timestamp). A program names its outputs itself, as equations, output("channel") = e, one value each:
-- The readings and their running total, written out together.
reading = input("reading", t : 4)
total = reading fby.t (total + next.t reading)
output("readings") = reading
output("total") = total
-- table reading = t,value,ts; 0,3,1000; 1,1,2000; 2,4,3000; 3,1,4000
-- expect output "readings" over t = 0..3
-- expect output "total" over t = 0..3
-- expect total[t = 3] = 9, at time 4000 ms
- The right side is any expression, written over its own bounds: here
tfrom 0 to 3. An output is not a value: no equation reads it. From 0.22.0, a program may write a channel it reads (output("reading") = reading); that output's file is thenreading-output.csv, so that it never replaces the data read. - Where it goes, and in what format, is the deployment's choice. With no choice made,
elucid8 runwrites each channel to a CSV file named after it besidedeploy.json(readings.csvandtotal.csvhere).deploy.jsonmay name another file, a format ("jsonl"for JSON lines,"parquet","arrow","npz"for NumPy,"frame", and, from 0.19.0,"zarr"and"vega-lite"for drawing, Seeing your results), or a program that takes the records, such as a database or a webhook, through the connector protocol. Such a destination is often called a sink. - Channels with the same dimensions and rows may share a file, side by side.
- Records that are eod can be left out:
"readings": {"skip": "eod"}writes only the records whose value is not eod (errors are always written), so an output that is eod wherever it has nothing to say writes only what it has (Leaving out eod records). - A table can be written wide, a column per coordinate of one dimension:
"table": {"wide": "quantity"}writes a row pertand a column per quantity, the shape a file read with"wide"has, each column's kind and message beside it (temperature_kind,temperature_message); with"csvWords": trueas well, a table read wide is written back as it was read (An output written wide).
With the readings in reading.csv (the program's four rows, each with its ts) and this configuration, which writes the two channels side by side:
{
"format": "elucid8-deploy/2",
"inputs": { "reading": { "from": "reading.csv" } },
"outputs": { "readings-report.csv": {"channels": ["readings", "total"]} }
}
./elucid8 run plan.json --config deploy.json writes readings-report.csv:
t,readings_value,readings_kind,readings_message,total_value,total_kind,total_message
0,3,value,,3,value,
1,1,value,,4,value,
2,4,value,,8,value,
3,1,value,,9,value,
Each value's column holds its data alone, so a spreadsheet or pandas reads it as numbers; its kind (value, eod, or error and the error's kind) and an error's message are beside it (Columns named after their channel).
A CSV file has no timestamps unless asked: with "timestamps": true (or --timestamps), each value's follows its message, t,readings_value,readings_kind,readings_message,readings_ts,total_value,…. The other formats carry them unless asked not to (Timestamps in files). The same two channels as an Apache Parquet file, which pandas, Polars and DuckDB read:
"outputs": { "archive.parquet": {"channels": ["readings", "total"]} }
| In the playground | In a deployment | |
|---|---|---|
| Where it goes | each output has a card in the Outputs section of Data In/Out (Add output there writes its equation into the program); Download results on the card saves the records as a file (CSV or JSON lines; an output in another format downloads as either), at most 100,000 records; where the page cannot save a file, Copy results | a file written by elucid8 run (CSV, JSON lines, frames, Arrow, .npz or Parquet), or a program that takes the records (a database, a webhook) through the connector protocol |
| When it is written | when you press Download results | each elucid8 run; under elucid8 serve, a subscription to an output sends a program only the records that changed when new data arrives |
#Two stored inputs, one answered on demand, and four outputs
Here a program reads two stored inputs, asks one input answered on demand, and names four output channels:
-- Orders: prices and quantities, their value, and a score for each, asked on demand.
price = input("price", i : 3)
qty = input("qty", i : 3)
amount = price * qty
scorer = input("scorer", n : inf)
score = scorer[n = amount]
output("prices") = price
output("quantities") = qty
output("amount") = amount
output("scores") = score
-- table price = i,value; 0,2.5; 1,4; 2,10
-- table qty = i,value; 0,4; 1,3; 2,1
-- service scorer: answers formula x1 / 10; takes 5 ms; deadline 50 ms
-- expect amount[i = 1] = 12
-- expect score[i = 1] = 1.2, at time 5 ms
-- expect output "prices" over i = 0..2
-- expect output "quantities" over i = 0..2
-- expect output "amount" over i = 0..2
-- expect output "scores" over i = 0..2
With "orders.csv": {"channels": ["prices", "quantities", "amount"]} and "scores": {"format": "jsonl"} in its outputs, elucid8 run writes orders.csv and scores.jsonl beside deploy.json.
#From the playground to a deployment
The playground's Download turns a saved program into a deployment, a folder that ./elucid8 run plan.json --config deploy.json runs with the playground's answers (Deploy tutorial):
- each table and formula becomes a CSV file in the folder
data, an entry ofinputsindeploy.json; - each input answered on demand becomes an entry of
inputswith its settings, a simulated program as"builtin": "simulated"; - each output channel's file, format and side-by-side layout, from its card, becomes an entry of
outputs, its file in the folderout(whichelucid8 runmakes).
Then swap what stands in for the real thing, one entry at a time: a file for the latest data, a program for a database or an API, a real program for the simulated one, a replay or a clock for data that should arrive over time, a database for an output file (Connecting eLucid8 to your data). The program does not change.
#Which to use when
| You have… | Use | For example |
|---|---|---|
| data that exists whether or not the program asks | a stored input | sensor readings, prices, purchases, the weather as observed |
| a value someone computes on request, at the point the program asks | an input answered on demand | a fraud score from an AI model, a translation, the weather forecast now, from an API |
| the same data, saved | a stored input | yesterday's forecasts, saved to a file, read again and versioned |
| data that keeps arriving | an input given rows over time, under elucid8 serve | readings sent by a sensor's script, a day's file replayed a row a second, a clock's ticks |
| a table with a column per field | a stored input read with "wide" | a spreadsheet's export, t,temperature,humidity |
| results to keep or pass on | an output (with "skip": "eod" to write only what there is, "wide" for a column per field) | a training table for a model, alerts into a database, a webhook for each change |
#Read on
- Connecting eLucid8 to your data: databases, APIs and streams as inputs, and as destinations.
- Data services: what every question does, and the data services there are.
- Command reference: every field of an output, outputs named in the program, and the formats.
- The long-running service: new data as it arrives, and subscriptions.
- Values and timestamps: what a value's timestamp is.