Ejemplo n.º 1
0
 def __init__(self, domain, support, weight):
     super().__init__(domain, support, weight)
     if not pysmt_installed:
         raise InstallError(
             "No PySMT solver is installed (not installed or not on path)")
     if PRAiSEInference is None:
         raise InstallError("The wmipa library is not in your PYTHONPATH")
Ejemplo n.º 2
0
    def __init__(self, domain, support, weight, cache=False):
        super().__init__(domain, support, weight)
        if not pysmt_installed:
            raise InstallError(
                "No PySMT solver is installed (not installed or not on path)")
        if MPWMI is None:
            raise InstallError("The pympwmi library is not in your PYTHONPATH")

        self.cache = cache
Ejemplo n.º 3
0
 def __init__(self, domain, support, weight, mode=None, timeout=None):
     super().__init__(domain, support, weight)
     if not check_installation_xadd_jar():
         raise InstallError(
             "The XADD engine requires the XADD library JAR file which is currently not installed."
         )
     if not check_installation_gurobi():
         raise InstallError(
             "The XADD engine requires Gurobi which is currently not installed."
         )
     self.mode = mode
     self.timeout = timeout
 def __init__(self):
     IntegrationBackend.__init__(self, exact=True)
     if psi is None:
         raise InstallError(
             "PsiPolynomialAlgebra requires the psi library to be installed"
         )
     self._eval_bounds_cache = psi.EvalBoundsCache()
Ejemplo n.º 5
0
    def __init__(
        self,
        domain,
        support,
        weight,
        exact,
        *,
        algebra: Optional[IntegratorAndAlgebra] = None,
        find_conflicts=False,
        ordered=False,
        vtree_strategy=bami,
        minimize=False,
    ):

        super().__init__(domain, support, weight, exact)
        try:
            from pysdd.sdd import SddManager, SddNode
        except ImportError as e:
            from pywmi.errors import InstallError

            raise InstallError(
                f"{type(self).__name__} requires the pysdd package") from e

        self.algebra = (algebra or PsiPiecewisePolynomialAlgebra()
                        )  # Algebra used to solve SMT theory
        self.find_conflicts = find_conflicts
        self.ordered = ordered
        self.vtree_strategy = vtree_strategy
        self.minimize = minimize  # Use SDD minimization as implemented in PySDD
Ejemplo n.º 6
0
    def __init__(self, domain, support, weight, directory=None, timeout=None):
        if WMI is None:
            raise InstallError()

        super().__init__(domain, support, weight)
        self.timeout = timeout
        self.directory = directory
Ejemplo n.º 7
0
    def __init__(self, sdd, smooth=True, smooth_to_root=False):
        """Simple iterator to iterate over the SDD graph.

        Supports smoothing: An arithmetic circuit AC(X) is smooth iff
        (1) it contains at least one indicator for each variable in X, and
        (2) for every child c of '+'-node n, we have vars(n) = vars(c).

        Note, if you know that you will be performing WMC, smoothing can be implemented more efficient
        by keeping track of the expected WMC of used and unused variables in the vtree instead of keeping
        track of the sets of variables as is done in this iterator.

        :param sdd: WmcManager
        :param smooth: Perform smoothing while iterating over the graph
        :param smooth_to_root: Perform smoothing wrt root instead of a given node
        """
        if SddManager is None:
            raise InstallError("The PySDD library is not installed")

        self.sdd = sdd  # type: SddManager
        self.vtree = sdd.vtree()  # type: Vtree
        self._wmc_cache = dict()  # type: Dict[SddNode, Union[float, int]]
        # Map Vtree node positions to expected variables
        self._expected_vars = None  # type: Optional[Dict[int, Set[int]]]
        # Map Sdd nodes to missing variables
        self._missing_vars = dict()  # type: Dict[SddNode, Set[int]]
        self.smooth = smooth  # type: bool
        self.smooth_to_root = smooth_to_root  # type: bool

        if self.smooth:
            self._cache_expected_vars()
