Repository navigation
cvc::ph composition: compositional port-Hamiltonian systems (C-PHAST, Phase 1) - #1227
Merged
Merged
Conversation
Port-Hamiltonian components joined by power-preserving ports: block laws with typed ports (linear_law; canonical_law with optional MLP potential, mass and damping), the skew pairing from explicit pairs, an incidence matrix or a dense rule, the composed field and power terms, a split transition (Euler or midpoint coupling) with whole-field RK4 and implicit-midpoint references, per-step energy books in dyn_ph_books, cvc-ph-law/1 and cvc-ph-system/1 files, cvc ph info|simulate|check, and pycvc ph_composite. The method is C-PHAST, by Shubham Bhardwaj and Chandrajit Bajaj.
docs/roadmap/PH-COMPOSE-ROADMAP.md maps the composition to the C-PHAST paper (Shubham Bhardwaj and Chandrajit Bajaj) and plans phases 2-5. src/cvc/tools/cphast_fixtures.py runs phast's own torch modules in float64 (it imports phast and copies none of it) and writes tests/data/ph_compose_golden.json; ph_compose_parity_test replays its four microgrids to rounding (3.1e-15 to 6.7e-15 over 200 steps). This port of C-PHAST needs Shubham Bhardwaj's and UT CVC-Lab's permission to license it LGPL-2.1 before it merges.
This was referenced Nov 15, 2026
…asured (#1242) ph_convoy_test builds a convoy's formation linkage as a cvc::ph composite: followers as point-mass canonical blocks, links as linear storage blocks wired by connect_incidence. It compares that formation with slot chasing and with the same links pulling one way, on a speed step and an emergency stop, for a column and a wedge, and checks the composite against an RK4 of the same equations. docs/roadmap/PH-CONVOY-FORMATION.md has the numbers. The pairing keeps errors bounded at any column length and any gains. It loses on peak error, settling, overshoot and closest approach, both to slot chasing and to the one-way links with the same information. So convoys are no reason for Phase 5's state-dependent port maps. It also records a limit of the split step: a flow source fed to a line through its input lets the line's state creep from the geometry at a steady state. The composite is therefore written in the lead's frame.
This was referenced Nov 15, 2026
# Conflicts: # src/cvc-cli/main.cpp
Owner
Author
|
Merging on Joe's OK (2026-11-15: "Merge anyway"). The authors' LGPL-2.1 permission (Shubham Bhardwaj; Dr. Bajaj / UT CVC-Lab) is still pending: record it on this PR when it arrives. |
transfix
added a commit
that referenced
this pull request
Nov 16, 2026
…#1253, #1255, #1256, #1264, #1268, #1271, #1273, #1277) - ci.yml: the sanitizer list keeps this branch's tests (stream_test, net_ws_client_test, ariadne_host_test) and master's segmentation_intrinsics_test. - STATE_EXEC_THREADED.md: the room-call verbs (room-run is #1273's) and #1252's segment.seeded provider in the provider table, both registered without a kind. room-call's async functions stay on the app's host: a reply settles on the relay client's reader thread through host.finish, so moving them to *ictx.host needs a finisher first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of porting C-PHAST into libcvc. It is two commits: the core (library, CLI, pycvc,
docs/PH_COMPOSE.md, self-contained tests), which can stand alone, then the parity layer (the plan, the phast fixture script, its golden file,ph_compose_parity_test). The plan isdocs/roadmap/PH-COMPOSE-ROADMAP.md. This PR adds acvc::phcomposition layer: port-Hamiltonian components joined by power-preserving ports, the composed field, the paper's split transition with per-step energy books, parity with CVC-Lab/phast, pycvc bindings andcvc phsubcommands.Licence: merged on Joe's OK with the authors' permission still pending
docs/roadmap/PH-COMPOSE-ROADMAP.md,docs/PH_COMPOSE.md, the header ofinc/cvc/ph/compose.hand the pycvc binding all credit Shubham Bhardwaj and the C-PHAST paper.What it adds
inc/cvc/ph/compose.h,src/cvc/ph/compose.cppblock_lawenergy,effort(∇H),structure(J, R),port_map(B),input_map(G), plus the local split mapskick,damp,conservelinear_lawH = ½ xᵀQxwith constant J, R, B, G (lines, linear DGUs, the linear-quadratic theorems)canonical_lawH = V(q) + ½ pᵀM(q)⁻¹p,R = diag(0, D(q)). V is a quadratic plus an optional MLP; M and D are diagonal constants orsoftplus(MLP) + min. Leapfrog or Picard implicit midpoint.compositeconnectpairs two ports,connect_incidencewires an electrical network (Eq. 23),connect_skewapplies a dense skew rule. It gives the skew pairing C, the composed field (Eq. 11), the coupling field, the power terms and the readout.stepsubsteps× (coupling half-step, each block's LocalStep, coupling half-step), with Euler (phast's) or explicit-midpoint (the paper's Eq. 71) coupling. Also whole-field RK4 and implicit-midpoint references.step_bookscvc::nav::diff::dyn_ph_books(dH, supplied, dissipated, residual)rollout,check_balance,describe,write_csvload_system,load_lawcvc-ph-system/1andcvc-ph-law/1JSON filesAround it
cvc ph info|simulate|check <system.json>.checkexits 1 when the pairing does work ordH/dtdeparts from-loss + supplied.pycvc.ph_composite(path_or_json), withsimulate, which returns a(steps+1, n)numpy array and the books, pluscheck,energy,effort,field,powers,pairingandblock.docs/PH_COMPOSE.md(model, schemes, books, file formats, CLI, Python) anddocs/roadmap/PH-COMPOSE-ROADMAP.md(the plan: phases 1-5 and the mapping to the paper).There is no process-static state. Laws are immutable and shared through
shared_ptr, and a composite belongs to its caller.Tests
ph_compose_testhas 15 self-contained tests (no golden file), andph_compose_parity_testhas 3 tests against phast.CvcCliTest.PhInfoSimulateAndCheckAComposedGridandtest_pycvc_ph.py(21 checks) cover the CLI and Python.Parity with phast (
src/cvc/tests/data/ph_compose_golden.json, fromsrc/cvc/tools/cphast_fixtures.pyat phast 8b7edc86, float64, 200 steps of phast's Euler-coupled step):The learned law's efforts match phast's autograd to 1.7e-16.
Structure, whatever the laws (random heterogeneous systems with rectangular pairings and a dense skew rule):
dH/dt = -loss + suppliedto 1e-13.cvc-ph-system/1file follows RK4 at dt/64 to 8.0e-4 (Euler coupling) and 3.4e-6 (midpoint), and so do the fifth-DGU candidates.On the bus-2 candidate, 200 steps, the books' total residual is -2.5e-5 with midpoint coupling and +1.1e-4 with Euler.
Checked locally on Linux Release (GCC 13):
ph_compose_test16/16, the CLI ph tests andtest_pycvc_ph.pypass.clang++-18 -Wall -Wextrais clean on the new files, andgit clang-formatreports nothing on the changed lines.Findings about phast (for Shubham)
QuadraticPotential(k=0.0). phast's_softplus_inverse(0.0)returns 0.0, so k = softplus(0) = ln 2: a spring on the line's dummy charge, which leapfrog feeds into the line's flux. On the 4-DGU chain this moves the state by up to 6.4e-2 in 200 steps. The fixtures use an exact zero potential instead.IncidenceCouplingPortcouples throughq / C_nodewhatever the law, so learned DGUs are coupled through the reference capacitance rather than their own efforts (the paper's Eq. 203). The fixtures use CompositionalPHAST's existingneeds_grad_q/phook for the effort form.CI note
The first CI run (on e7c84e4) failed only where master was broken: #1203 had left
cmd_traceand the rich-text tests on the old signatures. A Windows runner also failed installing cvcpkg's tools. #1225 fixed master, and master is merged in as d5e6776; the PR's diff against master is still only its own 16 files. On the merged tree, locally (Linux Release, GCC 13):ph_compose_test15/15,ph_compose_parity_test3/3, CLI ph + trace 6/6,pycvc_ph.Limits (Phase 1)