Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ contains 3,300 case/mode verdicts at the pinned revision. These are its only
changed rows, with no passing case regressing: 1,201 cases pass in 2state and
1,212 in 4state. Only these reviewed expectations are updated.

Zero-argument dynamic-container methods accept omitted parentheses, including
`size`, associative `num`, `delete`, and queue `pop_front` / `pop_back`
(7.5.2–7.5.3, 7.9, 7.10.2). Sixteen unmodified upstream simulation cases pass
the official runner in both state modes at the pinned revision: dynamic
`op-delete` / `op-size`, associative `alloc`, `nonexistent`, `delete`, `num`,
and `size`, and queue
`bounded`, `delete`, `insert`, `max-size`, `pop_back`, `pop_front`, `push_back`,
`push_front` and `size`. Only these 32 expectations change from `fail` to `pass`.
The focused runner checked 36 pinned case files containing these bare
method names (72 case/mode verdicts), with no passing candidate regressing.
This does not establish full dynamic-container conformance.
Shared regressions additionally cover discarded pop results, string/class
handles, four-state values and empty-pop defaults, and unevaluated type queries
that preserve packed result dimensions and authored bounds. The packed-result
query regression failed on all five Celox backend configurations even after
the initial 28 upstream checks passed. Arity and void-result rejection remain checked.
Queue slices, queue operands in concatenations, element-reference persistence,
warning diagnostics, and queries on nonintegral pop results remain outside
this change's support contract.

## Running locally

