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 (Options or None, default None) – Optional compatibility configuration. Prefer the named algorithm keywords. Combining this object with any algorithm keyword raises TypeError.

  • execution (ExecutionOptions or None, default None) – Optional compatibility configuration. Prefer backend, threads, and profile. Combining this object with any hardware keyword raises TypeError.

  • seed (int, default 1) – 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, default 0.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, default 0.00125) – Fraction in (0,1] of currently free variables selected per decimation. The batch is max(1, floor(batch_fraction * free_variables)), capped by the number free. Smaller batches require more SP fixed points.

  • epsilon (float, default 0.01) – Absolute tolerance in (0,1) on the largest undamped message update. Convergence does not establish the accuracy of the survey approximation.

  • damping (float, default 0.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, default 1024) – Positive sweep limit for each SP fixed-point attempt.

  • max_steps (int, default 100000) – Positive limit on recorded BSP actions. A step can contain many sweeps.

  • max_flips (int, default 0) – Nonnegative unsigned 64-bit WalkSAT flip budget across all restarts. Zero selects walksat_restarts * max(10000, 100 * residual_variables), counting free variables in active clauses at WalkSAT entry. Positive values override the automatic budget.

  • walksat_restarts (int, default 4) – Positive maximum number of randomized completions. Each restart has a quota of ceil(resolved_budget / walksat_restarts); the total cap still holds.

  • walksat_noise (float, default 0.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 (float or None, default None) – 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 macOS metal build; CUDA requires a Linux cuda build and a supported device. Availability is checked when a solver is constructed. Single precision may change the search path.

  • threads (int, default 0) – Worker limit in 0..1024. Zero selects available logical CPUs. A single scalar CPU or GPU solver uses one host execution thread; solve_many uses this budget for independent jobs. The parallel CPU backend also uses it for sweeps within a job when appropriate.

  • profile (str or pathlib.Path or None, default None) – JSON profile destination written by Solver.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.Iterable of Formula) – Inputs, materialized before solving. Repeated Formula objects share immutable CPU topology while each job retains independent mutable solver state.

  • options (Options or typing.Iterable of Options or None, default None) – 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 (ExecutionOptions or None, default None) – Optional compatibility configuration. Prefer backend, threads, and profile. Combining this object with any hardware keyword raises TypeError.

  • seed (int, default 1) – 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, default 0.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, default 0.00125) – Fraction in (0,1] of currently free variables selected per decimation. The batch is max(1, floor(batch_fraction * free_variables)), capped by the number free. Smaller batches require more SP fixed points.

  • epsilon (float, default 0.01) – Absolute tolerance in (0,1) on the largest undamped message update. Convergence does not establish the accuracy of the survey approximation.

  • damping (float, default 0.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, default 1024) – Positive sweep limit for each SP fixed-point attempt.

  • max_steps (int, default 100000) – Positive limit on recorded BSP actions. A step can contain many sweeps.

  • max_flips (int, default 0) – Nonnegative unsigned 64-bit WalkSAT flip budget across all restarts. Zero selects walksat_restarts * max(10000, 100 * residual_variables), counting free variables in active clauses at WalkSAT entry. Positive values override the automatic budget.

  • walksat_restarts (int, default 4) – Positive maximum number of randomized completions. Each restart has a quota of ceil(resolved_budget / walksat_restarts); the total cap still holds.

  • walksat_noise (float, default 0.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 (float or None, default None) – 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 macOS metal build; CUDA requires a Linux cuda build and a supported device. Availability is checked when a solver is constructed. Single precision may change the search path.

  • threads (int, default 0) – Worker limit in 0..1024. Zero selects available logical CPUs. A single scalar CPU or GPU solver uses one host execution thread; solve_many uses this budget for independent jobs. The parallel CPU backend also uses it for sweeps within a job when appropriate.

  • profile (str or pathlib.Path or None, default None) – JSON profile destination written by Solver.solve(). Enables phase timers and GPU timestamps; GPU instrumentation changes submission costs. Batch solving rejects profiling: profile individual solvers instead.

  • seeds (typing.Iterable of int or None, default None) – 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:

list of SolveResult – 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 (str or pathlib.Path) – UTF-8 text file with one p cnf N M header 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.