Convenience functions#
- pybsp_rust.solve(formula, options=None, *, execution=None, seed=DEFAULT, backtrack_ratio=DEFAULT, batch_fraction=DEFAULT, epsilon=DEFAULT, damping=DEFAULT, max_sweeps=DEFAULT, max_steps=DEFAULT, max_flips=DEFAULT, walksat_restarts=DEFAULT, walksat_noise=DEFAULT, timeout_seconds=DEFAULT, backend=DEFAULT, threads=DEFAULT, profile=DEFAULT)[source]#
Construct a fresh solver and return one terminal result.
- Parameters:
formula (
Formula) – Immutable normalized formula, or a compatible object exposing clauses and n.options (
OptionsorNone, defaultNone) – Optional compatibility configuration. Prefer the named algorithm keywords. Combining this object with any algorithm keyword raises TypeError.execution (
ExecutionOptionsorNone, defaultNone) – Optional compatibility configuration. Prefer backend, threads, and profile. Combining this object with any hardware keyword raises TypeError.seed (
int, default1) – Unsigned 64-bit solver RNG seed. Controls initial messages and local search. It does not change a formula already generated with another seed.backtrack_ratio (
float, default0.9) – Target ratio of backtracking actions to decimation actions, in[0,1). This is a deterministic scheduling ratio, not a per-step probability. Zero disables scheduled backtracking. Large values increase revisiting.batch_fraction (
float, default0.00125) – Fraction in(0,1]of currently free variables selected per decimation. The batch ismax(1, floor(batch_fraction * free_variables)), capped by the number free. Smaller batches require more SP fixed points.epsilon (
float, default0.01) – Absolute tolerance in(0,1)on the largest undamped message update. Convergence does not establish the accuracy of the survey approximation.damping (
float, default0.0) – Old-message weight in[0,1): new = raw + damping * (old - raw). Zero is undamped. Increasing it can stabilize oscillations but slows relaxation. The convergence test still compares raw against old.max_sweeps (
int, default1024) – Positive sweep limit for each SP fixed-point attempt.max_steps (
int, default100000) – Positive limit on recorded BSP actions. A step can contain many sweeps.max_flips (
int, default0) – Nonnegative unsigned 64-bit WalkSAT flip budget across all restarts. Zero selectswalksat_restarts * max(10000, 100 * residual_variables), counting free variables in active clauses at WalkSAT entry. Positive values override the automatic budget.walksat_restarts (
int, default4) – Positive maximum number of randomized completions. Each restart has a quota ofceil(resolved_budget / walksat_restarts); the total cap still holds.walksat_noise (
float, default0.5) – Probability in[0,1]of a uniformly random free variable in a sampled unsatisfied clause when every candidate has positive break count. Otherwise choose among minimum-break candidates, breaking ties randomly.timeout_seconds (
floatorNone, defaultNone) – Positive finite cooperative wall-time limit since solver construction, including backend setup and time between calls. None disables it.backend (
{'cpu', 'cpu-parallel', 'metal', 'cuda', 'cuda-f32'}, default'cpu') – Scalar CPU double precision, multicore CPU double precision, Apple GPU single precision, NVIDIA GPU double precision, or NVIDIA GPU single precision. Metal requires a macOSmetalbuild; CUDA requires a Linuxcudabuild and a supported device. Availability is checked when a solver is constructed. Single precision may change the search path.threads (
int, default0) – Worker limit in0..1024. Zero selects available logical CPUs. A single scalar CPU or GPU solver uses one host execution thread;solve_manyuses this budget for independent jobs. The parallel CPU backend also uses it for sweeps within a job when appropriate.profile (
strorpathlib.PathorNone, defaultNone) – JSON profile destination written bySolver.solve(). Enables phase timers and GPU timestamps; GPU instrumentation changes submission costs. Batch solving rejects profiling: profile individual solvers instead.
- Returns:
SolveResult– Verified assignment on status ‘sat’; otherwise a heuristic failure or limit.- Raises:
ValueError – If input/settings are invalid or backend setup fails.
TypeError – If keywords are unknown or configuration sources conflict.
Notes
DEFAULT denotes an omitted setting; effective defaults are listed above. Formula generation has its own seed. A failed search is not an UNSAT proof.
Examples
>>> result = solve(formula=Formula([[1], [-2]], n=2), seed=3) >>> result.status, result.assignment.tolist() ('sat', [1, 0])
- pybsp_rust.solve_many(formulas, options=None, *, execution=None, seed=DEFAULT, backtrack_ratio=DEFAULT, batch_fraction=DEFAULT, epsilon=DEFAULT, damping=DEFAULT, max_sweeps=DEFAULT, max_steps=DEFAULT, max_flips=DEFAULT, walksat_restarts=DEFAULT, walksat_noise=DEFAULT, timeout_seconds=DEFAULT, backend=DEFAULT, threads=DEFAULT, profile=DEFAULT, seeds=None)[source]#
Solve independent jobs with bounded workers and stable input order.
- Parameters:
formulas (
typing.IterableofFormula) – Inputs, materialized before solving. Repeated Formula objects share immutable CPU topology while each job retains independent mutable solver state.options (
Optionsortyping.IterableofOptionsorNone, defaultNone) – Optional compatibility settings, shared or one per formula. Prefer named algorithm keywords and seeds for the common per-job seed case. Combining this object with any algorithm keyword raises TypeError.execution (
ExecutionOptionsorNone, defaultNone) – Optional compatibility configuration. Prefer backend, threads, and profile. Combining this object with any hardware keyword raises TypeError.seed (
int, default1) – Unsigned 64-bit solver RNG seed. Controls initial messages and local search. It does not change a formula already generated with another seed.backtrack_ratio (
float, default0.9) – Target ratio of backtracking actions to decimation actions, in[0,1). This is a deterministic scheduling ratio, not a per-step probability. Zero disables scheduled backtracking. Large values increase revisiting.batch_fraction (
float, default0.00125) – Fraction in(0,1]of currently free variables selected per decimation. The batch ismax(1, floor(batch_fraction * free_variables)), capped by the number free. Smaller batches require more SP fixed points.epsilon (
float, default0.01) – Absolute tolerance in(0,1)on the largest undamped message update. Convergence does not establish the accuracy of the survey approximation.damping (
float, default0.0) – Old-message weight in[0,1): new = raw + damping * (old - raw). Zero is undamped. Increasing it can stabilize oscillations but slows relaxation. The convergence test still compares raw against old.max_sweeps (
int, default1024) – Positive sweep limit for each SP fixed-point attempt.max_steps (
int, default100000) – Positive limit on recorded BSP actions. A step can contain many sweeps.max_flips (
int, default0) – Nonnegative unsigned 64-bit WalkSAT flip budget across all restarts. Zero selectswalksat_restarts * max(10000, 100 * residual_variables), counting free variables in active clauses at WalkSAT entry. Positive values override the automatic budget.walksat_restarts (
int, default4) – Positive maximum number of randomized completions. Each restart has a quota ofceil(resolved_budget / walksat_restarts); the total cap still holds.walksat_noise (
float, default0.5) – Probability in[0,1]of a uniformly random free variable in a sampled unsatisfied clause when every candidate has positive break count. Otherwise choose among minimum-break candidates, breaking ties randomly.timeout_seconds (
floatorNone, defaultNone) – Positive finite cooperative wall-time limit since solver construction, including backend setup and time between calls. None disables it.backend (
{'cpu', 'cpu-parallel', 'metal', 'cuda', 'cuda-f32'}, default'cpu') – Scalar CPU double precision, multicore CPU double precision, Apple GPU single precision, NVIDIA GPU double precision, or NVIDIA GPU single precision. Metal requires a macOSmetalbuild; CUDA requires a Linuxcudabuild and a supported device. Availability is checked when a solver is constructed. Single precision may change the search path.threads (
int, default0) – Worker limit in0..1024. Zero selects available logical CPUs. A single scalar CPU or GPU solver uses one host execution thread;solve_manyuses this budget for independent jobs. The parallel CPU backend also uses it for sweeps within a job when appropriate.profile (
strorpathlib.PathorNone, defaultNone) – JSON profile destination written bySolver.solve(). Enables phase timers and GPU timestamps; GPU instrumentation changes submission costs. Batch solving rejects profiling: profile individual solvers instead.seeds (
typing.IterableofintorNone, defaultNone) – One unsigned 64-bit solver seed per formula. Length must match formulas. Combine with shared algorithm and hardware keywords. Do not combine with seed or options. None broadcasts seed (whose effective default is 1).
- Returns:
listofSolveResult– Results in input order, including heuristic failures. Empty input returns [].- Raises:
ValueError – If lengths/settings disagree, profile is not None, or backend setup fails.
TypeError – If keywords are unknown or configuration sources conflict.
Notes
Shared algorithm keywords apply to every job. Use seeds for independent restart seeds, or compatibility Options sequences for arbitrary per-job configurations. GPU concurrency is additionally bounded by estimated device memory. DEFAULT marks omission; effective defaults are listed above. Profile individual Solver objects instead of using a shared batch profile path.
Examples
>>> formula = Formula([[1], [-2]], n=2) >>> results = solve_many(formulas=[formula] * 3, seeds=[3, 4, 5], threads=2) >>> [result.seed for result in results] [3, 4, 5]
- pybsp_rust.from_file(path)[source]#
Read a DIMACS CNF file into a normalized
Formula.- Parameters:
path (
strorpathlib.Path) – UTF-8 text file with onep cnf N Mheader and zero-terminated clauses.- Returns:
Formula– Immutable formula preserving original variable IDs and declared n.- Raises:
OSError – If the file cannot be read.
ValueError – If DIMACS counts, termination, or literal ranges are invalid.