Skip to content

Exchange learned clauses between copies of a loaded solver - #3

Merged
aytey merged 1 commit into
stpfrom
claude/cool-meitner-eqjarj
Oct 17, 2026
Merged

aytey merged 1 commit into
stpfrom
claude/cool-meitner-eqjarj

Conversation

@aytey

@aytey aytey commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

STP's parallel mode forks copies of one loaded solver at its before-search point and lets them pass short learned clauses to each other. This adds the hooks it needs, matching the clause-import extension of STP's CaDiCaL fork, so the group can run on Kissat.

kissat_set_learn hands every clause conflict analysis learns, up to a size limit, and every unit derived at the root (kissat_learned_unit) to a callback in external literals. A clause naming a variable that factoring introduced, or one with no external counterpart, is kept back: such a variable means something different in each copy.

kissat_set_import polls a callback in the CDCL loop, after propagation and before the next decision, every given number of conflicts; a poll accepts every unit and a per-poll budget of longer clauses. External literals are mapped read-only through the import table: a clause over a variable that is unused, eliminated, substituted, an extension variable or beyond the table is dropped rather than restored (never through kissat_add), root-fixed literals satisfy or shorten it, and duplicates and tautologies are caught with the marks. One poll backtracks at most once, to the lowest level at which every accepted clause has two open literals (the root for units). Units are assigned at the root first; longer clauses become redundant clauses watched on two open literals. A clause falsified at the root makes the solver inconsistent. Nothing is imported while a proof is written, and the debugging checker takes each accepted clause as an original one.

Every imported clause must be implied by the clauses added to this solver. Every Kissat technique adds implied clauses, removes clauses, eliminates or substitutes variables with reconstruction, or introduces fresh variables (factor), so such a clause over active variables excludes no model the solver could return; unlike CaDiCaL's block, cover, condition and instantiate, nothing needs to be disabled.

kissat_diversify changes only search state: the seed (option and generator), the saved phases of active variables (all true, all false, or pseudo-random from the seed) and optionally a shuffled decision queue with random scores. The search mode remains the stable option, which the first search reads. kissat_get_import_statistics counts polls, imported clauses and units, drops, satisfied clauses and backtracks, and KISSAT_HAS_CLAUSE_EXCHANGE identifies the extension.

The STP side, which pins this commit, is stp/stp#1363.

Verification

  • test/exchange.cpp, registered as the CTest clause-exchange: groups of 2–4 copies of random 3- and 4-CNF formulas import each other's clauses while searching in conflict-limited slices (incremental) or one after another (non-incremental), under factoring, early probing, elimination, reduction and rephasing, every search mode, both incremental modes and tumble off. Each answer is compared with a fresh solver's and each model is checked against the formula; the test fails unless exports, imports, units, drops, satisfied clauses and backtracks all occur.
  • Debug CMake build (assertions and the checker on): 6/6 CTest tests pass, clause-exchange included (150/150 rounds: 95 sat, 55 unsat; 11,154 clauses imported, 115 of them units, 1,070 import backtracks).
  • Release library: 400/400 rounds (245 sat, 155 unsat; 30,117 clauses imported, 271 units, 2,816 backtracks).
  • GCC AddressSanitizer and UBSan, Debug: 60/60 rounds, no reports.
  • Without the fix that restricts diversified phases to active variables, the test aborts on assert (GET_OPTION (incremental) || !SAVED (idx)) in flags.c; with it, it passes.
  • Upstream suite: 1,045 Debug and 865 Release jobs succeed. The file tests were left out because they assume a user who cannot read /etc/shadow, and these runs were as root.
  • In STP with this commit pinned, every stp-p test passes with the group on Kissat, and so do STP's before-search API tests on Kissat (details in the STP PR).
cmake -S . -B build-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON -DKISSAT_BUILD_CLI=OFF
cmake --build build-debug
ctest --test-dir build-debug --output-on-failure

cmake -S . -B build-asan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON -DKISSAT_BUILD_CLI=OFF \
  -DCMAKE_C_FLAGS='-fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer' \
  -DCMAKE_CXX_FLAGS='-fsanitize=address,undefined -fno-sanitize-recover=undefined'
cmake --build build-asan --target kissat-exchange-test
build-asan/kissat-exchange-test 60

STP's parallel mode forks copies of one loaded solver and lets them pass
short learned clauses to each other. Add the hooks it needs.

kissat_set_learn hands every clause conflict analysis learns, up to a
size limit, and every unit derived at the root to a callback in external
literals; a clause over a variable that factoring introduced stays
private. kissat_set_import polls a callback in the CDCL loop, after
propagation and before the next decision, every given number of
conflicts, accepting every unit and a per-poll budget of longer clauses.
An imported clause must be implied by the added clauses: every enabled
technique only adds implied clauses, removes clauses, or eliminates,
substitutes or introduces variables while keeping models extendable, so
such a clause over still-active variables excludes no model. It becomes a
redundant clause, after one backtrack per poll to the level at which two
of its literals are open (the root for units). A clause over an
eliminated, substituted, unused or factoring variable is dropped rather
than restored, nothing is imported while a proof is written, and the
debugging checker takes imported clauses as original ones.

kissat_diversify changes only search state between solves: the seed,
the saved phases (all true, all false or pseudo-random) and, optionally,
the decision queue and score order. The search mode stays the 'stable'
option, which the first search reads.

test/exchange.cpp runs groups of copies in conflict-limited slices that
import each other's clauses, under factoring, early inprocessing, every
search mode and both incremental modes, and compares each answer with a
fresh solver's and each model with the formula.

Assisted-by: Claude Opus 5.5, via Claude Code
Signed-off-by: Andrew Teylu <andrew@tey.lu>
@aytey
aytey force-pushed the claude/cool-meitner-eqjarj branch from f8c5fce to 7db70ec Compare October 17, 2026 16:07
@aytey
aytey merged commit 78b48e4 into stp Oct 17, 2026
2 checks passed
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