Ejemplo n.º 8
0
def get_test_engine_factory(domain,
                            formula,
                            weight_function,
                            allow_rejection=True):
    if check_installation_pyxadd():
        return PyXaddEngine(domain, formula, weight_function)
    elif check_installation_pa():
        return PredicateAbstractionEngine(domain, formula, weight_function)
    elif allow_rejection:
        return RejectionEngine(domain, formula, weight_function,
                               TEST_SAMPLE_COUNT)
    else:
        raise InstallError()
Ejemplo n.º 9
0
def compile_to_sdd(formula: FNode, literals: LiteralInfo,
                   vtree: Optional[Vtree]) -> SddNode:
    """
    Compile a formula into an SDD.
    :param formula: The formula to represent as sdd. This formula must be a purely (abstracted) boolean formula
    (cf. extract_and_replace_literals(...) in literals.py)
    :param literals: The information of the literals in the formula
    :param vtree: The vtree to use. If None, a default vtree heuristic is used.
    :return: An SDD representing the given formula
    """
    if SddManager is None:
        raise InstallError(
            "The pysdd package is required for this function but is not currently installed."
        )
    if vtree is None:
        vtree = bami(literals)
    varnums = literals.numbered
    pysdd_vtree = vtree.to_pysdd(varnums)
    manager = SddManager.from_vtree(pysdd_vtree)
    converter = SddConversionWalker(manager, varnums)
    return converter.walk_smt(formula)
 def __init__(self):
     IntegrationBackend.__init__(self, exact=True)
     if psi is None:
         raise InstallError(
             "PiecewisePolynomialAlgebra requires the psi library to be installed"
         )
Ejemplo n.º 11
0
    def get_samples(self, n):
        raise NotImplementedError()

    def copy(self, domain, support, weight):
        return MPWMIEngine(domain, support, weight, cache=self.cache)

    def __str__(self):
        return "mpwmi" + (" w/cache" if self.cache else "")

    @staticmethod
    def compute_volumes(support, weight, queries=None, cache=False):
        solver = MPWMI(support, weight)
        return solver.compute_volumes(queries=queries, cache=cache)


if __name__ == "__main__":
    if MPWMI is None:
        raise InstallError("The pympwmi library is not in your PYTHONPATH")

    parser = ArgumentParser()
    parser.add_argument("filename", type=str)
    args = parser.parse_args()

    density = Density.from_file(args.filename)
    Z, vol_Q = MPWMIEngine.compute_volume_mpwmi(density.domain,
                                                density.support,
                                                density.weight)
    print(Z)
    print(vol_Q)
Ejemplo n.º 12
0
    with Solver() as solver:
        pysmt_installed = True
except NoSolverAvailableError:
    pysmt_installed = False

try:
    from wmipa.praiseinference import PRAiSEInference
except ImportError:
    lib_filename = os.path.join(os.path.dirname(__file__), "lib", "pa",
                                "wmi-pa-master")
    if os.path.exists(lib_filename):
        sys.path.append(lib_filename)
        try:
            from wmipa.praiseinference import PRAiSEInference
        except ImportError:
            raise InstallError("Corrupted PA install")
    else:
        PRAiSEInference = None

logger = logging.getLogger(__name__)


class PraiseEngine(Engine):
    def __init__(self, domain, support, weight):
        super().__init__(domain, support, weight)
        if not pysmt_installed:
            raise InstallError(
                "No PySMT solver is installed (not installed or not on path)")
        if PRAiSEInference is None:
            raise InstallError("The wmipa library is not in your PYTHONPATH")
 def __init__(self):
     super().__init__(True)
     if not shutil.which("integrate"):
         from pywmi.errors import InstallError
         raise InstallError("Latte (integrate) is not installed")
     self.algorithm = "--cone-decompose"