Use the locked development shell and install the pinned [`requirements.txt`](requirements.txt) in a Python environment.
Expand Down
64 changes: 32 additions & 32 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,8 @@ chapter-6/6.9.2--vector_vectored.sv 2state fail
chapter-6/6.9.2--vector_vectored.sv 4state fail
chapter-6/6.9.2--vector_vectored_inv.sv 2state pass
chapter-6/6.9.2--vector_vectored_inv.sv 4state pass
chapter-7/arrays/associative/alloc.sv 2state fail
chapter-7/arrays/associative/alloc.sv 4state fail
chapter-7/arrays/associative/alloc.sv 2state pass
chapter-7/arrays/associative/alloc.sv 4state pass
chapter-7/arrays/associative/arguments.sv 2state fail
chapter-7/arrays/associative/arguments.sv 4state fail
chapter-7/arrays/associative/assignment.sv 2state pass
Expand Down Expand Up @@ -1287,8 +1287,8 @@ chapter-7/arrays/associative/locator-methods/unique-index.sv 2state fail
chapter-7/arrays/associative/locator-methods/unique-index.sv 4state fail
chapter-7/arrays/associative/locator-methods/unique.sv 2state fail
chapter-7/arrays/associative/locator-methods/unique.sv 4state fail
chapter-7/arrays/associative/methods/delete.sv 2state fail
chapter-7/arrays/associative/methods/delete.sv 4state fail
chapter-7/arrays/associative/methods/delete.sv 2state pass
chapter-7/arrays/associative/methods/delete.sv 4state pass
chapter-7/arrays/associative/methods/exists.sv 2state pass
chapter-7/arrays/associative/methods/exists.sv 4state pass
chapter-7/arrays/associative/methods/first.sv 2state pass
Expand All @@ -1297,16 +1297,16 @@ chapter-7/arrays/associative/methods/last.sv 2state pass
chapter-7/arrays/associative/methods/last.sv 4state pass
chapter-7/arrays/associative/methods/next.sv 2state pass
chapter-7/arrays/associative/methods/next.sv 4state pass
chapter-7/arrays/associative/methods/num.sv 2state fail
chapter-7/arrays/associative/methods/num.sv 4state fail
chapter-7/arrays/associative/methods/num.sv 2state pass
chapter-7/arrays/associative/methods/num.sv 4state pass
chapter-7/arrays/associative/methods/prev.sv 2state pass
chapter-7/arrays/associative/methods/prev.sv 4state pass
chapter-7/arrays/associative/methods/size.sv 2state fail
chapter-7/arrays/associative/methods/size.sv 4state fail
chapter-7/arrays/associative/methods/size.sv 2state pass
chapter-7/arrays/associative/methods/size.sv 4state pass
chapter-7/arrays/associative/methods/traversal.sv 2state pass
chapter-7/arrays/associative/methods/traversal.sv 4state pass
chapter-7/arrays/associative/nonexistent.sv 2state fail
chapter-7/arrays/associative/nonexistent.sv 4state fail
chapter-7/arrays/associative/nonexistent.sv 2state pass
chapter-7/arrays/associative/nonexistent.sv 4state pass
chapter-7/arrays/associative/other.sv 2state fail
chapter-7/arrays/associative/other.sv 4state fail
chapter-7/arrays/associative/string.sv 2state pass
Expand All @@ -1315,12 +1315,12 @@ chapter-7/arrays/associative/wildcard.sv 2state fail
chapter-7/arrays/associative/wildcard.sv 4state fail
chapter-7/arrays/dynamic/basic.sv 2state pass
chapter-7/arrays/dynamic/basic.sv 4state pass
chapter-7/arrays/dynamic/op-delete.sv 2state fail
chapter-7/arrays/dynamic/op-delete.sv 4state fail
chapter-7/arrays/dynamic/op-delete.sv 2state pass
chapter-7/arrays/dynamic/op-delete.sv 4state pass
chapter-7/arrays/dynamic/op-new.sv 2state pass
chapter-7/arrays/dynamic/op-new.sv 4state pass
chapter-7/arrays/dynamic/op-size.sv 2state fail
chapter-7/arrays/dynamic/op-size.sv 4state fail
chapter-7/arrays/dynamic/op-size.sv 2state pass
chapter-7/arrays/dynamic/op-size.sv 4state pass
chapter-7/arrays/multidimensional/basic.sv 2state pass
chapter-7/arrays/multidimensional/basic.sv 4state pass
chapter-7/arrays/multidimensional/copy.sv 2state pass
Expand Down Expand Up @@ -1409,38 +1409,38 @@ chapter-7/memories/read-write.sv 2state pass
chapter-7/memories/read-write.sv 4state pass
chapter-7/queues/basic.sv 2state pass
chapter-7/queues/basic.sv 4state pass
chapter-7/queues/bounded.sv 2state fail
chapter-7/queues/bounded.sv 4state fail
chapter-7/queues/delete.sv 2state fail
chapter-7/queues/delete.sv 4state fail
chapter-7/queues/bounded.sv 2state pass
chapter-7/queues/bounded.sv 4state pass
chapter-7/queues/delete.sv 2state pass
chapter-7/queues/delete.sv 4state pass
chapter-7/queues/delete_assign.sv 2state fail
chapter-7/queues/delete_assign.sv 4state fail
chapter-7/queues/insert.sv 2state fail
chapter-7/queues/insert.sv 4state fail
chapter-7/queues/insert.sv 2state pass
chapter-7/queues/insert.sv 4state pass
chapter-7/queues/insert_assign.sv 2state fail
chapter-7/queues/insert_assign.sv 4state fail
chapter-7/queues/max-size.sv 2state fail
chapter-7/queues/max-size.sv 4state fail
chapter-7/queues/max-size.sv 2state pass
chapter-7/queues/max-size.sv 4state pass
chapter-7/queues/persistence.sv 2state fail
chapter-7/queues/persistence.sv 4state fail
chapter-7/queues/pop_back.sv 2state fail
chapter-7/queues/pop_back.sv 4state fail
chapter-7/queues/pop_back.sv 2state pass
chapter-7/queues/pop_back.sv 4state pass
chapter-7/queues/pop_back_assing.sv 2state fail
chapter-7/queues/pop_back_assing.sv 4state fail
chapter-7/queues/pop_front.sv 2state fail
chapter-7/queues/pop_front.sv 4state fail
chapter-7/queues/pop_front.sv 2state pass
chapter-7/queues/pop_front.sv 4state pass
chapter-7/queues/pop_front_assign.sv 2state fail
chapter-7/queues/pop_front_assign.sv 4state fail
chapter-7/queues/push_back.sv 2state fail
chapter-7/queues/push_back.sv 4state fail
chapter-7/queues/push_back.sv 2state pass
chapter-7/queues/push_back.sv 4state pass
chapter-7/queues/push_back_assign.sv 2state fail
chapter-7/queues/push_back_assign.sv 4state fail
chapter-7/queues/push_front.sv 2state fail
chapter-7/queues/push_front.sv 4state fail
chapter-7/queues/push_front.sv 2state pass
chapter-7/queues/push_front.sv 4state pass
chapter-7/queues/push_front_assign.sv 2state fail
chapter-7/queues/push_front_assign.sv 4state fail
chapter-7/queues/size.sv 2state fail
chapter-7/queues/size.sv 4state fail
chapter-7/queues/size.sv 2state pass
chapter-7/queues/size.sv 4state pass
chapter-7/queues/slice.sv 2state fail
chapter-7/queues/slice.sv 4state fail
chapter-7/structures/packed/basic.sv 2state pass
Expand Down
74 changes: 74 additions & 0 deletions crates/aplite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,77 @@ the query history because learning and search activity are retained. Unknown
includes invalid predicate indexes and exhausted budgets, and is not Unsat.
This API supplies reusable solving for future distribution policies; it does not
implement uniform sampling, variable ordering, or SystemVerilog `randomize()`.

## Bounded hash cells

