Skip to content

Feat/add extensive testing - #9

Merged
IbrahimElk merged 8 commits into
mainfrom
feat/add-extensive-testing
Mar 30, 2026
Merged

Feat/add extensive testing#9
IbrahimElk merged 8 commits into
mainfrom
feat/add-extensive-testing

Conversation

@IbrahimElk

Copy link
Copy Markdown
Collaborator

Fixes #8

This PR was originally opened to verify that adding Arjun to compile_from_ganak would not break any circuits.
To support that verification, I added an sd-DNNF checker to klay that checks decomposability and smoothness.
That checker is currently available in my branch here:

https://github.com/IbrahimElk/klay/tree/feat/sd-dnnf-checker

and will hopefully be merged into the main klay branch at:

https://github.com/ML-KULeuven/klay

Using this checker, I found that compile_from_ganak without any preprocessing by Arjun was producing incorrect circuits. This PR fixes that issue in field_circuit.h and adds more extensive tests to ensure the behavior remains correct in the future.

It also introduces exhaustive equivalence tests that verify the CNF formula and the generated circuit encode the same Boolean function. Since testing all CNF formulas is infeasible, the test suite focuses on small formulas, random 3-CNF instances, and edge cases.

Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
* check circuit output matches CNF truth table for all assignments,
covering trivial and random 3-CNF cases.

* check compiled circuits satisfy decomposability
and smoothness via klay.check_sdnnf.

Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
@IbrahimElk

Copy link
Copy Markdown
Collaborator Author

Work related to Arjun’s integration will be handled separately in another branch and a dedicated PR.

* FCircuit's operator/= was a no-op, causing non-decomposable circuits when
GANAK's flipped_declit conflict path calls branch_mc /= weight(x1) to undo
a previously multiplied-in literal weight.

* Literal weights are now kept in pending_lits_ rather than immediately
committed into the AND tree. operator/= removes the literal from this list.
Pending lits are committed into node_ only when an OR node is built, which
is after the division window has closed.

* Also fix larger_than() to use count_ instead of returning false, so GANAK's
cube selection heuristic has a meaningful ordering.

Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
* in order to access sdnnf checker of klay

Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
@IbrahimElk
IbrahimElk force-pushed the feat/add-extensive-testing branch from c87ed73 to 733c237 Compare March 24, 2026 08:45
* Remove the compile_from_ganak(string) overload that
created its own circuit internally, callers must now
provide an existing circuit explicitly.

* Expand test_api.py into a TestAPI class

Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
@IbrahimElk
IbrahimElk force-pushed the feat/add-extensive-testing branch from 733c237 to c206583 Compare March 24, 2026 08:50
Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
@IbrahimElk

Copy link
Copy Markdown
Collaborator Author

see ML-KULeuven/klay#24

* non-chronological backtracking is not yet
compatible with circuit building.

Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
Signed-off-by: IbrahimElk <ibrahim_elkaddouri@outlook.com>
@IbrahimElk
IbrahimElk merged commit 2b49ae8 into main Mar 30, 2026
3 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.

circuit compilation produces non-decomposable DNNF on certain CNFs

1 participant