Skip to content

Compile in skip-level form under auto --skip-levels (experimental, not for merging) - #32

Draft
guyvdbroeck wants to merge 9 commits into
mainfrom
skip-levels
Draft

guyvdbroeck wants to merge 9 commits into
mainfrom
skip-levels

Conversation

@guyvdbroeck

Copy link
Copy Markdown
Member

This draft holds tddlog's side of the work on diagrams whose pairs skip vtree levels. It is kept open as a record of that work and as the branch to continue it on, not to be merged. The library side is Tractables/tididi#24, and the issue is Tractables/tididi#23. Cargo.toml pins tididi to e4b7af7e, the head of that pull request's branch skip-levels.

What it does

With --skip-levels the backend keeps every formula of a layout's run as a skip-form diagram (SkipTdd), whose pairs may skip levels of the vtree; on a right-linear vtree that is a reduced OBDD. Each backend operation has a skip arm that calls the library's skip operation. The constructors build in the stored form and convert once. The evidence is counted in skip form once, up and down: a literal query reads its joint off the pass down, and a query formula on the evidence's scope is walked against the counted evidence without building the conjunction. The option runs under --vtree program, program:fanin, decision and auto.

Under auto the form is decided per trial. A trial of program, program:fanin or decision measures its first formula of 2^16 pairs or more in skip form. Where that formula keeps under 1/22 of its pairs, the trial weighs the two forms over a stretch of work: it copies its compile into skip form at the step where the stretch begins, goes on stored until its work has doubled, then goes on with the copy over the same components. It keeps the skip form where that spends less work, the conversion included, and goes back to the stored compile where it spends as much. The weighing is charged to no trial, so a trial that weighs keeps its place in the race. A step only the stored form takes sends a trial back to the stored form. Every other trial, and every trial whose formula keeps more pairs, stays stored. A skip operation charges the work clock 16 times its own units, so that the turns and the stop mean the same time in either form.

Without the flag, trials, work and answers are unchanged. A unit test checks every skip arm against the stored arm on random vtrees, and the integration tests check answers and P(e) against the stored form, the auto rule, and every refused combination of options.

Why it is a draft

The gains so far do not justify the size. Against main this branch changes 35 files, adding 3,220 lines and removing 352, on top of the library branch's 11,580 lines added and 1,304 removed.

Results

auto against auto --skip-levels, on 173 bit-blasted circuits exported by Alea.jl:

Without skips With skips
Circuits answered 142 144
PAR-2 total 40850 s 38463 s

The ratio of CPU time with skips to without, per circuit, has a geometric mean of 0.930 and a median of 1.003. Most of the gain is in one family: fair_dt runs 1.6 to 3.4 times faster. laplace_w15 and altermu2_p64 are answered only with skips, and addFun_max is between 0.94 and 1.07. Per operation the skip form is still several times slower than the stored form where skipping does not shrink a diagram much, which is why the rule weighs the skip form only where skipping shrinks a formula about 22-fold. The answers agree on all instances.

Beyond the circuits

On the other 1,857 instances of tddlog's results that tddlog reads (probabilistic logic programs, probabilistic databases, Bayesian networks, Markov networks and probabilistic functional programs), skipping never engages:

  • The 687 runs that compute the probability of evidence without queries refuse --skip-levels: they sum the evidence out as they walk it, which reads stored levels.
  • On the networks that do run, auto's trials use layouts that have no skip form.
  • 48 trials measured their first large formula in skip form. It kept between 7% and 95% of its pairs (median 63%), never under the 1/22 the rule needs before it weighs the two forms.

So every trial stayed stored, with auto's answers and work, and on the 48 the measurement cost nothing measurable (paired CPU ratio 1.004).

🤖 Generated with Claude Code

guyvdbroeck and others added 9 commits November 4, 2026 12:53
The skip form's operations that --skip-levels calls (evaluation,
counts with a literal or a diagram, conditioning, quantification and
the rest) are on tididi's skip-levels branch, not on its main.

Co-Authored-By: Claude <noreply@anthropic.com>
With --skip-levels, the backend keeps every formula of one layout's run
as a skip-form diagram, whose pairs may skip levels of the vtree (on a
right-linear vtree, a reduced OBDD), and answers the queries from it.
Each backend operation has a skip arm that calls the library's skip
operation; the constructors build in the stored form and convert once,
refusing a formula that holds implicit levels.

The evidence's mass is the engine's evaluation of the skip diagram, a
literal query conjoins the literal with the evidence, and any other
query counts its product with the evidence on the union of their
scopes. The sum-out walk, which reads stored levels, does not run in
skip form.

The option runs under `--vtree program`, `program:fanin` and `decision`,
with the queries. It is refused as an options error under `auto`,
`dynamic`, `td`, the families and `closed`, without the queries, and
with --ground, --program and --cnf, which stop before the compile.
--stats names the form and the trace records it.

A unit test checks every skip arm against the stored arm in skip form on
random vtrees, and the integration tests check the answers and P(e) of
circuits, named cuts, a narrowed formula and the examples against the
stored form, and every refusal.

