Skip to main content

rupaka

rupaka (रूपक) means a form, a play that the audience sees, and the figure of speech that shows one thing through another. A rupaka demo is one interactive figure that teaches one idea. The learner changes the inputs and sees the result change.

A demo never shows the answer first. Each demo follows one loop:

  1. Predict. The demo shows the inputs and asks one question. The result is hidden.
  2. Reveal. The learner locks in with ⌘↩. The demo shows the result and says if the prediction was right.
  3. Manipulate. Now the controls are live. The result changes when the inputs change.
  4. Explain. The caption ends with a new question that the learner answers with the controls.

The validator enforces step 1: a block that shows a value which the answer depends on must wait for the gate.

What a demo is

A demo is a JSON spec, not code. It has a small state, derived values from named functions (fns), and a list of blocks. A model can write a spec safely, because a spec cannot run code.

part what it is
block a reusable UI part in rupaka/blocks/<name>/: its JS, its CSS, a block.json manifest and an example
fn a pure function that computes a derived value: rules, rrf, softmax, lookup, expr, ids, pick, sort, fmt
gate the block that asks for the prediction and hides the result until the lock in
spec the JSON object: state, derive, blocks and tables

The blocks are gate, readout, caption, row, stack, slider, toggle, choice, wheel, ranklist, bars, axis, point, plot and grid.

Install

pip install rupaka

The headless check needs playwright: pip install "rupaka[check]". It uses the Chromium that playwright install chromium gives, or the browser in $FASTCDP_CHROME. It never runs your everyday Chrome.

How to use

Build a spec with the builders, or write the JSON.

from rupaka.spec import *
d = demo('sum', 'A sum', ask='Predict the sum before you see it.', state=dict(a=2, b=3), derive=[expr('a + b', 'sum')],
         blocks=[gate('s', 'What is {a} + {b}?', [4, 5, 6], 'sum', why='Say why, in one line.'),
                 readout('{a} + {b} = {sum}', after='s')])

validate returns the errors. An empty list means the spec is good.

assert validate(d) == []

A readout that shows the sum before the gate breaks the think rule:

bad = {**d, 'blocks': [d['blocks'][0], readout('{a} + {b} = {sum}')]}
validate(bad)

Then put the demo where the learner is:

where how
a notebook (leela, Jupyter) show(spec): an HTML output in a sandboxed frame, and the application/vnd.rupaka+json mime
Markdown md(spec) writes a ```rupaka fence; md(spec, frame=True) writes a frame that leela draws today
a FastHTML page Demo(spec) and Assets('/rupaka'); serve bundle('js') and bundle('css') at that prefix
a file save(spec, 'demo.html') writes one page that works from file:// with no network

check(spec) draws the demo in headless Chrome and plays it. author(concept, ask) asks a model for a demo, and checks and repairs it.

The host API

A host page can read and change a demo that it mounted. In these calls, el is the element that holds the demo: the [data-rupaka] element, or the element that you gave to Rupaka.mount.

call what it does
Rupaka.state(el) gives a copy of the input keys (the keys of spec.state) and their values
Rupaka.set(el, state) sets the input keys that state has, then runs derive one time and draws one time. It ignores other keys.
Rupaka.options(el, gate) gives the option values of the gate gate, in the order that the gate shows them. Each value is the value itself, not the text that the gate shows. The gate reads options from the state after derive, and this call does the same. An unknown gate gives null.
Rupaka.settle(el, gate, pick, {answer}) closes the gate gate as if the learner picked pick. It draws the verdict and shows the blocks that wait for the gate. With pick null, the gate closes with no verdict. An unknown gate does nothing and gives false. The options object is optional.
Rupaka.open(el, gate) opens the closed gate gate again, as the Try another button of the gate does. It removes the pick, the reason and the verdict, and hides the blocks that wait for the gate. It draws one time. It does not move the focus. A gate that is open does not change, and the call gives true. A gate that waits for the host to save a prediction does not open, and the call gives false. An unknown gate does nothing and gives false.
Rupaka.mount(el, spec, {save}) calls save(state) after each change of an input key. state is the value that Rupaka.state(el) gives.

Rupaka.set, Rupaka.settle and Rupaka.open never send rk-predict, never add to st.log and never call save. Rupaka.options only reads. A lock does not stop Rupaka.set. Each call throws an error when no demo is mounted in el.

To show one demo in two windows, mount the spec in each window. Send Rupaka.state of the first copy to the second window, and call Rupaka.set there. To send a pick, send its index in Rupaka.options of the first copy. In the second window, find the value at that index in Rupaka.options, and call Rupaka.settle with it. When the learner in the first window clicks Try another, call Rupaka.open in the second window.

A host can remove the gate answers from the spec of a copy that a room sees, so that the room cannot read them early. Then give the answer to Rupaka.settle in answer. The gate uses it to draw the verdict. answer is {is: value} or a path in the state, as in a gate. When the spec has an answer, the gate uses the answer in the spec. Rupaka does not write answer into the spec or the state. When the spec has no answer and you give no answer, the gate closes with no verdict.

rupaka.poll makes a question for a room from a gate. of_gate(spec, gate) gives the question and the index of the answer. public(p) gives the part that the room sees.

rupaka/demos/ holds hand-made demos: vowel sandhi, reciprocal rank fusion, softmax and temperature, nakṣatra and pāda, and a parabola.

Develop

The notebooks in nbs/ are the source of the Python. The JS and CSS are hand-written files under rupaka/static/, rupaka/blocks/ and rupaka/fns/.

uv sync
uv run nbdev-prepare
uv run pytest

Metadata

Release files for rupaka 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rupaka 0.0.6
File Size Uploaded Provenance Actions
rupaka-0.0.6.tar.gz 293.9 kB Without provenance Details for rupaka-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rupaka 0.0.6
File Interpreter ABI Platform Actions
rupaka-0.0.6-py3-none-any.whl Python 3 none any Details for rupaka-0.0.6-py3-none-any.whl

Total release size: 615.9 kB

Release files / rupaka-0.0.6.tar.gz

Download URL rupaka-0.0.6.tar.gz
Size 293.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e6b4498a8b8ddd9dcec2df20ece56d4cc4dde26164703d70f7ce485754fa10bf
BLAKE2b-256 checksum
How to use checksums
9622378d832be8bab97982a96df7ae6310b087a2b6547b698b4d6cbcd06c58a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / rupaka-0.0.6-py3-none-any.whl

Download URL rupaka-0.0.6-py3-none-any.whl
Size 322.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12bfaae4f9e9f3359c66c054b1af0e6feae534b1dfe364660d14a49fb790207d
BLAKE2b-256 checksum
How to use checksums
4fde5206d74f85b0eff695bcab874e4120f2ea793e69a20f9058057c059482f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for rupaka 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page