Skip to content

pycvc_gl.ariadne: a Python host for Ariadne documents - #985

Merged
transfix merged 12 commits into
masterfrom
feat/pycvc-gl-ariadne-host
Nov 5, 2026
Merged

transfix merged 12 commits into
masterfrom
feat/pycvc-gl-ariadne-host

Conversation

@transfix

@transfix transfix commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

A Python program can now host an Ariadne document: open it (in a window, offscreen, or headless with no GL), have the document call Python functions with arguments and get values back, push values, tables, series, pictures and streams into it, and read back what it produces. pycvc_gl.ariadne.Host is the API; four examples in examples/ariadne/python show it to the Python team; docs/ARIADNE.md §9.3 is now "Writing a Python host".

What it adds

C++

  • AppRuntime::register_function(name, native_fn) and register_async_function(name, marshal, done_channel): host functions with arguments and a value. The old register_verb / register_async_verb took none and returned a string. Also AppRuntime::run_program(script, done).
  • AriRuntime forwards those and adds publish_image, enable_streaming (the stream verbs and stream_view), prefix, has_function, register_quit / exit_code and wait_idle. frame(), render(), step() and run() throw std::logic_error when called from inside a frame (from a handler or a function the frame is running).

pycvc

  • pycvc.host_function(name, fn, is_async=False, with_call=False, done_channel="") builds a host function from a Python callable. It is built in pycvc, where the value conversion lives, and pycvc_gl takes it through SWIG's type table.
  • pycvc.AriApp: a GL-free host, an AppRuntime with no backend and no scene, for tests and CI.
  • pycvc.nav_world_rasterize(world, rows, cols, bounds, inflate): cvc::nav's planning grid (occupancy and terrain height) from a city bundle's world, with no VTK.
  • pycvc.nav_plant(..., ground=field): on terrain that isn't flat, each vehicle starts on the ground under it (nav_plant_options::ground_height). Before, every vehicle started at ground_z, inside raised terrain.

pycvc_gl

  • pycvc_gl.ariadne.Host:
    • modes window / offscreen / headless;
    • on, function, async_function, on_frame, watch, emit;
    • set / set_tree / set_table / set_series / publish_image / open_stream / run_program;
    • get* / get_tree / get_series / snapshot / frame_rgb;
    • run, step, settle and close;
    • host.lab over the document's scene, plus frame_bounds.
  • pycvc_gl.scenes.find_scene / find_vehicle_model find the installed scene bundle and vehicle model.
  • pycvc_gl.vehicle.VehicleModel makes a glTF vehicle +X-forward and +Z-up at true scale, as the C++ demos' load_vehicle_template does. seat_transform and body_transform place it.

The GIL, both ways

  • A frame runs the document's programs, and they call Python: a handler or a function on this thread, an async function on a pool thread. So these release the GIL, and each Python call takes it back:
    • AriRuntime's frame / render / step / run / load / wait_idle and its destructor;
    • AriApp's;
    • cvc::app's destructor.
  • Before, run() held the GIL, so an async Python function waited for it forever.
  • del app with a Python call in flight deadlocked: reproduced (no exit in 30 s), now done in 0.5 s. ~app waits for the app's async calls.
  • Re-entry is refused: step() / run() from a callback raises RuntimeError, and load() from one waits for the frame to end.
  • test_pycvc_gl_ariadne_gil.py runs each case in its own process with a timeout, so a deadlock fails the test instead of hanging it:
    • run() with an async function;
    • the old async verb;
    • re-entry;
    • another Python thread writing state;
    • state writes from the pool;
    • close() and dropping everything with a call in flight, headless and GL.

Examples (examples/ariadne/python)