Co-Authored-By: Claude <noreply@anthropic.com>
A query in skip form was answered by conjoining it with the evidence and
counting the product, once per query. The engine now counts the evidence
in skip form once, up and down (Engine::skip_count): a literal of the
evidence's scope reads its joint off the pass down, and a query formula
on the evidence's scope is walked against the counted evidence
(skip_count_and) without building the conjunction. Counts are in floats
while they are exact and are taken again in Counts otherwise, as the
stored route does. A query whose variables the evidence's scope does not
all hold, or that a template answers, keeps the product.

The test checks literals, negated literals, derived atoms on and off the
evidence's scope, and a count that underflows floats, against answers by
enumeration.

Co-Authored-By: Claude <noreply@anthropic.com>
…few pairs

With --skip-levels, auto no longer refuses. A trial of program,
program:fanin or decision measures its first formula of 2^16 pairs or
more in skip form, once, and begins again in skip form, with its target
and the work it has spent, where that formula keeps under 1/22 of its
pairs there. A skip pair costs 2 to 23 times the time of a stored pair
on the bit-blasted circuits, so below that share the skip form pays even
at the costly end. Every other trial, and every trial whose formula keeps
more, stays stored. A trial in skip form that meets a step only the
stored form takes begins again stored.

A skip operation charges the work clock 16 times its own units, the ratio
of the two engines' rates on the circuits, and the run's stop inside the
operation is scaled alike, so that turns, the guard and the watch mean
the same time in either form.

On the 173 bit-blasted circuits under auto, 33 put a trial in skip form:
answers equal, 144 circuits answered against 142, PAR-2 total 6% lower.
fair_dt4 and fair_dt14 ran about twice as fast; addFun_max ran up to 2.3
times slower. Without the flag, trials, work and answers are unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
A trial whose first large formula keeps under 1/22 of its pairs in skip
form no longer goes on in skip form on that share alone. A skip pair's
cost varies too much for one bound: on the bit-blasted circuits it took
0.5 to 250 times a stored pair's time in program's compiles, and 35 to
56 times in program:fanin's, where addFun_max's trials kept 2.5% to
3.7% of their pairs and ran 1.2 to 2.5 times slower in skip form.

The trial now goes on stored from its next step until its work has
doubled, sets that compile aside, and begins again in skip form. Its
work in skip form over the same components is weighed against the
stored form's: where it is less, the trial goes on in skip form and the
stored compile is freed; where it reaches as much, the trial goes on
with the stored compile set aside, or begins it again where a run
without a watch could not keep it. A step that needs the stored form
goes back the same way.

The two forms' work is read on the trial's clock: what it spent before
the turn and the work since. The engine's work clock starts again with
each run, so a clock read from the engine alone would run back between
turns.

Co-Authored-By: Claude <noreply@anthropic.com>
A trial that weighed the skip form against its stored compile was
charged both forms' work over the stretch. That put it behind the
trials that did not weigh, and the race gave them its turns: on the
addFun_max circuits every trial went back to the stored form, yet the
runs took 1.1 to 2.6 times as long, while the weighing itself was
about a tenth of the work.

Whichever form it goes on in, the trial now takes up the race where it
set its stored compile aside, with that target, work and progress, and
what it spent past the verdict. The weighing's work is charged to no
trial, as settling's is not.

Co-Authored-By: Claude <noreply@anthropic.com>
A trial that weighed the skip form set its stored compile aside and
compiled again in skip form from the first component. On the addFun_max
circuits, where every duel went back to the stored form, that compile
from the start was the weighing's cost: 5 to 14% of the run.

The compile now makes a copy of itself in skip form at the step where
the probe's stretch begins: every formula, the other polarities it
caches and the clause loops it keeps, converted. The stored compile goes
on over the stretch as before. When the stretch ends, the trial sets the
stored compile aside and goes on with the copy from that component, so
the two forms are weighed over the same components. Skip form is
canonical, so the copy holds the diagrams a compile in skip form from
the start holds there.

The conversion reads each stored pair once, the pairs of a level held
as its description among them, and the engine's work clock counts none
of it, so the copy is charged those pairs on the skip side. A level held
as its description is converted rather than refused: a builder's birth
in skip form still refuses one, since every birth would write out its
pairs, but the copy converts each diagram once. A copy over the memory
budget leaves the trial stored.

Co-Authored-By: Claude <noreply@anthropic.com>
The library now holds a skip-form negation as a mark on the diagram it
negates, and the disjunction and conjunction of marked operands as the
negation of their dual, so a skip arm's result can store the canonical
form of its complement. The test compared its pairs with those of the
stored arm's result in skip form; it now accepts the complement's
where they differ.

Co-Authored-By: Claude <noreply@anthropic.com>
The library branch now has no experiment switches. The help line for
--skip-levels described an earlier rule; under auto a trial whose first
large formula keeps under 1/22 of its pairs in skip form weighs both
forms over a stretch of work and keeps the cheaper one.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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