Skip to content

ports: cvc::param_table, a params struct declared once (P0b, part 1) - #1110

Merged
transfix merged 1 commit into
masterfrom
p0b/param-table
Nov 10, 2026
Merged

transfix merged 1 commit into
masterfrom
p0b/param-table

Conversation

@transfix

@transfix transfix commented Nov 9, 2026

Copy link
Copy Markdown
Owner

The first of the VolumeRover ports' shared pieces: phase P0b's parameter table (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.5, §7). Additive and non-breaking.

What it does

A params struct is declared once, as a constexpr table of its fields: name, member, unit, range and doc. An enum's choices come from BOOST_DESCRIBE_ENUM. Generic code then gives:

From the table Header
params_validate(p): a list of what is wrong (out of range, NaN, no such choice, the table's own check) cvc/core/param_table.h
params_to_state / params_from_state: one key per field. Missing keys are seeded with their defaults. A value that does not parse is reported, not replaced. Each key gets its properties (comment, doc, unit, min, max, choices, default, type, access) param_table.h
The CLI flags and their help (boost::program_options) cvc/core/param_cli.h
The DSL dict an intrinsic takes, and the app's registry behind (params.defaults name) / (params.check name dict) cvc/core/param_dsl.h
pycvc keywords (an unknown one raises TypeError naming the valid ones), validate(), from_state / to_state, from_dict / to_dict bindings/pycvc/pycvc_params.i
A Markdown table for a port's docs params_markdown()

Numbers are written in their shortest round-trip form, so struct → tree → struct is exact. The registry lives in the app's data map, so there is no process-wide table (§1.3).

compute_contour_tree's options get the first real table (cvc/volume/contour_tree_params.h). pycvc wraps them as pycvc.contour_tree_options(max_dim=64, quantize_u8=True).

Tests under node

src/cvc/tests/port_tests.cmake lists the ports' googletest binaries. -DCVC_BUILD_PORT_TESTS=ON builds only those, with CVC_BUILD_TESTS off. A new CI lane, ports (wasm-mt, node), modelled on physics replay (wasm-mt, node), builds them for wasm-mt and runs each one under node (§1.8, T14). googletest is built from source there, because the catalog has no wasm-mt googletest.

Tests

  • param_table_test, the T8 rows for the piece itself:

    • every field kind round-trips, bit for bit, through text, the tree, the CLI and the DSL;
    • defaults are seeded, properties written, and bad values named;
    • two apps keep their own registries.

    It runs natively, under node in the new lane, and in the sanitizer lanes (SAN_CXX_TESTS).

  • test_pycvc_params.py.

Checked locally on Windows (MSVC 2022, Release): param_table_test passes 20/20 and pycvc_params passes. clang-format 18 reports no changes.

What follows

  • Part 2: cvc::result_job<R>, the node-key publisher, the generic -start / -async / waiting intrinsic forms plus job.cancel, the T7 harness, and pycvc's result_job wrapper. Its tests join this lane.
  • Part 3: tools/volrover-goldens/.

The first of the VolumeRover ports' shared pieces (VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.5, §7
P0b). A params struct is declared once, as a constexpr table of its fields (name, member, unit,
range, doc; an enum's choices from BOOST_DESCRIBE_ENUM), and generic code gives:

- params_validate(): a list of what is wrong (range, NaN, choices, the table's own check);
- params_to_state / params_from_state: one key per field, missing keys seeded with their
  defaults, a value that does not parse reported (not replaced), and the properties written on
  each key (comment, doc, unit, min, max, choices, default, type, access);
- param_cli.h: the CLI flags and their help on boost::program_options;
- param_dsl.h: the DSL dict an intrinsic takes, and the app's registry of tables behind
  (params.defaults name) and (params.check name dict), held in the app's data map;
- pycvc_params.i: PYCVC_PARAM_TABLE, keywords (an unknown one raises TypeError naming the valid
  ones), validate(), from_state / to_state, from_dict / to_dict;
- params_markdown(): the table for a port's docs.

Numbers are written in their shortest round-trip form, so struct -> tree -> struct is exact.
compute_contour_tree's options get the first real table (contour_tree_params.h), which pycvc
wraps as contour_tree_options.

Tests: param_table_test (T8 for the piece itself: every field round-trips through text, the tree,
the CLI and the DSL; defaults seeded, properties written, bad values named; two apps keep their
own registries) and test_pycvc_params.py.

src/cvc/tests/port_tests.cmake lists the ports' googletest binaries. CVC_BUILD_PORT_TESTS builds
only those (with CVC_BUILD_TESTS off), and the new `ports (wasm-mt, node)` CI lane builds them for
wasm-mt and runs each under node (T14). param_table_test also joins the sanitizer lanes.
@transfix
transfix merged commit ed2e0d5 into master Nov 10, 2026
31 checks passed
@transfix
transfix deleted the p0b/param-table branch November 10, 2026 07:34
@transfix
transfix restored the p0b/param-table branch November 10, 2026 07:35
transfix added a commit that referenced this pull request Nov 10, 2026
#1110 merged as ed2e0d5, a squash of this branch's first commit (cc48acd). This merge's tree is
master plus this PR's own changes (cc48acd..49eb2cd), so the PR's diff against master is only
part 2. The conflicts were only where part 2's lines sit next to part 1's (ci.yml's sanitizer and
path-filter lines, port_tests.cmake, src/cvc/CMakeLists.txt, pycvc's CMakeLists.txt and
pycvc_contour_tree.i, docs/PORT_SHARED_PIECES.md).
transfix added a commit that referenced this pull request Nov 10, 2026
…rary (#1114), seabed damping (#1127)

One conflict, in ci.yml's sanitizer test list: this branch's stream_test,
net_ws_client_test and ariadne_host_test, and master's param_table_test, all
kept.
@transfix
transfix deleted the p0b/param-table branch November 10, 2026 07:43
transfix added a commit that referenced this pull request Nov 10, 2026
Changing a PR's base doesn't start the pull_request workflow, and this branch's last push came
while its base was #1110's branch, which CI/CD skips. This empty commit starts it.
transfix added a commit that referenced this pull request Nov 11, 2026
…obs (P0b, part 2) (#1113)

* ports: cvc::param_table, a params struct declared once (P0b, part 1)

The first of the VolumeRover ports' shared pieces (VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.5, §7
P0b). A params struct is declared once, as a constexpr table of its fields (name, member, unit,
range, doc; an enum's choices from BOOST_DESCRIBE_ENUM), and generic code gives:

- params_validate(): a list of what is wrong (range, NaN, choices, the table's own check);
- params_to_state / params_from_state: one key per field, missing keys seeded with their
  defaults, a value that does not parse reported (not replaced), and the properties written on
  each key (comment, doc, unit, min, max, choices, default, type, access);
- param_cli.h: the CLI flags and their help on boost::program_options;
- param_dsl.h: the DSL dict an intrinsic takes, and the app's registry of tables behind
  (params.defaults name) and (params.check name dict), held in the app's data map;
- pycvc_params.i: PYCVC_PARAM_TABLE, keywords (an unknown one raises TypeError naming the valid
  ones), validate(), from_state / to_state, from_dict / to_dict;
- params_markdown(): the table for a port's docs.

Numbers are written in their shortest round-trip form, so struct -> tree -> struct is exact.
compute_contour_tree's options get the first real table (contour_tree_params.h), which pycvc
wraps as contour_tree_options.

Tests: param_table_test (T8 for the piece itself: every field round-trips through text, the tree,
the CLI and the DSL; defaults seeded, properties written, bad values named; two apps keep their
own registries) and test_pycvc_params.py.

src/cvc/tests/port_tests.cmake lists the ports' googletest binaries. CVC_BUILD_PORT_TESTS builds
only those (with CVC_BUILD_TESTS off), and the new `ports (wasm-mt, node)` CI lane builds them for
wasm-mt and runs each under node (T14). param_table_test also joins the sanitizer lanes.

* ports: result_job, node keys, generic intrinsics, T7 harness, pycvc jobs (P0b, part 2)

The VolumeRover ports' job pieces (VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.4, §1.6, §1.9, §7 P0b),
proved on libcvc's own steppers, since no port exists yet.

- cvc::result_job<R> (cvc/core/result_job.h): any resumable stepper as a sliced_job that owns its
  result. step(budget) takes the result and destroys the stepper once done; cancel() from any
  thread ends it at the next step with nothing; a throwing step fails the job (status "failed:
  <message>", result() rethrows); phase/progress/status for UIs; step timings. make_result_job
  takes the stepper by value or unique_ptr, with take() or a taker. cvc/volume/volume_jobs.h:
  contour_tree_job and resize_job.
- cvc::job_keys and schedule_published_job (cvc/core/job_keys.h): fe_lab's node keys (busy,
  stoppable, status, progress 0-100, phase "<phase> 42%", stats.work_ms, pid) published from a
  task's hooks. fe_lab now writes its job keys through it (its own WorkTimer still times
  stats.work_ms). sliced_task gains on_cancelled (a job stopped through its own cancel()) and
  stop_sliced_job (safe from another process's step).
- cvc/core/job_intrinsics.h: a port registers an op from its stepper factory and parameter table
  and gets (<op> ...) (parks on the task), (<op>-async ...) (a future), (<op>-start ... target)
  (the pid at once; keys under target, the result at target.result), plus (job.cancel pid) and
  params.defaults / params.check. Tasks carry the caller's owner tag; killing the caller or the
  task cancels the job.
- The T7 harness (src/cvc/tests/resumable_harness.h): budgets 1, 64, seeded random and 0 against
  the blocking result bit for bit; monotone progress and named phases; a cancel in each phase
  leaves no result and destroys the stepper; the slowest step at the default budget and the
  stepping overhead recorded; a cooperative frame-time run on an app's scheduler.
- pycvc_jobs.i: PYCVC_RESULT_JOB wraps result_job<R> generically (step, done, cancel, progress,
  phase, status, result, take_result, run), with the GIL released inside each step;
  pycvc.contour_tree_job, pycvc.resize_job, pycvc.compute_contour_tree and the tree.

Tests: result_job_test (the job on fake steppers; T7 on contour_tree_builder, resize_stepper and,
with libigl, fem::stepped_solve; the node keys cooperative and threaded) and job_intrinsics_test
(T10: each form cooperative and threaded, bad parameters and inputs, failures, job.cancel, kills,
owner tags, and an Ariadne button's on: action starting a job with -start under the default action
limits while its progress keys rise frame by frame). Both join the ports (wasm-mt, node) lane and
the sanitizer lanes; test_pycvc_jobs.py joins pycvc's.

* fem: stepped_solve's step(0) runs to the end, as fem.h says

The T7 harness's fem::stepped_solve case (result_job_test, built where libigl is) found that a
budget-0 step returned three times before the solve was done. fem.h, like every stepper's
contract, says budget 0 runs to the end. The builder and the factorization stages spend whatever
budget they are handed, so even an unbounded budget ended run() after each of them. With budget 0,
step() now calls run() until the solve is done. A budgeted step is unchanged, and so are its
results: the harness's bit-for-bit comparisons across budgets 1, 64, random and 0 already passed.

* ci: run CI/CD on #1113 now that it targets master

Changing a PR's base doesn't start the pull_request workflow, and this branch's last push came
while its base was #1110's branch, which CI/CD skips. This empty commit starts it.

* pycvc: a job's result() is Python's own copy

The clang-tsan lane found a heap-use-after-free in test_pycvc_jobs.py. result() returned a
reference into the job, so `pycvc.contour_tree_job(vol).run()`, which drops its job at once, left
the tree pointing at freed memory (dims_list, nodes.__len__). A reference would dangle the same way
once the result is taken. pycvc_jobs.i now declares result() by value, so SWIG copies it and Python
owns the copy; take_result() still moves it out. New test: a result outlives its job and a take.

* pycvc: a tree's nodes and arcs are copies; port tests link -sFETCH

Two failures at 55da976:

- clang-tsan: test_pycvc_jobs.py still read freed memory. tree.nodes was a view into the tree that
  does not keep the tree alive, so len(pycvc.compute_contour_tree(vol).nodes) read it after the
  temporary tree was collected. %naturalvar makes nodes and arcs copies Python owns. The test now
  checks that nodes outlive their tree.
- ports (wasm-mt, node): job_intrinsics_test reaches Ariadne, which links cvc::net's fetch backend,
  and an executable must add -sFETCH=1 for it (src/cvc/CMakeLists.txt). The port tests now link
  with it.

* pycvc: a tree's nodes and arcs are copies by value; tsan lanes run one OpenMP thread

%naturalvar left tree.nodes a view into the tree (the sanitizers caught
len(pycvc.compute_contour_tree(vol).nodes) reading the freed tree):
nodes and arcs are now properties over getters that return the vectors
by value, which Python owns.

The tsan lanes configure CVC_ENABLE_OPENMP=OFF, yet voxels.cpp's
parallel regions arrive compiled with -fopenmp; libgomp is not built
with TSan, so result_job_test's ResizeStepper reference (voxels::resize)
reported the main thread racing its workers. run.sh sets
OMP_NUM_THREADS=1 for tsan and clang-tsan.

* cvc: no OpenMP from ImageMagick's flags; parallel voxel writers detach once

ImageMagick's own build flags no longer turn OpenMP on. CMake's
FindImageMagick copies pkg-config's CFLAGS_OTHER into the
ImageMagick::* targets' INTERFACE_COMPILE_OPTIONS, and cvcpkg's Linux
ImageMagick (built with configure's default OpenMP) lists -fopenmp
there. Linked PUBLIC, it compiled every cvc source with OpenMP whatever
CVC_ENABLE_OPENMP said, so the sanitizer lanes' OFF still built
voxels.cpp's parallel regions, run on a libgomp TSan cannot see into.
src/cvc/CMakeLists.txt drops the OpenMP flags (with an -Xpreprocessor or
-Xclang that introduces one) from those targets. The previous commit's
OMP_NUM_THREADS=1 in .github/sanitizers/run.sh goes again.

The parallel writers that still wrote through operator(), and so called
preWrite() on every voxel from every thread, now detach the buffer and
dirty the histogram once before the region and write with setValueRaw,
as fillsub and map do: resizeTrilinearCPU (newvox), composite (whose
threads raced to detach a shared buffer) and anisotropicDiffusion
(tempt). preWrite() writes the histogram flag only when it is clean, so
gdtvFilter's gradient (a fresh voxels, already dirty) is written in
parallel without a race on it.
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