diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7ee042..c5e896e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: run: sudo dot -c - name: Install package and dependencies - run: uv sync --extra test --extra symbolic + run: uv sync --extra test --extra symbolic --extra global - name: Run tests env: diff --git a/CHANGELOG.md b/CHANGELOG.md index eb1af7c..6a91018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,26 @@ A second correctness review: every fix below was reproduced against a brute-force reference or a closed-form value and has a regression test. +### Restricted global bound (SCIP) + +- New `sofic.generators.global_bound`: `generator_global_bound(bidir, k)` minimizes the state entropy over the + coupled generator equations for `k` states with SCIP's spatial branch and bound (optional dependency, + `pip install sofic[global]`), with two-step path flows and the two-step edge law when the bidirectional edge + chain is known, sorted weights, optional caps and an objective limit. `lower` bounds the state entropy of + every generator with at most `k` states, and only those: it is a lower bound on `C_g` only once the number + of states of a minimal generator is bounded (open). It is numerical, not a certificate. Each entropy term is + evaluated at `max(pi_w, pi_min)`, and the overestimate (`k pi_min log2(1 / pi_min)`) is subtracted, so + states of tiny weight cannot slip under the bound. +- `hmm_generator_search(..., initial=[T])` polishes given `k`-state HMMs: their rounds keep the entropy term + off and move them to a nearby generator (from a near-generator, the entropy descent stalls at an infeasible + point). This turns a SCIP solution, which satisfies necessary conditions only, into a verified generator. +- `generative_model(..., global_bound=True, global_bound_states=k)` runs the bound after the belief-free + search (default `k = min(|S+|, |S-|) + 1`, half the remaining budget, the best candidate's entropy as + objective limit, models up to 2,000 variables), records `restricted_lower` and `restricted_states`, and + offers the polished solution as a candidate. `lower` and `certified` are unchanged. At + `(p, q) = (0.836, 0.788)` in the binary two-state family the bound at `k = 3` is 0.15563 (11 s), and the + polished solution is a generator of entropy 0.15571, 0.43 bits below `C_mu`. + ### Belief-free generator search - New `sofic.generators.hmm_search`: `hmm_generator_search(machine, k)` optimizes the symbol matrices of a diff --git a/docs/generators/generative_models.rst b/docs/generators/generative_models.rst index 5c82c8c..b5556d6 100644 --- a/docs/generators/generative_models.rst +++ b/docs/generators/generative_models.rst @@ -374,6 +374,36 @@ feeds them to :func:`~sofic.generators.generator_caps.generator_coverage_bound` on :math:`C_g` from the forward ε-machine alone. On the :math:`(2, \infty)` process a two-symbol window already gives :math:`C_g \ge 3/2`. +Restricted global bound +----------------------- + +:func:`~sofic.generators.global_bound.generator_global_bound` (optional dependency PySCIPOpt, +``pip install sofic[global]``) minimizes :math:`\H{\pi}` over the coupled generator equations for +``k`` states, written in the flows :math:`F(w, x, v) = \pi_w K(x, v \mid w)` and solved by SCIP's +spatial branch and bound :cite:`Achterberg2009,Vigerske2018` through PySCIPOpt :cite:`Maher2016`. +With the bidirectional edge chain it adds two-step path flows and the two-step edge law. The +weights are sorted, so caps on the heaviest states enter as linear cuts, and an objective limit +(the entropy of a verified generator) lets SCIP prune. The result bounds the state entropy of every +generator with at most ``k`` states and says nothing about larger ones. It is therefore a lower +bound on :math:`C_g` only once the number of states of a minimal generator is bounded, which is open +(every certified case so far needs at most :math:`|S^+| + 1` states). It is also numerical, not a +certificate: the equations with data on the right-hand side are relaxed by ``data_tol``, and SCIP +works to its own tolerances. SCIP's solution satisfies necessary conditions only; +:func:`~sofic.generators.hmm_search.hmm_generator_search` with ``initial`` polishes it into a +generator. On the binary process with symbol matrices +:math:`T^{(0)} = \begin{pmatrix} p & 0 \\ q & 0 \end{pmatrix}` and +:math:`T^{(1)} = \begin{pmatrix} 0 & 1 - p \\ 1 - q & 0 \end{pmatrix}` at +:math:`(p, q) = (0.836, 0.788)`, where :math:`C_\mu = 0.5866`, the bound at ``k = 3`` is +:math:`0.15563` (11 s), and the polished solution is a generator of entropy :math:`0.15571`: no +generator with at most 3 states does :math:`10^{-4}` bits better. + +The pipeline runs it with ``global_bound=True``, after the belief-free search, for +``global_bound_states`` states (default :math:`\min(|S^+|, |S^-|) + 1`). It gets half the remaining +budget (120 s without a budget) and the best candidate's entropy as its objective limit, and it is +skipped above 2,000 SCIP variables. The value goes to ``restricted_lower`` and ``restricted_states``, +not to ``lower``, so ``certified`` is unchanged; the polished solution is offered as a candidate. The +two-step flows and this restricted use are not from the literature. + API === @@ -397,6 +427,8 @@ Coupled generators and bounds .. autofunction:: sofic.generators.generative_search.resolve_bidirectional .. autofunction:: sofic.generators.hmm_search.hmm_generator_search .. autofunction:: sofic.generators.hmm_search.coupled_seed_from_hmm +.. autofunction:: sofic.generators.global_bound.generator_global_bound +.. autoclass:: sofic.generators.global_bound.GlobalBoundResult .. autoclass:: sofic.generators.generative_search.GenerativeModelResult :members: certified, gap, g_optima_generate .. autofunction:: sofic.generators.coverage_bound.coverage_entropy_lower diff --git a/docs/references.bib b/docs/references.bib index 2541bab..414df1c 100644 --- a/docs/references.bib +++ b/docs/references.bib @@ -1865,3 +1865,37 @@ @article{Ruebeck2018 year = {2018}, doi = {10.1063/1.5003041}, } + +@article{Achterberg2009, + author = {Achterberg, Tobias}, + title = {{SCIP}: Solving Constraint Integer Programs}, + journal = {Mathematical Programming Computation}, + volume = {1}, + number = {1}, + pages = {1--41}, + year = {2009}, + doi = {10.1007/s12532-008-0001-1}, +} + +@article{Vigerske2018, + author = {Vigerske, Stefan and Gleixner, Ambros}, + title = {{SCIP}: Global Optimization of Mixed-Integer Nonlinear Programs in a Branch-and-Cut Framework}, + journal = {Optimization Methods and Software}, + volume = {33}, + number = {3}, + pages = {563--593}, + year = {2018}, + doi = {10.1080/10556788.2017.1335312}, +} + +@inproceedings{Maher2016, + author = {Maher, Stephen and Miltenberger, Matthias and Pedroso, Jo{\~a}o Pedro and Rehfeldt, Daniel and Schwarz, Robert and Serrano, Felipe}, + title = {{PySCIPOpt}: Mathematical Programming in {Python} with the {SCIP} Optimization Suite}, + booktitle = {Mathematical Software -- {ICMS} 2016}, + series = {Lecture Notes in Computer Science}, + volume = {9725}, + pages = {301--307}, + publisher = {Springer}, + year = {2016}, + doi = {10.1007/978-3-319-42432-3_37}, +} diff --git a/pyproject.toml b/pyproject.toml index 8fda9fe..acf1e4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ docs = [ "sofic[symbolic]", ] dev = [ - "sofic[test,viz,capacity]", + "sofic[test,viz,capacity,global]", "sofic[docs]", "ruff", "ty", @@ -78,6 +78,9 @@ sat = [ capacity = [ "cvxpy>=1.4", ] +global = [ + "pyscipopt>=5", +] symbolic = [ "sympy>=1.12", "dit[symbolic]>=2.4", @@ -208,6 +211,8 @@ allowed-unresolved-imports = [ "sympy.**", "pysat", "pysat.**", + "pyscipopt", + "pyscipopt.**", ] [tool.ty.rules] diff --git a/sofic/generators/generative_search.py b/sofic/generators/generative_search.py index 765ccaf..680351f 100644 --- a/sofic/generators/generative_search.py +++ b/sofic/generators/generative_search.py @@ -27,6 +27,11 @@ (:func:`~sofic.generators.exact_ci_bounds.generator_heaviest_term_bound`, ``generator_heaviest_term``) aims at the verified upper bound with the rest of the budget, on joints with at most 14 causal states (7 without a budget, where it is capped at 2,000 boxes). +6. *Restricted global bound* (opt-in, ``global_bound``; runs after the belief-free search). SCIP's lower bound + on the state entropy of generators with at most ``global_bound_states`` states + (:func:`~sofic.generators.global_bound.generator_global_bound`) is reported as ``restricted_lower``. It does + not enter ``lower``: no bound on the number of states of a minimal generator is known. SCIP's solution, + polished by the belief-free search, is offered as a candidate. Every candidate is word-verified. ``certified`` reports when ``lower`` meets ``upper``. :func:`minimal_wyner_model` runs the same stages ranked by :math:`\I{W : S^+, S^-}`; the functional @@ -95,6 +100,12 @@ # are worth it (900 s raised the bound on 3 x 5 to 3 x 11 joints of the binary 3-state dataset too). _GENERATOR_HEAVIEST_TERM_NODES = 2_000 _GENERATOR_HEAVIEST_TERM_MAX_DIMS = 14 +# The restricted global bound runs only on SCIP models up to this many variables (two-step flows included; +# 3-state binary processes at 4 states have about 1,200), and for this many seconds when there is no budget. +_GLOBAL_BOUND_MAX_VARS = 2_000 +_GLOBAL_BOUND_SECONDS = 120.0 +# SCIP solution states lighter than this are dropped before the belief-free polish. +_GLOBAL_BOUND_MIN_WEIGHT = 1e-6 def _entropy(p: np.ndarray) -> float: @@ -127,6 +138,10 @@ class GenerativeModelResult: ``decomposition`` holds the generator itself as plain lists, for saving and later study: state names (as in ``model``), forward and reverse causal-state labels, symbols, weights ``pi``, beliefs ``Q`` (over :math:`S^+`) and ``R`` (over :math:`S^-`), and the kernel ``K[w][x][w']``. + + ``restricted_lower`` (set by the opt-in ``global_bound`` stage) bounds the state entropy of generators with at + most ``restricted_states`` states only (:func:`~sofic.generators.global_bound.generator_global_bound`). It is + numerical, and it is not part of ``lower`` or ``certified``: a minimal generator might have more states. """ model: CoupledGenerativeModel @@ -147,6 +162,8 @@ class GenerativeModelResult: reproduction_error: float | None = None structure: dict[str, Any] | None = None decomposition: dict[str, Any] | None = None + restricted_lower: float | None = None + restricted_states: int | None = None @property def certified(self) -> bool: @@ -183,6 +200,8 @@ def _reliability_summary(result: GenerativeModelResult) -> dict[str, Any]: "budget_exhausted": result.budget_exhausted, "reproduction_error": result.reproduction_error, "structure": result.structure, + "restricted_lower": result.restricted_lower, + "restricted_states": result.restricted_states, } @@ -424,6 +443,8 @@ def _bracket_search( generator_heaviest_term: bool = True, hmm_search: bool = True, hmm_search_starts: int = 8, + global_bound: bool = False, + global_bound_states: int | None = None, generator_caps: int = 2, targeted: bool = True, entropy_sweep_starts: int = 80, @@ -896,6 +917,49 @@ def maybe_return_early() -> GenerativeModelResult | None: found += 1 log.append({"stage": "belief-free HMM search", "k": list(ks), "starts": n_starts, "generators": found}) + restricted_lower: float | None = None + restricted_states: int | None = None + if global_bound and not wyner and not out_of_time("restricted global bound"): + from sofic.generators.global_bound import _model_size, generator_global_bound + + k = global_bound_states if global_bound_states is not None else min(problem.n_plus, problem.n_minus) + 1 + size = _model_size(problem, k) + stage_deadline = share(0.5) + limit = min((c[0] for c in candidates), default=None) + if size > _GLOBAL_BOUND_MAX_VARS: + log.append({"stage": "restricted global bound", "k": k, "skipped": f"{size} SCIP variables"}) + else: + seconds = _GLOBAL_BOUND_SECONDS if stage_deadline is None else stage_deadline - time.monotonic() + try: + gb = generator_global_bound(problem, k, objective_limit=limit, time_limit=seconds) + except ImportError as exc: + log.append({"stage": "restricted global bound", "k": k, "skipped": str(exc)}) + else: + restricted_lower, restricted_states = gb.lower, k + log.append( + { + "stage": "restricted global bound", + "k": k, + "value": gb.lower, + "status": gb.status, + "objective limit": limit, + "two-step": gb.two_step, + "nodes": gb.nodes, + "seconds": gb.seconds, + } + ) + if gb.seed is not None: + pi, _, _, K = gb.seed + keep = np.flatnonzero(pi > _GLOBAL_BOUND_MIN_WEIGHT) + T = [K[:, x, :][np.ix_(keep, keep)] for x in range(K.shape[1])] + rows = sum(T).sum(axis=1, keepdims=True) + polished = hmm_generator_search( + reference, len(keep), starts=0, initial=[[M / rows for M in T]], deadline=deadline + ) + name = f"polished global-bound solution k={len(keep)}" + for res in polished: + offer(name, coupled_seed_from_hmm(problem, res.matrices)) + best_value = min((c[0] for c in candidates), default=np.inf) if targeted and optima and best_value - lower > _TARGETED_GAP and not out_of_time("targeted line-split search"): seeds = targeted_line_split_seeds(problem, optima, residual_atol=residual_atol, deadline=share(0.8), rng=rng) @@ -922,6 +986,7 @@ def maybe_return_early() -> GenerativeModelResult | None: ) if result is None: raise StochasticValidationError(f"{objective} generator search: no candidate reproduced the source process") + result.restricted_lower, result.restricted_states = restricted_lower, restricted_states # last, so it aims at the verified upper bound and gets the whole remaining budget max_dims = _HEAVIEST_TERM_MAX_DIMS if deadline is None else _GENERATOR_HEAVIEST_TERM_MAX_DIMS if ( @@ -973,6 +1038,8 @@ def generative_model_from_bidirectional( generator_heaviest_term: bool = True, hmm_search: bool = True, hmm_search_starts: int = 8, + global_bound: bool = False, + global_bound_states: int | None = None, generator_caps: int = 2, targeted: bool = True, entropy_sweep_starts: int = 80, @@ -985,7 +1052,12 @@ def generative_model_from_bidirectional( time_budget: float | None = None, rng: np.random.Generator | None = None, ) -> GenerativeModelResult: - """Run the generator-search pipeline on an existing bidirectional machine; see the module docstring.""" + """Run the generator-search pipeline on an existing bidirectional machine; see the module docstring. + + ``global_bound`` (needs PySCIPOpt, ``pip install sofic[global]``) adds the restricted global bound for + generators with at most ``global_bound_states`` states (default :math:`\\min(|S^+|, |S^-|) + 1`), reported as + ``restricted_lower``; see :class:`GenerativeModelResult`. + """ return _bracket_search( bidir, objective="entropy", @@ -1005,6 +1077,8 @@ def generative_model_from_bidirectional( generator_heaviest_term=generator_heaviest_term, hmm_search=hmm_search, hmm_search_starts=hmm_search_starts, + global_bound=global_bound, + global_bound_states=global_bound_states, generator_caps=generator_caps, targeted=targeted, entropy_sweep_starts=entropy_sweep_starts, @@ -1103,6 +1177,8 @@ def generative_model( generator_heaviest_term: bool = True, hmm_search: bool = True, hmm_search_starts: int = 8, + global_bound: bool = False, + global_bound_states: int | None = None, generator_caps: int = 2, targeted: bool = True, entropy_sweep_starts: int = 80, @@ -1129,6 +1205,7 @@ def generative_model( The check runs between stages (and between line-split seeds and coupled-search sizes), so a single long stage can overrun it. The bidirectional build's retry ladder counts against the budget (see :func:`~sofic.generators.bidirectional_build.build_bidirectional_with_ladder`). + ``global_bound`` and ``global_bound_states`` are as in :func:`generative_model_from_bidirectional`. """ start = time.monotonic() bidir, build_meta = resolve_bidirectional( @@ -1154,6 +1231,8 @@ def generative_model( generator_heaviest_term=generator_heaviest_term, hmm_search=hmm_search, hmm_search_starts=hmm_search_starts, + global_bound=global_bound, + global_bound_states=global_bound_states, generator_caps=generator_caps, targeted=targeted, entropy_sweep_starts=entropy_sweep_starts, diff --git a/sofic/generators/global_bound.py b/sofic/generators/global_bound.py new file mode 100644 index 0000000..9fde3a2 --- /dev/null +++ b/sofic/generators/global_bound.py @@ -0,0 +1,273 @@ +r"""Restricted global lower bound: the least state entropy of generators with at most ``k`` states. + +Every generator with states :math:`w`, weights :math:`\pi_w`, causal-state beliefs :math:`Q_w` (over +:math:`S^+`) and :math:`R_w` (over :math:`S^-`) and kernel :math:`K(x, v \mid w)` satisfies the one-step coupled +generator equations of :mod:`~sofic.generators.coupled_generators`. In terms of the flows +:math:`F(w, x, v) = \pi_w K(x, v \mid w)` they read + +.. math:: + + \sum_{x, v} F(w, x, v) = \pi_w = \sum_{u, x} F(u, x, w), \qquad + \sum_w \pi_w Q_w R_w^\top = P, \qquad + \sum_{w, v} F(w, x, v)\, Q_w(a) R_v(b) = \Pr(S^+_0 = a, X_0 = x, S^-_1 = b), + +together with forward stationarity of :math:`\pi_w Q_w` and reverse consistency of :math:`\pi_w R_w`. When the +problem carries the bidirectional edge chain, two-step path flows +:math:`V(w, x, v, y, u) = \pi_w K(x, v \mid w) K(y, u \mid v)` add :math:`V \pi_v = F(w, x, v) F(v, y, u)`, their +marginals, and the two-step edge law :math:`\sum V\, Q_w(a) R_u(b) = \Pr(S^+_0 = a, X_0 X_1 = x y, S^-_2 = b)`. +All of these are necessary for a generator, not sufficient. :func:`generator_global_bound` minimizes +:math:`\H{\pi}` over them with SCIP's spatial branch and bound :cite:`Achterberg2009,Vigerske2018` through +PySCIPOpt :cite:`Maher2016`. Its dual bound therefore bounds the state entropy of every generator with at most +``k`` states from below; it says nothing about larger generators, so it is a lower bound on the generative +complexity :math:`C_g` only once a bound on the number of states of a minimal generator is known (open; every +certified case so far needs at most :math:`|S^+| + 1`). The two-step flows and this restricted use are not from +the literature. + +The bound is numerical, not a certificate: the data are floats, the equations with data on the right-hand side +are relaxed to ``|lhs - rhs| <= data_tol`` (which only enlarges the feasible set), and SCIP works to its own +feasibility tolerances. PySCIPOpt is an optional dependency (``pip install sofic[global]``). +""" + +from __future__ import annotations + +import math +import time +from collections.abc import Sequence +from dataclasses import dataclass +from typing import Any + +import numpy as np + +from sofic.generators.bidirectional_epsilon_machine import BidirectionalEpsilonMachine +from sofic.generators.coupled_generators import _GeneratorProblem + +__all__ = ["GlobalBoundResult", "generator_global_bound"] + + +@dataclass(frozen=True) +class GlobalBoundResult: + """Outcome of :func:`generator_global_bound`. + + ``lower`` bounds the state entropy of every generator with at most ``k`` states (and only those): the SCIP + dual bound minus ``slack``, or ``objective_limit - slack`` when SCIP proves that no point of the equations has + entropy below the limit (``status == "infeasible"``); it is ``inf`` when the equations have no solution at all + (no generator with at most ``k`` states). ``primal`` and ``seed`` (``(pi, Q, R, K)``, with + ``K[w, x, v] = F(w, x, v) / pi_w``) describe SCIP's best solution, which solves the necessary equations only + and must be verified (or polished with :func:`~sofic.generators.hmm_search.hmm_generator_search`, whose + ``initial`` argument takes its symbol matrices) before it counts as a generator. ``two_step`` records whether + the two-step flows were used. + """ + + k: int + status: str + lower: float + dual_bound: float + slack: float + primal: float | None + seed: tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray] | None + nodes: int + seconds: float + two_step: bool + + +def _pyscipopt() -> Any: + try: + import pyscipopt + except ImportError as exc: + raise ImportError( + "generator_global_bound needs PySCIPOpt; install it with `pip install sofic[global]`" + ) from exc + return pyscipopt + + +def _two_step_law(problem: _GeneratorProblem) -> np.ndarray | None: + """``Pe2[x, y, a, b] = Pr(S+_0 = a, X_0 X_1 = x y, S-_2 = b)`` from the bidirectional edge chain, if known.""" + lifted = problem.lifted + edges = getattr(lifted, "edges", None) + if edges is None: + return None + step = edges / np.maximum(lifted.p, 1e-300)[:, None, None] + ns = edges.shape[1] + out = np.empty((ns, ns, lifted.plus.shape[1], lifted.minus.shape[1])) + for x in range(ns): + for y in range(ns): + out[x, y] = lifted.plus.T @ edges[:, x, :] @ step[:, y, :] @ lifted.minus + return out + + +def _model_size(problem: _GeneratorProblem, k: int, *, two_step: bool = True) -> int: + """Number of SCIP variables :func:`generator_global_bound` creates for ``problem`` and ``k`` states.""" + na, nb, ns = problem.n_plus, problem.n_minus, problem.n_sym + n = k * (3 + 2 * (na + nb)) + k * ns * k * (1 + na) + if two_step and getattr(problem.lifted, "edges", None) is not None: + n += k * ns * k * ns * k * (1 + na) + return n + + +def generator_global_bound( + bidir: BidirectionalEpsilonMachine | _GeneratorProblem, + k: int, + *, + objective_limit: float | None = None, + two_step: bool = True, + caps: Sequence[float] = (), + time_limit: float | None = None, + data_tol: float = 1e-7, + pi_min: float = 1e-7, +) -> GlobalBoundResult: + r"""Lower bound on the state entropy of generators with at most ``k`` states, by SCIP global optimization. + + Builds the coupled generator equations (see the module docstring) for ``k`` states, with the two-step flows + when ``two_step`` is set and ``bidir`` carries the bidirectional edge chain, and minimizes the state entropy + with SCIP. Generators with fewer than ``k`` states are covered (their missing states get weight 0). The + weights are sorted, so the optional ``caps`` (valid caps on the total weight of the ``j`` heaviest states of + any generator, e.g. those of :func:`~sofic.generators.generator_caps.generator_coverage_bound`) become + linear cuts. Each entropy term is evaluated at :math:`\max(\pi_w, \text{pi\_min})`, which overestimates it by + at most :math:`\text{pi\_min} \log_2(1/\text{pi\_min})`; ``slack`` (``k`` times that) is subtracted. + + ``objective_limit`` (e.g. the entropy of a verified generator) lets SCIP prune everything above it; when it + then reports ``"infeasible"``, no generator with at most ``k`` states has entropy below + ``objective_limit - slack``. ``time_limit`` (seconds) stops SCIP early; the dual bound reached is still valid. + The result is numerical, not a certificate, and says nothing about generators with more than ``k`` states; + see :class:`GlobalBoundResult`. + + Requires PySCIPOpt (``pip install sofic[global]``). + """ + scip = _pyscipopt() + start = time.monotonic() + problem = bidir if isinstance(bidir, _GeneratorProblem) else _GeneratorProblem(bidir) + lifted = problem.lifted + P = lifted.plus.T @ (problem.p_pair[:, None] * lifted.minus) + P = P / P.sum() + Pe, fwd, rev = np.asarray(problem.Pe, float), np.asarray(problem.F) > 0, np.asarray(problem.G) > 0 + pp, pm = np.asarray(problem.p_plus, float), np.asarray(problem.p_minus, float) + na, nb, ns = P.shape[0], P.shape[1], Pe.shape[1] + Pe2 = _two_step_law(problem) if two_step else None + W, X, A, B = range(k), range(ns), range(na), range(nb) + quicksum = scip.quicksum + + m = scip.Model() + m.hideOutput() + + def data_eq(lhs: Any, rhs: float) -> None: + m.addCons(lhs <= rhs + data_tol) + m.addCons(lhs >= rhs - data_tol) + + pi = {w: m.addVar(lb=0, ub=1) for w in W} + s = {w: m.addVar(lb=pi_min, ub=1) for w in W} # max(pi_w, pi_min), the argument of the entropy term + e = {w: m.addVar(lb=0, ub=1 / (math.e * math.log(2)) + 1e-9) for w in W} + Q = {(w, a): m.addVar(lb=0, ub=1) for w in W for a in A} + R = {(w, b): m.addVar(lb=0, ub=1) for w in W for b in B} + Y = {(w, a): m.addVar(lb=0, ub=float(pp[a])) for w in W for a in A} + Z = {(w, b): m.addVar(lb=0, ub=float(pm[b])) for w in W for b in B} + F = {(w, x, v): m.addVar(lb=0, ub=1) for w in W for x in X for v in W} + FQ = {(w, x, v, a): m.addVar(lb=0, ub=1) for w in W for x in X for v in W for a in A} + + m.addCons(quicksum(pi.values()) == 1) + for w in W: + m.addCons(s[w] >= pi[w]) + m.addCons(s[w] <= pi[w] + pi_min) + m.addCons(e[w] >= -s[w] * scip.log(s[w]) / math.log(2)) + m.addCons(quicksum(Q[w, a] for a in A) == 1) + m.addCons(quicksum(R[w, b] for b in B) == 1) + m.addCons(quicksum(Y[w, a] for a in A) == pi[w]) + m.addCons(quicksum(Z[w, b] for b in B) == pi[w]) + for a in A: + m.addCons(Y[w, a] == pi[w] * Q[w, a]) + for b in B: + m.addCons(Z[w, b] == pi[w] * R[w, b]) + m.addCons(quicksum(F[w, x, v] for x in X for v in W) == pi[w]) + m.addCons(quicksum(F[u, x, w] for u in W for x in X) == pi[w]) + if w + 1 < k: + m.addCons(pi[w] >= pi[w + 1]) + for w in W: + for x in X: + for v in W: + m.addCons(quicksum(FQ[w, x, v, a] for a in A) == F[w, x, v]) + for a in A: + m.addCons(FQ[w, x, v, a] == F[w, x, v] * Q[w, a]) + for a in A: + data_eq(quicksum(Y[w, a] for w in W), float(pp[a])) + for b in B: + data_eq(quicksum(Z[w, b] for w in W), float(pm[b])) + for a in A: + for b in B: + data_eq(quicksum(Y[w, a] * R[w, b] for w in W), float(P[a, b])) + data_eq(quicksum(Q[w, a] * Z[w, b] for w in W), float(P[a, b])) + for a in A: + for x in X: + for b in B: + data_eq(quicksum(FQ[w, x, v, a] * R[v, b] for w in W for v in W), float(Pe[a, x, b])) + for v in W: # forward stationarity: S+_1 is a function of (S+_0, X_0) + for a2 in A: + src = [(a, x) for a in A for x in X if fwd[a, x, a2]] + m.addCons(Y[v, a2] == quicksum(FQ[w, x, v, a] for a, x in src for w in W)) + for w in W: # reverse consistency: S-_0 is a function of (X_0, S-_1) + for b in B: + tgt = [(x, c) for x in X for c in B if rev[x, c, b]] + m.addCons(Z[w, b] == quicksum(F[w, x, v] * R[v, c] for x, c in tgt for v in W)) + for j, cap in enumerate(list(caps)[:k]): + m.addCons(quicksum(pi[w] for w in range(j + 1)) <= float(cap)) + if Pe2 is not None: + V = {(w, x, v, y, u): m.addVar(lb=0, ub=1) for w in W for x in X for v in W for y in X for u in W} + VQ = {(*key, a): m.addVar(lb=0, ub=1) for key in V for a in A} + for w in W: + for x in X: + for v in W: + m.addCons(quicksum(V[w, x, v, y, u] for y in X for u in W) == F[w, x, v]) + for y in X: + for u in W: + # the hidden chain is Markov: Pr(w, x, v, y, u) pi_v = Pr(w, x, v) Pr(v, y, u) + m.addCons(V[w, x, v, y, u] * pi[v] == F[w, x, v] * F[v, y, u]) + m.addCons(quicksum(VQ[w, x, v, y, u, a] for a in A) == V[w, x, v, y, u]) + for a in A: + m.addCons(VQ[w, x, v, y, u, a] == V[w, x, v, y, u] * Q[w, a]) + for v in W: + for y in X: + for u in W: + m.addCons(quicksum(V[w, x, v, y, u] for w in W for x in X) == F[v, y, u]) + for x in X: + for y in X: + for a in A: + for b in B: + data_eq( + quicksum(VQ[w, x, v, y, u, a] * R[u, b] for w in W for v in W for u in W), + float(Pe2[x, y, a, b]), + ) + m.setObjective(quicksum(e.values()), "minimize") + if objective_limit is not None: + m.setObjlimit(float(objective_limit)) + if time_limit is not None: + m.setParam("limits/time", max(1.0, float(time_limit))) + m.optimize() + + status = str(m.getStatus()) + slack = k * pi_min * math.log2(1 / pi_min) + dual = float(m.getDualbound()) + dual = math.inf if dual >= m.infinity() else -math.inf if dual <= -m.infinity() else dual + if status == "infeasible": + lower = math.inf if objective_limit is None else float(objective_limit) - slack + else: + lower = (dual if objective_limit is None else min(dual, float(objective_limit))) - slack + primal, seed = None, None + if m.getNSols() > 0: + primal = float(m.getPrimalbound()) + sol = m.getBestSol() + pi_v = np.clip([m.getSolVal(sol, pi[w]) for w in W], 0, None) + Q_v = np.clip([[m.getSolVal(sol, Q[w, a]) for a in A] for w in W], 0, None) + R_v = np.clip([[m.getSolVal(sol, R[w, b]) for b in B] for w in W], 0, None) + F_v = np.clip([[[m.getSolVal(sol, F[w, x, v]) for v in W] for x in X] for w in W], 0, None) + K_v = F_v / np.maximum(F_v.sum(axis=(1, 2), keepdims=True), 1e-300) + seed = (pi_v / pi_v.sum(), Q_v, R_v, K_v) + return GlobalBoundResult( + k=k, + status=status, + lower=float(lower), + dual_bound=dual, + slack=slack, + primal=primal, + seed=seed, + nodes=int(m.getNNodes()), + seconds=time.monotonic() - start, + two_step=Pe2 is not None, + ) diff --git a/sofic/generators/hmm_search.py b/sofic/generators/hmm_search.py index 812435c..084db00 100644 --- a/sofic/generators/hmm_search.py +++ b/sofic/generators/hmm_search.py @@ -18,6 +18,7 @@ import itertools import time +from collections.abc import Sequence from dataclasses import dataclass from typing import Any @@ -26,6 +27,9 @@ __all__ = ["HMMSearchResult", "coupled_seed_from_hmm", "hmm_generator_search"] +# Zero entries of a given start are raised to this before taking logits (log 0 is not a logit). +_INITIAL_FLOOR = 1e-8 + @dataclass(frozen=True) class HMMSearchResult: @@ -88,6 +92,16 @@ def _target_words(machine: Any, tree: _WordTree) -> np.ndarray: return tree.forward(T, pi).sum(axis=1) +def _logits(matrices: Sequence[np.ndarray], k: int, ns: int, floor: float) -> np.ndarray: + """Softmax logits (the inverse of :func:`_unpack`) of ``k``-state symbol matrices, entries floored first.""" + T = [np.asarray(M, float) for M in matrices] + if len(T) != ns or any(M.shape != (k, k) for M in T): + raise ValueError(f"initial generator must have {ns} symbol matrices of shape ({k}, {k})") + E = np.concatenate([np.maximum(M, floor) for M in T], axis=1) + E /= E.sum(axis=1, keepdims=True) + return np.log(E).ravel() + + def _unpack(theta: np.ndarray, k: int, ns: int) -> tuple[list[np.ndarray], np.ndarray]: L = theta.reshape(k, ns * k) E = np.exp(L - L.max(axis=1, keepdims=True)) @@ -133,6 +147,7 @@ def hmm_generator_search( k: int, *, starts: int = 8, + initial: Sequence[Sequence[np.ndarray]] = (), rng: np.random.Generator | None = None, deadline: float | None = None, rounds: int = 12, @@ -141,7 +156,12 @@ def hmm_generator_search( """Low-entropy ``k``-state generators of the process of ``machine`` (its forward ε-machine), best first. Each of ``starts`` random starts reaches a generator with no entropy term, then descends in :math:`H[\\pi]` - under the augmented Lagrangian (``rounds`` outer updates). Only end points whose largest word residual is at + under the augmented Lagrangian (``rounds`` outer updates). ``initial`` adds starts from given ``k``-state HMMs + (each a sequence of symbol matrices in symbol order), run before the random ones. Such a start is an + approximate generator to be polished, for instance the solution of + :func:`~sofic.generators.global_bound.generator_global_bound`: its rounds keep the entropy term off, so it + moves to a nearby generator instead of descending (from a near-generator, the descent stalls at an infeasible + point). A result's ``start`` counts the initial starts first. Only end points whose largest word residual is at most ``feasibility_tol`` are returned; callers should still verify them exactly (the pipeline does). ``deadline`` is a :func:`time.monotonic` value checked between starts and rounds. """ @@ -150,14 +170,16 @@ def hmm_generator_search( rng = rng if rng is not None else np.random.default_rng() mats = symbol_matrices(machine.to_mealy() if hasattr(machine, "to_mealy") else machine) ns, n = len(mats), next(iter(mats.values())).shape[0] + given = [_logits(T, k, ns, _INITIAL_FLOOR) for T in initial] tree = _WordTree(ns, k + n) target = _target_words(machine, tree) opts = {"maxiter": 3000, "ftol": 1e-16, "gtol": 1e-12} out = [] - for start in range(starts): + for start in range(len(given) + starts): if deadline is not None and time.monotonic() >= deadline: break - theta = rng.normal(size=k * ns * k) + theta = given[start] if start < len(given) else rng.normal(size=k * ns * k) + weight = 0.0 if start < len(given) else 1.0 lam = np.zeros(len(target)) args = (k, ns, tree, target) theta = minimize(_objective, theta, args=(*args, lam, 10.0, 0.0), jac=True, method="L-BFGS-B", options=opts).x @@ -165,7 +187,9 @@ def hmm_generator_search( for _ in range(rounds): if deadline is not None and time.monotonic() >= deadline: break - theta = minimize(_objective, theta, args=(*args, lam, mu, 1.0), jac=True, method="L-BFGS-B", options=opts).x + theta = minimize( + _objective, theta, args=(*args, lam, mu, weight), jac=True, method="L-BFGS-B", options=opts + ).x T, _ = _unpack(theta, k, ns) pi = _stationary(sum(T)) lam = lam + mu * (tree.forward(T, pi).sum(axis=1) - target) diff --git a/tests/test_global_bound.py b/tests/test_global_bound.py new file mode 100644 index 0000000..d831291 --- /dev/null +++ b/tests/test_global_bound.py @@ -0,0 +1,121 @@ +"""Restricted global lower bound (SCIP) on the state entropy of generators with at most ``k`` states.""" + +from __future__ import annotations + +import math +import sys + +import numpy as np +import pytest + +from sofic.generators import global_bound as gb +from sofic.generators import hmm_search as hs + + +@pytest.fixture +def scip(): + return pytest.importorskip("pyscipopt") + + +def _two_state(p, q): + from sofic.examples.epsilon_machines import from_symbol_matrices + from sofic.generators.epsilon_machine import EpsilonMachine + + m = from_symbol_matrices((0, 1), (0, 1), {0: np.array([[p, 0], [q, 0]]), 1: np.array([[0, 1 - p], [1 - q, 0]])}) + return m if isinstance(m, EpsilonMachine) else EpsilonMachine.from_hmm(m) + + +def _bidir(forward): + from sofic.generators.bidirectional_epsilon_machine import BidirectionalEpsilonMachine + + return BidirectionalEpsilonMachine.from_forward(forward) + + +def _h(p): + p = np.asarray(p, float) + p = p[p > 0] + return float(-(p * np.log2(p)).sum()) + + +GOLDEN_MEAN = (0.5, 1.0) +C_MU_GOLDEN = _h([2 / 3, 1 / 3]) + + +def test_golden_mean_bound_is_the_statistical_complexity(scip) -> None: + bidir = _bidir(_two_state(*GOLDEN_MEAN)) + one = gb.generator_global_bound(bidir, 1) + assert one.status == "infeasible" and one.lower == math.inf # the golden mean is not i.i.d. + two = gb.generator_global_bound(bidir, 2) + assert two.status == "optimal" and two.two_step + assert C_MU_GOLDEN - 1e-4 <= two.lower <= C_MU_GOLDEN + 1e-9 + assert two.lower == pytest.approx(two.dual_bound - two.slack) + + +def test_objective_limit_semantics(scip) -> None: + bidir = _bidir(_two_state(*GOLDEN_MEAN)) + below = gb.generator_global_bound(bidir, 2, objective_limit=C_MU_GOLDEN - 0.01) + assert below.status == "infeasible" and below.seed is None + assert below.lower == pytest.approx(C_MU_GOLDEN - 0.01 - below.slack) + above = gb.generator_global_bound(bidir, 2, objective_limit=C_MU_GOLDEN + 0.03) + assert above.status == "optimal" and above.seed is not None + assert C_MU_GOLDEN - 1e-4 <= above.lower <= C_MU_GOLDEN + 1e-9 + assert above.primal == pytest.approx(C_MU_GOLDEN, abs=1e-4) + + +def test_pattern_c_point_bound_and_polish(scip) -> None: + """At (p, q) = (0.836, 0.788) a 3-state generator of entropy H(1 - 2y, y, y) beats C_mu by 0.43 bits.""" + from sofic.generators.coupled_generators import CoupledSearchResult, _GeneratorProblem, _model_from_kernel + from sofic.generators.minimal_generative_model import _equivalence_error + + p, q = 0.836, 0.788 + y = (1 - p) * (p - q) / ((2 - p) * (p * q + p - q)) + h_c = _h([1 - 2 * y, y, y]) + forward = _two_state(p, q) + problem = _GeneratorProblem(_bidir(forward)) + res = gb.generator_global_bound(problem, 3, time_limit=300) + assert res.status == "optimal" + assert h_c - 2e-4 <= res.lower <= h_c + pi, _, _, K = res.seed + T = [K[:, x, :] for x in range(K.shape[1])] + polished = hs.hmm_generator_search(forward, 3, starts=0, initial=[T]) + assert polished and polished[0].entropy == pytest.approx(h_c, abs=1e-5) + seed = hs.coupled_seed_from_hmm(problem, polished[0].matrices) + model = _model_from_kernel(problem, CoupledSearchResult(*seed, polished[0].entropy, 0.0, "t"), 1e-12) + assert _equivalence_error(model, forward) < 1e-6 + + +def _pipeline(bidir, **kwargs): + from sofic.generators.generative_search import generative_model_from_bidirectional + + return generative_model_from_bidirectional( + bidir, + stages=("machines",), + coverage="off", + generator_heaviest_term=False, + early_certified=False, + rng=np.random.default_rng(0), + **kwargs, + ) + + +def test_pipeline_records_the_restricted_bound_only(scip) -> None: + bidir = _bidir(_two_state(*GOLDEN_MEAN)) + off = _pipeline(bidir) + on = _pipeline(bidir, global_bound=True, global_bound_states=2) + assert off.restricted_lower is None and off.restricted_states is None + assert on.restricted_states == 2 + assert C_MU_GOLDEN - 1e-4 <= on.restricted_lower <= on.upper + 1e-9 + assert (on.lower, on.lower_source, on.certified) == (off.lower, off.lower_source, off.certified) + summary = on.stages[-1] + assert summary["stage"] == "reliability summary" and summary["restricted_states"] == 2 + assert any(s["stage"] == "restricted global bound" and "value" in s for s in on.stages) + + +def test_missing_pyscipopt(monkeypatch) -> None: + monkeypatch.setitem(sys.modules, "pyscipopt", None) + bidir = _bidir(_two_state(*GOLDEN_MEAN)) + with pytest.raises(ImportError, match=r"sofic\[global\]"): + gb.generator_global_bound(bidir, 2) + result = _pipeline(bidir, global_bound=True) + assert result.restricted_lower is None + assert any(s["stage"] == "restricted global bound" and "skipped" in s for s in result.stages) diff --git a/tests/test_hmm_search.py b/tests/test_hmm_search.py index dbd0ced..f5c1e0d 100644 --- a/tests/test_hmm_search.py +++ b/tests/test_hmm_search.py @@ -82,6 +82,22 @@ def h(p): assert res.entropy >= excess - 1e-9 # every generator carries at least the excess entropy +def test_initial_start_recovers_a_perturbed_generator() -> None: + from sofic.generators.matrices import symbol_matrices + + forward = _two_state() + mats = symbol_matrices(forward.to_mealy()) + T = [np.asarray(mats[x], float) for x in sorted(mats)] + rng = np.random.default_rng(0) + noisy = [M * np.exp(rng.normal(scale=0.05, size=M.shape)) for M in T] + rows = sum(noisy).sum(axis=1, keepdims=True) + results = hs.hmm_generator_search(forward, 2, starts=0, initial=[[M / rows for M in noisy]]) + assert [res.start for res in results] == [0] + assert max(np.abs(A - B).max() for A, B in zip(results[0].matrices, T, strict=True)) < 1e-6 + with pytest.raises(ValueError, match="symbol matrices of shape"): + hs.hmm_generator_search(forward, 3, starts=0, initial=[T]) + + @pytest.mark.slow def test_search_beats_the_epsilon_machine_on_n3_t122_d2() -> None: forward = _dataset_n3_t122_d2() diff --git a/uv.lock b/uv.lock index cb49f70..46e1ce1 100644 --- a/uv.lock +++ b/uv.lock @@ -1955,6 +1955,52 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/10/bd/c038d7cc38edc1aa5bf91ab8068b63d4308c66c4c8bb3cbba7dfbc049f9c/pyparsing-3.3.2-py3-none-any.whl", hash = "sha256:850ba148bd908d7e2411587e247a1e4f0327839c40e2e5e6d05a007ecc69911d", size = 122781, upload-time = "2026-01-21T03:57:55.912Z" }, ] +[[package]] +name = "pyscipopt" +version = "6.3.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "numpy" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/d0/7c/0021484212345deca8db57f96f450c60db0f357cfb8c8ee9ea831942deb0/pyscipopt-6.3.0.tar.gz", hash = "sha256:d9d1d36ed916b1ce1129627055145014b93f66711f8d974fdab941773d8d0adb", size = 1945537, upload-time = "2026-10-11T16:14:52.409Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0f/91/35f82fd9e44c627549f0d1c49cc2ed7ed12fedc41bd628fac7d551551abe/pyscipopt-6.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:8cbda985a4ae8635aa3084c4ddff1aa25e99c40e832396cbb8e555c9488bb245", size = 8657964, upload-time = "2026-10-11T16:12:54.071Z" }, + { url = "https://files.pythonhosted.org/packages/57/aa/d4198e1f3b69b8c2df28410a234013f1b026a5fdf159ad3097161a14c7c5/pyscipopt-6.3.0-cp311-cp311-macosx_11_0_x86_64.whl", hash = "sha256:eac50df087ecfe82a09613943df876f8cb1ba128911cc99d4ba3f5ca90eba732", size = 12435944, upload-time = "2026-10-11T16:12:56.647Z" }, + { url = "https://files.pythonhosted.org/packages/ec/c8/c0aad68c1a7da65c48c96586cfff2b48adeaf65390b1cb66cd84d1ba8979/pyscipopt-6.3.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:17bd07e48d277bbbc8f8221e399eb1ecfacd81f53c2e3744c4a8e82527735a6f", size = 17090694, upload-time = "2026-10-11T16:12:59.865Z" }, + { url = "https://files.pythonhosted.org/packages/c7/5f/501ff5a128b7ff4225bc4fdca50a019337486f7ac76620a3f233cc2d3f76/pyscipopt-6.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6e3931d84f51cb1ca6646eea900012c5455af124774221318fecd731c79c80ca", size = 18369542, upload-time = "2026-10-11T16:13:02.63Z" }, + { url = "https://files.pythonhosted.org/packages/8e/ba/405962d0e1c6a4f922ace4ffbcbe9322c704988ac1149bef0052d325ee19/pyscipopt-6.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:251266f21b58df8c2c005cbbca49c0bbbb1d4c7a4cdb2c9ff57e4ae5c2df100c", size = 48297135, upload-time = "2026-10-11T16:13:08.069Z" }, + { url = "https://files.pythonhosted.org/packages/31/5e/38b5aee3402d00f1a452e33b67cd64fbb17985e8f73087cf5648c6c21d3d/pyscipopt-6.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:401ecfbc57bdc049a04bb9181d5b741faa3432405ba147b7cc58b5e52c6f4487", size = 8662298, upload-time = "2026-10-11T16:13:10.879Z" }, + { url = "https://files.pythonhosted.org/packages/d9/b7/c239aa85a160b91c9d3703aaa796d3b64d82d2ef02eeceefaa603d432bff/pyscipopt-6.3.0-cp312-cp312-macosx_11_0_x86_64.whl", hash = "sha256:fda5b59ed1520f18a046387bd72291f80aff816621d1a2a40659a49ffdc78cd3", size = 12416268, upload-time = "2026-10-11T16:13:13.448Z" }, + { url = "https://files.pythonhosted.org/packages/c4/a8/f232f5040721b488532d46eaee2ff15cfb20d6578437c3475673ddc72b2d/pyscipopt-6.3.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:470b449d6fe0e1746a86789d17ce2df9a3357136a0522ea6c214c1b19b4c29a4", size = 16826121, upload-time = "2026-10-11T16:13:16.139Z" }, + { url = "https://files.pythonhosted.org/packages/92/c6/44d60da93c069f4a26ac3d43e85cf07835fc535232f2eeafe07632e2b160/pyscipopt-6.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f1c6696a58be7e088017a57982dc9d8a681da3f21bdca1d74fba2d41b47f5fbe", size = 18182683, upload-time = "2026-10-11T16:13:19.122Z" }, + { url = "https://files.pythonhosted.org/packages/f8/38/80617dfc24d038976266825565aeefcf01526ae4d5758927a050015ed1d2/pyscipopt-6.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:7aaa698983070c4e0b30d77c3bf3db84721f8174668b4f495abc78f51dbdd2af", size = 48251320, upload-time = "2026-10-11T16:13:23.645Z" }, + { url = "https://files.pythonhosted.org/packages/df/69/d376543f4505b439231ae9ddc5766008f456c520f88b8109e298a6903103/pyscipopt-6.3.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:56df32929ca82daa1c0b824480fab44f4688bb1c06b1b8e6144557825e3c4fe2", size = 8674076, upload-time = "2026-10-11T16:13:26.479Z" }, + { url = "https://files.pythonhosted.org/packages/a8/a3/a0ab8222eea9f85968590f38301fc7acac19515f649db1294eb2a3e48123/pyscipopt-6.3.0-cp313-cp313-macosx_11_0_x86_64.whl", hash = "sha256:6d8b28f077eb56df7033dfbbf08a60af38887ea55d23d9e81426bfb887aa2718", size = 12431507, upload-time = "2026-10-11T16:13:28.965Z" }, + { url = "https://files.pythonhosted.org/packages/7e/92/92ec1d8c4c15a31b5351fad6b84298e48b17520715fe9e8ae90b7e02f112/pyscipopt-6.3.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:19c5f1a174cbe5a3216f2a6b63457b7c54cf0313b54cd461436a5a908cec9f52", size = 16833262, upload-time = "2026-10-11T16:13:32.08Z" }, + { url = "https://files.pythonhosted.org/packages/3c/fc/247d5e524500a334283c3c3ca067c525bd8bf9e6570b00586c91b5e4aaf8/pyscipopt-6.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0761e4cda7a0a94c75e6faaefe0b921a117c4cfd7dbd8b7e9bc9665f6c68ef3b", size = 18183962, upload-time = "2026-10-11T16:13:34.839Z" }, + { url = "https://files.pythonhosted.org/packages/cd/94/489399c8cf91d523587c319312897117349f36f5ad4f2f63e6929bbec0fe/pyscipopt-6.3.0-cp313-cp313-win_amd64.whl", hash = "sha256:7910abd7fd9cb1e97816fef5fc7aed085308a7cc097b10c3efdecfee71e432e7", size = 48249883, upload-time = "2026-10-11T16:13:39.182Z" }, + { url = "https://files.pythonhosted.org/packages/be/a3/05e4931d2ca8b7d16ab081685fd9f8bcd8874080e702526d0cba7cf5b33f/pyscipopt-6.3.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:34f542f690eacd54b079cc415605af77e324b76e168c4ea4292430e5f071e32f", size = 8694895, upload-time = "2026-10-11T16:13:41.794Z" }, + { url = "https://files.pythonhosted.org/packages/04/de/2f862e50ae89b4d401f28384ea0f1ba54ca610299fcbe231e1040ac3dd4e/pyscipopt-6.3.0-cp314-cp314-macosx_11_0_x86_64.whl", hash = "sha256:542c12eb1a69a34c397dc4f38afbdefd389beb36e7a6bc9c9c91ffc031fb630e", size = 12442377, upload-time = "2026-10-11T16:13:44.065Z" }, + { url = "https://files.pythonhosted.org/packages/55/b6/4f2d2f2a683ed2e09f72a3af21dd4351de8983458869f9be06326f5bc966/pyscipopt-6.3.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f9b95ef1966903d7be4fa928f7579dad99fc56a7a39298403cb916bff379f3ff", size = 16791202, upload-time = "2026-10-11T16:13:46.853Z" }, + { url = "https://files.pythonhosted.org/packages/30/d3/9bb1e97aaa1f215ca909900a4ebc8718fbba72a3d3911198219378986f55/pyscipopt-6.3.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0a6e33a62b477a5ed78393784a0b6f78d04a004f2bcfda9cb56058407ee9ba84", size = 18063929, upload-time = "2026-10-11T16:13:49.599Z" }, + { url = "https://files.pythonhosted.org/packages/53/7d/c12136479893e0ee144a050f13d111b7a83b5e2aaf37a1a253169ef66744/pyscipopt-6.3.0-cp314-cp314-win_amd64.whl", hash = "sha256:266cce2a6712cd4c5fe5d7feaf1002d7ee5e724616b153c3529ecd60c7d087e7", size = 49412054, upload-time = "2026-10-11T16:13:53.788Z" }, + { url = "https://files.pythonhosted.org/packages/32/f1/d61a6c176c229fdc7aefaace8a33da4bf3c74e5886a732b4de73f9519cc0/pyscipopt-6.3.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:d3589a00c62c1219641754f69ef903a4189b50d02a0ea8ef96931fc699a95b21", size = 8767403, upload-time = "2026-10-11T16:13:56.481Z" }, + { url = "https://files.pythonhosted.org/packages/ea/e4/9538ed3100709bf3215bf17f8a4e558a2235bdb00adc2c20a781218ef930/pyscipopt-6.3.0-cp314-cp314t-macosx_11_0_x86_64.whl", hash = "sha256:4f0c4fda99f6a9ce668aa887052bf56b1860a0c5539491b07a5d431144f9275e", size = 12474734, upload-time = "2026-10-11T16:13:58.867Z" }, + { url = "https://files.pythonhosted.org/packages/f3/b9/d5ac3d4ac020b71b2c2eeb1bb671cf7bec9dc1230a54d4bdf6d013752249/pyscipopt-6.3.0-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:15a9fd691e3e75c6bf75f1cc4bf8e6acdaf4aa8b02570a1609f6eb3dcac4b23d", size = 17426471, upload-time = "2026-10-11T16:14:01.664Z" }, + { url = "https://files.pythonhosted.org/packages/78/bf/0c2c63513fd86c327b04742c052c4386695d93966767e1aa52dc76a2c56e/pyscipopt-6.3.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:69ea80f981b4e7d5f2bb74cb600e8a9ebf8e8df54a7afe5f8a715172bb8681b9", size = 18285434, upload-time = "2026-10-11T16:14:04.578Z" }, + { url = "https://files.pythonhosted.org/packages/e7/41/4710d0d81b16fa4cd2e412f5636ff50a05878ccb9d2e9aacef20cc1feae8/pyscipopt-6.3.0-cp314-cp314t-win_amd64.whl", hash = "sha256:e1005ecf03f3dbd3936485343ab79c85db7d27d296516787a2223cd84f143747", size = 49443593, upload-time = "2026-10-11T16:14:08.909Z" }, + { url = "https://files.pythonhosted.org/packages/7e/3b/72d1a15488a6747997682774618dd68b5c03e83133973735c0c630dd9e79/pyscipopt-6.3.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:0b2737c33fd4d0402d83745dda04ac1740e18d01d3f8cdddb6d95b31980799c5", size = 8693806, upload-time = "2026-10-11T16:14:11.485Z" }, + { url = "https://files.pythonhosted.org/packages/c7/6f/1e0cfbea83e9c7721cc76e56292070e13050b8c403cd80dd615784c7ec50/pyscipopt-6.3.0-cp315-cp315-macosx_11_0_x86_64.whl", hash = "sha256:6c0b80ede0fb3028ca1e38321d50dcc08ce27754227ae1010be3f079fc480df3", size = 12440937, upload-time = "2026-10-11T16:14:13.775Z" }, + { url = "https://files.pythonhosted.org/packages/13/9e/0706827a5ec459de1991f6495240e6c24d2bfb405dbdf3d58d3345100c6b/pyscipopt-6.3.0-cp315-cp315-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f4992167acdb55c02ca44057e406098ded35f3c07d0fcf27775a767ec9f0857e", size = 16784377, upload-time = "2026-10-11T16:14:16.203Z" }, + { url = "https://files.pythonhosted.org/packages/eb/fb/770dccdcca94bb19f6a86d9fa2decf9c423ea246e67b3c79ee2d266d4764/pyscipopt-6.3.0-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4c9ecceac4ef6a76adf599bf1d260745b4c6ace3e22eed3b83cb2b40a6193100", size = 18089078, upload-time = "2026-10-11T16:14:19.079Z" }, + { url = "https://files.pythonhosted.org/packages/fa/7b/828f67a0ff3f19faa26dcfbac96a1df018bddf87511c0635acd9bbc0ad6b/pyscipopt-6.3.0-cp315-cp315-win_amd64.whl", hash = "sha256:9e20b729a88e74bac6d13bc641278f4c5a452ae8abe1b94ab3838ea00f4eca8c", size = 49412495, upload-time = "2026-10-11T16:14:23.095Z" }, + { url = "https://files.pythonhosted.org/packages/e6/6a/9f3f2cbf6d56b99cfdb0935b950bbe344220d1b26079bc997126c5f3c19e/pyscipopt-6.3.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:cd02af2e3efb49a0feede946956f79f884210d9335f7fae10f838a597b48b631", size = 8764924, upload-time = "2026-10-11T16:14:25.821Z" }, + { url = "https://files.pythonhosted.org/packages/eb/d1/c396c13bf58e1c5dcc10aecb03207bbc3233d2940444448f002ddcd90324/pyscipopt-6.3.0-cp315-cp315t-macosx_11_0_x86_64.whl", hash = "sha256:b3382b157ed08b753d948534a2e152800fbb2bbd5c0fe12cd183d34380524e0c", size = 12472866, upload-time = "2026-10-11T16:14:27.933Z" }, + { url = "https://files.pythonhosted.org/packages/9c/14/76b60bde11dc4373a2e8aeb5af74db0f5da27584eebbd3edf663e1f5df65/pyscipopt-6.3.0-cp315-cp315t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b7ad2fbe509371ab079627f6a3c371b21dee5aa148f7ac7906f38cb53a24a0b5", size = 17389349, upload-time = "2026-10-11T16:14:30.414Z" }, + { url = "https://files.pythonhosted.org/packages/3c/f4/1f4be22e02a092f291dd3e8aaed148aac30e573af1d56f106a4ab1a170fa/pyscipopt-6.3.0-cp315-cp315t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:aa67eef05844783c41b23322071089c4f31e25bad49b7088b2e793013f59d2c1", size = 18481659, upload-time = "2026-10-11T16:14:33.171Z" }, + { url = "https://files.pythonhosted.org/packages/39/6f/1d1d8fe825170e456482573d48c901fb697709a849a277603f6bacb0cd19/pyscipopt-6.3.0-cp315-cp315t-win_amd64.whl", hash = "sha256:c8b9c8d75c66dac7de6635dec8cc61988202bda62d4c402fca1073d52dc68e4c", size = 49442904, upload-time = "2026-10-11T16:14:36.644Z" }, +] + [[package]] name = "pytensor" version = "2.38.3" @@ -2504,6 +2550,7 @@ dev = [ { name = "hypothesis", extra = ["numpy"] }, { name = "ipython" }, { name = "matplotlib" }, + { name = "pyscipopt" }, { name = "pytest" }, { name = "pytest-cov" }, { name = "pytest-rerunfailures" }, @@ -2527,6 +2574,9 @@ docs = [ { name = "sphinxcontrib-bibtex" }, { name = "sympy" }, ] +global = [ + { name = "pyscipopt" }, +] sat = [ { name = "python-sat" }, ] @@ -2573,6 +2623,8 @@ requires-dist = [ { name = "networkx", specifier = ">=2.6" }, { name = "numpy", specifier = ">=1.22" }, { name = "pymc", marker = "extra == 'bayes'", specifier = ">=5" }, + { name = "pyscipopt", marker = "extra == 'dev'", specifier = ">=5" }, + { name = "pyscipopt", marker = "extra == 'global'", specifier = ">=5" }, { name = "pytest", marker = "extra == 'dev'", specifier = ">=9.0.3" }, { name = "pytest", marker = "extra == 'test'", specifier = ">=9.0.3" }, { name = "pytest-cov", marker = "extra == 'dev'" }, @@ -2598,7 +2650,7 @@ requires-dist = [ { name = "sympy", marker = "extra == 'symbolic'", specifier = ">=1.12" }, { name = "ty", marker = "extra == 'dev'" }, ] -provides-extras = ["bayes", "capacity", "dev", "docs", "sat", "symbolic", "test", "viz"] +provides-extras = ["bayes", "capacity", "dev", "docs", "global", "sat", "symbolic", "test", "viz"] [[package]] name = "sortedcontainers"