Example Mirrors Shows
hello.py ariadne_hello a button calls (greet NAME) in Python, another raises an event Python handles, and Python writes the document every frame
data_feed.py ariadne_stream two plotted series, a table (repeat:), a numpy picture and a live video stream pushed from Python; the document's controls read back
form.py nav_compute a function returns a dict the document writes with state-set-tree; an async Monte Carlo runs while the UI keeps drawing; a watch recomputes a preview
nav.py nav_convoy, nav_city_drive Humvees at true scale on a sim_world through Austin (a block city when the bundle isn't installed), following routes planned for their turning radius, on Jolt or nav's kinematic bicycle (a combo), chase or overview camera, map picture
  • The nav document uses terrain_lab's soft afternoon look: a pale sky, a low warm three-point sun, and shadows that follow the camera with softness: 3.
  • The navigator gets the grade (nav_sim_world_set_terrain with the Humvee's terrain_config_of), and routes keep off the slopes nav_terrain_build marks infeasible.
  • Jolt runs on flat ground with the buildings as boxes, as the C++ city demos do. --relief puts it on the real terrain and building mesh.
  • Every example declares what it needs in requires: (AriadneComponents.ShippedExamplesDeclareWhatTheyNeed). nav.ari has a scene:, so it requires gl.scene and nav.py has no headless run: it runs in a window or --offscreen.

Tests

New:

  • pycvc_ariadne (29 checks, no GL);
  • pycvc_gl_ariadne_host (46 headless checks, plus 17 offscreen including all four examples, nav on both Jolt and kinematic);
  • pycvc_gl_ariadne_gil (8 cases);
  • nav_world_rasterize in test_pycvc_world_geometry.py;
  • nav_plant(ground=) in test_pycvc_nav_routes.py;
  • AriadneHostVerbs.AFunctionTakesArgumentsAndReturnsAValue and .AnAsyncFunctionTakesArgumentsAndPostsToItsChannel.

Locally, Windows, MSVC 14.44 with the cvcpkg prefixes:

  • all 53 bindings/pycvc/test_pycvc*.py scripts pass;
  • ariadne_host_test: 44 passed, 11 skipped (no FTXUI here);
  • ariadne_loader_test: 214 passed, 2 skipped ("built without yaml-cpp or json-schema-validator").

The GL halves skip without a GL context unless CVC_REQUIRE_RENDER=1, which pycvc-linux sets under Xvfb.

Findings

  • Ariadne's per-action caps (0.1 s, 5000 steps) stop any slow Python call (did not complete: time_limit_exceeded). An async call's CPU time counts as steps at 8000 per ms. Host raises the caps by default (limits= overrides) and the docs say why.
  • sim_world's kinematic park doesn't hold an agent at its goal: reached turns true, then the agent rolls on past it. nav.py sends each arrival a new route instead.
  • On Austin's relief with Jolt (--relief), the grade term halves the rollovers: 8 of 16 Humvees in 96 s without it, 4 with it. The rest roll in open ground on 10-25 degree side slopes at 5-9 m/s. The grade limit is the climb, not cornering on a side slope.
  • GRL-SNAM's live Austin demos import pycvc_gl.scenes.terrain_grid, which this tree has retired. Its Ariadne ports PR fixes them.

Not done

  • CI hasn't run yet.
  • No wasm build of the new pieces was tried.

Host functions with arguments and a value (AppRuntime::register_function / register_async_function; pycvc.host_function from Python), a GL-free host (pycvc.AriApp), and pycvc_gl.ariadne.Host over AriRuntime or AriApp: data in (values, trees, tables, series, pictures, streams), data out (get, watch, frames), and the document's calls into Python.

The GIL: AriRuntime's frame/render/step/run/load/wait_idle and its destructor, AriApp's, and cvc::app's destructor release it, so an async Python function finishes while frames run, under run(), and at teardown (del app with a call in flight deadlocked). A frame entered from inside one raises.

Examples (hello, data_feed, form, nav) in examples/ariadne/python, tests pycvc_ariadne, pycvc_gl_ariadne_host and pycvc_gl_ariadne_gil, and docs/ARIADNE.md 9.3 Writing a Python host.
…t-function C++ tests

examples/ariadne/python/nav.py drives Humvees on a sim_world through Austin when its bundle is installed (a block city otherwise): true-scale models, routes planned for their turning radius, Jolt or kinematic plant, chase or overview camera, map picture, terrain_lab's soft afternoon look.

pycvc.nav_world_rasterize (cvc::nav::rasterize, no VTK), nav_plant(ground=field), pycvc_gl.scenes.find_scene / find_vehicle_model, pycvc_gl.vehicle.VehicleModel / seat_transform / body_transform. AriadneHostVerbs tests for register_function and register_async_function.
The terrain's height at each grid sample (nav_world_rasterize) goes to the navigator with the Humvee's terrain_config_of (nav_sim_world_set_terrain), and the routes keep off the slopes nav_terrain_build marks infeasible. On Austin's relief (--relief) that halves the Jolt rollovers (8 -> 4 of 16 in 96 s); the rest are cornering on 10-25 degree side slopes at 5-9 m/s, which the climb limit does not cover, so flat-ground physics stays the default.
…res:)

AriadneComponents.ShippedExamplesDeclareWhatTheyNeed failed on every CI
platform: python/data_feed.ari and python/nav.ari had no requires: block,
and nav.ari has a scene: without requiring gl.scene.

data_feed.ari requires quit, with stream_view and raster.bitmap optional
(a headless run shows text). nav.ari requires gl.scene and quit, so, like
every shipped document with a scene, a host without a scene refuses it:
nav.py --headless now says so instead of running, and its headless
branches are gone. The host test's nav runs (kinematic and Jolt) move to
the offscreen section, which CI runs on llvmpipe under Xvfb, and the
headless section checks the refusal.
transfix added a commit that referenced this pull request Nov 3, 2026
* docs: roadmap for Ariadne scripting hosts (ari-py, arigl-py, arisrv-py)

Host variants that embed CPython with pycvc, pycvc_gl and numpy, natively and in one wasm
module: what already exists (static CPython/numpy/vtk-python/pycvc_gl for wasm, the Python
host in #985, VolRover3's embedded interpreter), the naming, the engine and host module, a
python: block for documents with a trust rule, the arigl-py-web link and its risks, server
documents and sandboxed client scripts on arisrv (RestrictedPython in worker processes),
and where Lua fits later. Design only; nothing is built.

* docs: name the scripting hosts arix, ariglx, arisrvx and ariglx-web

The x marks the extended host (the stock runtime plus its scripting engines), so a Lua engine
can join the same binaries without the names going stale. Lua's hosting now lands in the x hosts
beside Python; the stock hosts stay a separate decision.
…OS CI)

AnAsyncFunctionTakesArgumentsAndPostsToItsChannel failed on package-macos / libcvc-release: the
call's wait is charged to the action (ariadne.limits.action_max_time, 0.1 s by default), and on the
loaded macOS runner starting the kernel and its 20 ms took longer, so the program was stopped
(time_limit_exceeded) before it set got or posted to the channel. Reproduced here with the cap set
to 0.5 ms (the same failure, and run_program's done says time_limit_exceeded). The test is about the
arguments and the channel, so it sets the cap a host gives (30 s) and checks the program finished.
…ne-host

# Conflicts:
#	src/cvcGL/ariadne/AriRuntime.cpp
* Ariadne: arix and ariglx, ari and arigl with an embedded Python

The first part of the scripting hosts (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md, P1), native:

- src/ariadne_python: the engine. One CPython per process, booted from the install prefix's
  python312 (else the Python built against), the GIL parked between crossings. The _arihost
  builtin lends Python the host's app, document runtime and (ariglx) window objects.
- A document's python: block runs at load, before requires: is checked; its @export functions
  (and export: entries) become host functions through pycvc.host_function. The python and
  python.<module> capability tokens hold there; a stock host names the scripting hosts instead.
- A Python program in place of the document (arix|ariglx run|snapshot|check app.py):
  pycvc_gl.ariadne.Host() adopts the host (mode "embedded"), and host.run() runs the host's own
  loop. <host> python [args] is the embedded interpreter as a plain python3. --python-path DIR.
- AppRuntime::add_load_hook and add_frame_hook; pycvc.ari_app_attach; pycvc_gl's
  *_from_capsule proxies over a host's window objects.
- ctest: arix_python_* (block, program, error, interpreter), ari_python_needs_arix,
  ariglx_python_check / _program; three AriadneRequires cases. pycvc-linux builds and runs them.

* cvcpkg: arix and ariglx recipes, published from the cp312 Linux job

The scripting hosts as cvcpkg packages of their own, so ari and arigl stay Python-free. Each
recipe builds src/ari or src/arigl standalone with -DARI_WITH_PYTHON / -DARIGL_WITH_PYTHON
against the installed SDKs and the deps prefix's python312 (named outright, not a system
python3), and installs only its own binary. Runtime deps bring python312, numpy-cp312,
pycvc-cp312 (and for ariglx pycvc-gl-cp312) into the same prefix, where the installed host
finds its Python beside it. Linux only, where pycvc-cp312 and pycvc-gl-cp312 are published.

A recipe build no longer compiles in the build's Python home (CVC_ARIADNE_PYTHON_HOME is
in-tree only), so no builder path ships.