`HashCells` prepares seed-selected affine XOR predicates over chosen scalar
variables. A query chooses a prefix of those predicates and their target bits;
shorter prefixes leave larger cells. The original formula and all predicates are
compiled once. The cell query uses one temporary SAT database and retains local
learning while it blocks already-seen projected assignments. It does not recompile
the formula for each model or retain blockers between cells.

```rust
use aplite::{CellStatus, Env, HashCells, Limits, Sort, boolv, var};
let projection = Env::from([("value".into(), var("x".into(), Sort::Bv(3)))]);
let cells = HashCells::new(&boolv(true), &projection, 2, 42, Limits::default()).unwrap();
let cell = cells.cell(&[true, false], 8, Limits::default());
assert_eq!(cell.status, CellStatus::Complete);
assert!(cell.models.iter().all(|model| model.contains_key("x")));
```

`Complete` certifies all models in that cell, including an empty cell. `TooLarge`
means the cell has more models than the caller's bound, and `Unknown` covers
invalid input or exhausted budgets. Neither exposes a truncated model list.
All searches and replay in one cell share one work/time budget. Hidden variables
are existential: multiple witnesses cannot duplicate a projected assignment.
Call `PreparedQuery::enumerate_cell` directly for custom partition predicates.

These operations are building blocks, **not a uniform sampler**. Uniformly picking
a cell and then uniformly picking one of its models generally biases results
when cells have different sizes. A sampling policy must control cell sizing and
acceptance separately. The exhaustive reservoir sampler remains a test-only reference.
Rows may be dependent or constant; hash construction preserves those cases.

## Approximate sample batches

`Sampler` connects count estimation, cell acceptance and model selection using
the two-stage policy of [UniGen2, algorithms 1 and 2](https://people.eecs.berkeley.edu/~sseshia/pubdir/tacas15.pdf).
It uses fixed kappa=0.638 (pivot 27, accepted cell sizes 11..63), estimates the
number of XOR rows, then tries that count and its two predecessors with fresh
hash families. An accepted cell yields 11 distinct randomly selected models.
A bounded initial probe handles at most 64 total models directly, returning one
random model per call; a larger space is never fully enumerated.

```rust
use aplite::{Env, Limits, Sampler, Sort, Verdict, boolv, var};
let projection = Env::from([("data".into(), var("data".into(), Sort::Bv(8)))]);
let mut sampler = Sampler::new(&boolv(true), &projection, 7, Limits::default()).unwrap();
let batch = sampler.sample_batch(Limits::default());
match batch.verdict {
Verdict::Sat => assert!(!batch.models.is_empty()),
Verdict::Unsat => panic!("this unconstrained query is satisfiable"),
Verdict::Unknown => assert!(batch.models.is_empty()),
}
```

Preparation caches the formula/projection snapshot and estimated count parameters.
Each fresh hash family currently builds its own encoding; searches within its cell
reuse that encoding and local learned clauses. Gaussian elimination simplifies
XOR rows and transforms target bits together, preserving every original cell and
prefix. This avoids sending a dense redundant linear system directly to CDCL.

This is **approximate sampling**, not a claim of exact uniformity or independent
samples. The paper's ideal-randomness guarantees are not a certification of this
seeded, resource-bounded implementation. Its fixed tolerance is broad (epsilon
approximately 16.09); empirical frequency tests do not establish a tighter bound.
A failed estimate or an unsuccessful three-cell attempt is reported as an error
or `Unknown`, never a heuristic sample or an UNSAT verdict. A complete empty
initial probe is the only source of UNSAT. There is no automatic fallback.

One budget covers preparation and a separate budget covers each complete batch
request. Unknown returns no partial batch. Work after an unreported preparation
failure is conservatively charged to the remaining work limit. Changing state
variables or constraints requires a new sampler. Weighted distributions,
`solve before`, `randc`, and SystemVerilog frontend/runtime integration are not
implemented by this API.
2 changes: 1 addition & 1 deletion crates/aplite/src/finite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod control;
mod lookup;
mod prepared;
mod readonly;
pub use prepared::{Assumption, PreparedQuery};
pub use prepared::{Assumption, Cell, CellStatus, HashCells, PreparedQuery, SampleBatch, Sampler};
pub use readonly::ArrayModel;

type Lit = i32;
Expand Down
7 changes: 7 additions & 0 deletions crates/aplite/src/finite/prepared.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
//! Reusable scalar encoding with temporary Boolean assumptions.
use super::*;

mod cell;
mod hashing;
mod sampler;
pub use cell::{Cell, CellStatus};
pub use hashing::HashCells;
pub use sampler::{SampleBatch, Sampler};

/// Select the polarity of a predicate supplied when preparing the query.
#[derive(Clone, Copy, Debug)]
pub struct Assumption {
Expand Down
Loading
Loading