SharpSAT plugin
The SharpSAT model plugin provides scalable approximate model counting and almost-uniform sampling of feature-model configurations.
Table of contents
Official repository
https://www.github.com/flamapy/sharpsat_metamodel
SharpSAT metamodel plugin of flamapy framework
The sharpsat_metamodel plugin adds scalable analyses over the CNF of a feature model. It
complements the existing backends: the SAT and Z3 backends count configurations by full
enumeration (which does not scale), and the BDD backend counts exactly but its diagram can
blow up on large models. sharpsat_metamodel instead uses hashing-based tools from the
CryptoMiniSat family that scale to far larger models:
- ApproxMC for an (epsilon, delta) approximate count of the number of valid configurations.
- UniGen for almost-uniform sampling of valid configurations.
Features of the SharpSAT Metamodel Plugin
- Approximate model counting
- Uses ApproxMC (
pyapproxmc) to estimate the number of valid configurations with probabilistic guarantees, scaling beyond exact enumeration or BDD compilation.
- Uses ApproxMC (
- Almost-uniform sampling
- Uses UniGen (
pyunigen) to draw configurations almost uniformly at random, honouring a partial configuration and with/without replacement.
- Uses UniGen (
- Reuses the SAT CNF
- The CNF (including the optional Tseytin encoding) is produced by reusing the SAT
metamodel’s
FmToPysattransformation, so counting and sampling are always projected onto the feature variables — auxiliary variables never distort the results.
- The CNF (including the optional Tseytin encoding) is produced by reusing the SAT
metamodel’s
Installation instructions
To install the sharpsat_metamodel plugin, follow these steps:
-
Install Python: Ensure that Python 3.11 or later is installed on your system.
-
Install the SharpSAT Metamodel Plugin:
- Using pip, the Python package manager, you can install the
flamapy-sharpsatplugin directly from PyPI:pip install flamapy-sharpsatThis also pulls in
pyapproxmcandpyunigen.
- Using pip, the Python package manager, you can install the
Links
- PyPI: flamapy-sharpsat on PyPI
- GitHub Repository: sharpsat_metamodel on GitHub
Usage
from flamapy.metamodels.fm_metamodel.transformations import UVLReader
from flamapy.metamodels.sharpsat_metamodel.transformations import FmToSharpSAT
from flamapy.metamodels.sharpsat_metamodel.operations import (
SharpSATConfigurationsNumber,
SharpSATSampling,
)
fm = UVLReader('model.uvl').transform()
model = FmToSharpSAT(fm).transform()
count = SharpSATConfigurationsNumber().execute(model).get_result()
sampler = SharpSATSampling()
sampler.set_sample_size(10)
sample = sampler.execute(model).get_sample()
Operations
Currently, this plugin enables the following operations:
Transformations supported
The plugin provides a single Model-to-Model transformation, FmToSharpSAT, which builds the
CNF of a feature model (reusing the SAT metamodel encoding). Counting and sampling then run
directly on that CNF.