publish-cvcpkg.yml builds, smoke-tests, packs and publishes both in the cp312 job: arix runs
`arix python` and the python: block test document through that job's pycvc; ariglx, last,
loads it and renders the Python program's document under Xvfb.

* publish-cvcpkg: PYTHONHOME for arix and ariglx alone, not the cvcpkg that packs them

The dry run (41598099932) built both and both passed their smoke tests on Linux (arix: its
interpreter and python_block.ari 5/5; ariglx: the python: block in a window and app.py rendered),
then cvcpkg pack died with "No module named 'cvcpkg'": the exported PYTHONHOME pointed cvcpkg's
own Python at $PY's stdlib. The hosts now get it through env, one command at a time.
…ne-host

# Conflicts:
#	.github/workflows/publish-cvcpkg.yml
#	bindings/pycvc/pycvc_physics.i
#	src/ari/main.cpp
#	src/arigl/main.cpp
@transfix
transfix merged commit d0bb057 into master Nov 5, 2026
27 checks passed
@transfix
transfix deleted the feat/pycvc-gl-ariadne-host branch November 5, 2026 21:11
transfix added a commit that referenced this pull request Nov 6, 2026
Bumps the project version and every recipe's upstream_version from 3.7.10 to 3.7.11, arix and
ariglx included. The v3.7.11 tag on this commit is the first release with the Python host
(#985) and the Ariadne data store (#998), and the first that publishes arix and ariglx.
transfix added a commit that referenced this pull request Nov 6, 2026
…1028)

* docs: scripting-hosts roadmap says what P1 shipped (#985, v3.7.11)

The roadmap predates P1. It now describes what #985 shipped and marks
what didn't:

- 3.1: the engine is src/ariadne_python, compiled into each x host by
  cvc_ariadne_python_host (ARI_WITH_PYTHON / ARIGL_WITH_PYTHON, or
  CVC_BUILD_PYCVC in-tree), not a cvc_ari_python library; Engine's real
  config and home rules; _arihost's functions; no py-eval / py-exec and
  no script_engine interface yet (the token registry and the load and
  frame hooks are P1's seams).
- 3.2: an explicit mode inside an x host opens a separate Host rather than
  raising; run()'s two forms.
- 4.1-4.5: python.<module> is the one module token (python.vtkmodules, not
  python.vtk); ari info lists tokens; the block runs on every load, before
  requires:; its keys and export forms; caps raised for every document;
  load:ed modules' blocks, --python-allow and run -m are planned (P1b);
  the console is P2.
- 9, 10: risks 4 and 6 updated; P0 and P1 done, the rest of P1 is a new
  P1b row, which L1 and G1 now need for the script_engine interface.

* docs: scripting-hosts roadmap review fixes (configure error, arix's closure, find_spec)

- An explicit -DARI_WITH_PYTHON=ON / -DARIGL_WITH_PYTHON=ON makes a
  missing Python Development.Embed a configure error; only in-tree is the
  target skipped.
- arix links libcvc and libpython only, and a Python program under arix
  needs pycvc-gl-cp312 for Host; ariglx links libcvcGL too.
- python.<module>: find_spec imports a dotted module's parent package.
transfix added a commit that referenced this pull request Nov 6, 2026
…1026)

New section 6.5 covers what a service such as cy-pca/cyprov needs from one
arisrvx process:
- an asyncio loop on the script thread;
- serve_asgi for FastAPI/uvicorn, with lifespan and graceful shutdown;
- server-published namespaces;
- an authenticate hook that yields principals, and per-principal read scopes;
- room-call with ctx (principal, progress, idempotency, deadline), role gates
  and CallError;
- a relay join mode for ari and the x hosts, plus native transport security;
- a ServerHarness for plain-python tests.

Phases S0-S2 gain these parts, S5-S7 are new, and the application-services
cut S0-S2 + S5 + S7 is called out. Risks 16-19 are new. The status line now
records that P0/P1 landed in #985.
transfix added a commit that referenced this pull request Nov 14, 2026
…_gl (#1216)

A Python program run in place of the document (arix run app.py) adopts
the host with Host(), which lived in pycvc_gl.ariadne (#985). Under arix
the Host never draws: with no GL it drives the host's own runtime through
core pycvc (pycvc.ari_app_attach), as a headless Host drives pycvc.AriApp.
But the import ran pycvc_gl's __init__, which loads the native _pycvc_gl
(cvcGL and VTK). So the arix recipe told programs to install
pycvc-gl-cp312 beside it, and ctest arix_python_program failed in any
tree built without pycvc_gl.

The module moves to core pycvc as pycvc.ari (bindings/pycvc/pymod/ari.py).
It is installed beside pycvc.py as _pycvc_ari.py, the way pycvc.ariadne is.
pycvc.ariadne stays arisrvx's server Host.

- pycvc imports it as pycvc.ari. pycvc-cp312's `_pycvc*` files already
  cover it.
- A window or offscreen Host, host.lab, and an embedded Host in ariglx
  import pycvc_gl when they need it. If it is missing, the ImportError
  says to install pycvc-gl-cp312 or use mode="headless".
- pycvc_gl.ariadne is the same module, not a copy. Importing it puts
  pycvc.ari in its place, so `pycvc_gl.ariadne is pycvc.ari`, and
  existing imports get the same Host, current_host() and export.
- The browser's python312.zip and the pycvc-gl wasm host (link-host.sh)
  ship _pycvc_ari.py beside pycvc.py, since pycvc_gl.ariadne needs it.
- The arix test program, the examples, ari's and ariglx's help, the
  recipes and ARIADNE.md 9.3 and 9.6 name pycvc.ari. The logger is
  pycvc.ari.

Tests:
- pycvc_ariadne runs a document under a headless pycvc.ari.Host and
  checks pycvc_gl is never imported.
- pycvc_gl_ariadne_host checks the alias.
- arix_python_program passes with CVC_BUILD_PYCVC_GL=OFF.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant