Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# symident 0.18.2

* Under `equilibrate` with a diagonal start, reconstruction and the kernel checks take curve
samples where a direct solve of the resting balances at a random point needs msolve past short
work limits: a point is reached on a line from a forward seed at Z = 0, each condition lifted as
a power series, and the kernel in the coordinates at eps = 1 is the Padé form of the series
kernel with the state columns eliminated. Every route, relevance probes, lines and checks
included, runs on them without a resting solve at the point or msolve. `SYMIDENT_RESTCURVE`
and `SYMIDENT_NORESTCURVE` force curve samples or direct solves.
* The exact scalings are peeled also on curve samples: the state entries of a tangent are those of
the kernel vector with the same coordinate entries.
* Where a kernel at eps = 1 needs more series coefficients, the curve samples double their order
for the rest of the analysis, at most twice from `gap_order_cap`; past that the point is skipped
and `info["limits"]` says so.
* Under `equilibrate`, the Lie order certificate ranks a continued condition at a resting point drawn
forward on the component of the continuation, also on curve samples, without an error bound;
before, it ranked at the start of the continuation, where the conditions coincide, and could
certify too low a block order. The resting Jacobian is checked at the seed of a lift.
* Under `equilibrate` with a diagonal start, the Lie orders of a continued condition are scanned on
the series instead of ranked at the start of the continuation, and the field proof refuses a
continued resting state with a reason instead of failing on it.
* The forward seed takes a column basis of the rate coefficients where the direct pick of the
turnover rates is singular, as for a pool of a total that no picked rate drains.
* The diagonal start leaves out the parameters the conditions coincide without, which could remove
the only rate of a state that rests at zero and make the resting Jacobian singular.
* Under `equilibrate`, states whose right-hand sides vanish together where all of them are zero, with
a Jacobian on them invertible at generic values, rest at zero, as a single state with a linear
right-hand side does; `info["branches"]` names them and `free_initial` takes another branch.
* The method chapter states the error bound of a check on curve samples.

# symident 0.18.1

* `discrete()` closes the output pipes of every msolve call and the output file of msolve in the
Expand Down
6 changes: 6 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Diagnostic output:
the reduction solve.
``JOINTDIAG``
the joint resting-state rows.
``CURVEDIAG``
the lines and kernels at eps = 1 of curve samples.

Routes:

Expand All @@ -95,6 +97,10 @@ Routes:
no forward seed of the resting states.
``NODIAG``
no diagonal start: resting conditions continued from the forward one only.
``RESTCURVE``
curve samples of the resting conditions also where a direct solve is cheap.
``NORESTCURVE``
direct resting solves for reconstruction and checks, never curve samples.
``NOSHARED``
a tape per condition also where the conditions differ only in the values of symbols.
``NOSELECT``
Expand Down
20 changes: 19 additions & 1 deletion docs/method/conditions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ as *conjugate* where the balances have an irreducible eliminant; conjugate roots
and an eliminant irreducible at a point is irreducible over :math:`\mathbb{Q}(\theta)`. A
state rests at zero when the right-hand side, with the inputs at zero, is linear in it with a
coefficient nonzero at rest; a second branch with the state away from zero is named there and taken
by ``free_initial``.
by ``free_initial``. The same holds for a set of states whose right-hand sides all vanish where the
set is zero, an invariant face, when the Jacobian on the set is invertible at generic values; states
of a conserved total make it singular and stay off the face.

**Conserved totals.** A linear combination :math:`T = \sum_i a_i x_i` of states that the right-hand
sides conserve is a *total*; the coefficients may hold parameters, such as volumes, and the basis
Expand Down Expand Up @@ -113,6 +115,22 @@ invertible. The rank over the truncated series bounds the generic rank from belo
``info["series_certified"]`` says whether the *series order* is proven sufficient.
``SYMIDENT_NODIAG`` turns the diagonal start off.

**Curve samples.** Where a direct solve of the balances at a random point needs msolve past short
work limits, reconstruction and checks take *curve samples* instead of resting points. A point
:math:`\theta^\ast` is reached on the line :math:`\theta(\varepsilon) = \hat\theta + \varepsilon
(\theta^\ast - \hat\theta)` from a forward seed :math:`\hat z = (\hat\theta, \hat x)` at
:math:`Z = 0`: the seed of :math:`\theta^\ast` itself, whose turnover rates then move along the
line, or an earlier seed that differs from :math:`\theta^\ast` in fewer coordinates. Each
condition is lifted as above, the state columns are eliminated from the series rows, and the
kernel in the coordinates at :math:`\varepsilon = 1`, the kernel at :math:`\theta^\ast`, is the
Padé form of each entry, accepted where the known coefficients determine it with one to spare.
Only :math:`\xi_\theta` is read off: the state components follow from :math:`J_x \xi_{x_N} =
-J_\theta \xi_\theta`. Where an entry has no such form, the series order of the curve samples is
doubled for the rest of the analysis, at most twice from ``gap_order_cap``; past that the point is
skipped like a pole and ``info["limits"]`` says so. The Lie order of a continued condition is
certified at a resting point drawn forward (:ref:`sufficient-lie-order`). ``SYMIDENT_RESTCURVE``
and ``SYMIDENT_NORESTCURVE`` force curve samples or direct solves.

**Existence of a resting state.** Before the analysis the balances are solved over :math:`\mathbb{Q}`
at random rational parameter values. Balances without a complex solution raise an ``InputError``,
unless the modular decision below proves a resting state; a warning is given where no real root lies
Expand Down
7 changes: 7 additions & 0 deletions docs/method/local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ U\}`, with :math:`U` the smallest subspace for which :math:`F` stays in :math:`U
:math:`S`. This covers a start at rest, states that stay at zero, fixed initial values, and linear
relations the dynamics keeps. Under ``equilibrate`` :math:`S` is the resting variety of the
condition (:ref:`steady-states`). In both cases the rank at the start is taken at the base point.
A continued condition rests at the base point as a power series only and is ranked at a resting
point drawn forward instead: random states and parameters, the turnover rates and the states of
the plan solved from the balances. Such points are generic on one irreducible component of the
resting variety, the closure of the points where the balances are regular in these unknowns. The
continued condition lies on it where the balances are regular in them along the continuation, a
rank over :math:`\mathbb{F}_p((\varepsilon))` that a truncated series can only lower; otherwise the
order is not certified. The draw has no error bound, and ``info["order_bound_why"]`` says so.
Where the start does not reach :math:`\rho_S`, e.g., on the level set of a nonlinear conserved
quantity, the order stops after a *plateau* of three orders without change of rank
(``SYMIDENT_LIEPLATEAU``), and the result says that the Lie order is not proven sufficient.
Expand Down
23 changes: 23 additions & 0 deletions docs/method/proofs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ taken lies on one component over :math:`\mathbb{Q}(\theta)` (``info["branches"]`
with a power or exponential in the balances, a direction that the proof leaves open is ``checked``,
and ``info["bound"]`` gives the reason.

**The bound on curves.** On a curve sample (:doc:`conditions`, *Curve samples*) the check point
:math:`\theta^\ast` is still uniform modulo :math:`p`, and the resting states lie on the component
through the seed. Where the Padé form of every kernel entry is the entry itself, the check is the
check at a resting point and Equation :eq:`eq-rest-bound` applies unchanged. A Padé form from
:math:`n` coefficients is unique up to total degree :math:`(n - 3)/2`, so a wrong value at
:math:`\varepsilon = 1` needs an entry of higher degree whose coefficient at
:math:`\varepsilon^{n-1}` agrees with the form. The coefficient at :math:`\varepsilon^k` of the
lifted states is a polynomial in the seed and :math:`\zeta = \theta^\ast - \hat\theta` of degree
at most :math:`1 + 2k (d - 1)`, :math:`d = \max_i \deg f_i`, since each Newton step multiplies
by :math:`\operatorname{adj}(J_x)` over :math:`\det J_x` at the seed. For kernel entries of degree
:math:`\delta` in the states and coordinates, the agreement is a nonzero polynomial of degree at
most :math:`\delta (1 + 2 (n - 1)(d - 1))` in the drawn values, and

.. math::
:label: eq-curve-bound

\Pr\big[\text{a wrong value at } \varepsilon = 1\big] \le
\frac{n_e\, \delta \big(1 + 2 (n - 1)(d - 1)\big)}{p}

for :math:`n_e` entries read, per check point. ``info["bound"]`` holds no number for checks on
curve samples and names the reason. Proofs over :math:`\mathbb{Q}` that need :math:`J_x`
invertible on the component take the seed, where the lift requires it.

**What the bounds exclude.** The bounds above are probabilities over the points modulo :math:`p`. They
exclude the chance that :math:`p` divides the *content* of an integer identity, the greatest
common divisor of the coefficients, which then vanishes modulo :math:`p`, or that :math:`p` is
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "symident"
version = "0.18.1"
version = "0.18.2"
description = "Structural identifiability of ODE models by Lie symmetries over finite fields"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion src/symident/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"install_msolve",
"switches",
]
__version__ = "0.18.1"
__version__ = "0.18.2"
20 changes: 18 additions & 2 deletions src/symident/detection/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,21 @@ def report_physical(result, znames, aux_names, sc, nz, P, aux_field, flag_joint=
return result


def peel_scalings(scal_res, znames, nz, zval, P, N, modulo=None, shifts=()):
def _completed(t, N, cols, P):
"""The vector of the column span of N that agrees with `t` off the columns `cols`, or None."""
if not N.shape[1]:
return None
known = [i for i in range(len(t)) if i not in set(cols)]
c = _core.sym_solve_mod(np.asarray(N, dtype=np.int64)[known, :] % P, np.asarray(t)[known] % P, P)
if c is None:
return None
return (np.asarray(N, dtype=object) @ np.asarray(c, dtype=object) % P).astype(np.int64)


def peel_scalings(scal_res, znames, nz, zval, P, N, modulo=None, shifts=(), unknown=()):
"""Independent scalings of all conditions with tangent in the nullspace (modulo `modulo`), exact per entry; a
coordinate in `shifts` is translated by the weight."""
coordinate in `shifts` is translated by the weight. The tangent entries of the coordinates `unknown`, whose values
at the kernel point are not known, are those of the kernel vector that has the other entries."""
scaling = []
Bmat = np.zeros((nz, 0), dtype=np.int64)
env = {z: int(v) for z, v in zip(znames, zval)}
Expand Down Expand Up @@ -180,6 +192,10 @@ def eval_w(w):
scale = np.asarray(zval, dtype=np.int64) % P
scale[[zi[k] for k in moved]] = 1
tangent = (v * scale) % P
if unknown:
tangent = _completed(tangent, N, [zi[k] for k in unknown if k in zi], P)
if tangent is None:
continue
if modulo is not None and N.shape[1]:
free, nuis = modulo
proj = (N.astype(object) @ tangent[free].astype(object)) % P
Expand Down
40 changes: 39 additions & 1 deletion src/symident/detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,37 @@ def vanishes(e):
zero.update({spy.Symbol(k): 0 for k in new})


def _zero_face(fdyn, forcings, known=(), nonzero=()):
"""The largest set of states whose right-hand sides all vanish with the set, the inputs and `known` at zero,
with a Jacobian on the set invertible at generic values: an invariant face that rests at zero. States a left
kernel vector of that Jacobian reads, such as those of a conserved total, are left out. None of `nonzero`."""
import random

import sympy as spy

from ..sym.parse import _make_local_parse

_, parse = _make_local_parse([f"{k} = {v}" for k, v in fdyn.items()])
rhs = {k: parse(str(v).replace("^", "**")) for k, v in fdyn.items()}
base = {spy.Symbol(u): 0 for u in list(forcings) + list(known)}
face = [k for k in rhs if k not in set(forcings) | set(known) | set(nonzero) and rhs[k] != 0]
rng = random.Random(1)
while face:
at = {**base, **{spy.Symbol(k): 0 for k in face}}
keep = [k for k in face if spy.cancel(spy.together(rhs[k].xreplace(at))) == 0]
if keep != face:
face = keep
continue
J = spy.Matrix([[spy.diff(rhs[k], spy.Symbol(j)).xreplace(at) for j in face] for k in face])
vals = {x: spy.Integer(rng.randrange(2, 10**6)) for x in J.free_symbols}
left = J.xreplace(vals).T.nullspace()
if not left:
return face
drop = {face[i] for v in left for i in range(len(face)) if v[i] != 0}
face = [k for k in face if k not in drop]
return []


def _rest_zeros(fdyn, reactions, forcings, nonzero=()):
"""The states at zero at rest: those the network and the right-hand sides force, then one per branch, noted;
none of `nonzero` (``free_initial``), whose resting value is free."""
Expand All @@ -184,7 +215,14 @@ def _rest_zeros(fdyn, reactions, forcings, nonzero=()):
forced, open_ = _ode_zeros(fdyn, forcings, zero, nonzero)
zero = list(dict.fromkeys(zero + forced))
if not open_:
return zero
face = _zero_face(fdyn, forcings, zero, nonzero)
if face:
session.note(
"branches",
f"the resting states {', '.join(face)}: their right-hand sides vanish where all of them are "
"zero; the result holds for them at zero, `free_initial` takes another branch",
)
return list(dict.fromkeys(zero + face))
session.note(
"branches",
f"the resting states {', '.join(open_)}: the right-hand side of {open_[0]} "
Expand Down
2 changes: 2 additions & 0 deletions src/symident/detection/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ def field_check(setup, V, znames, leaf_names, point, chains, joint):
if sol is None:
raise RouteError("no resting state at the evaluation point")
xs = sol["sol"]["val_by"]
if sol.get("cont"):
raise RouteError("the resting states are a curve sample, not a point")
base = dict(leaf_val)
base.update({k: int(v) % P for k, v in xs.items()})
state_col = {f"{k}|c{mi + 1}" for k in xs}
Expand Down
46 changes: 36 additions & 10 deletions src/symident/detection/observability/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,14 @@ def _gap_why(self, sc):
"failed": f"no kernel past gap order {run.mtot}",
}[stop]

def _cert_segments(self, sc, p=None, tries=24):
def _cert_segments(self, sc, bases=None, p=None, tries=24):
"""The certificate inputs: chains of tapes, a seed per chain, at rest a start per chain, and the points drawn
for the seeds. At rest and a prime `p` the seeds are resting states solved modulo `p` at the first of `tries`
points uniform modulo `p`, random points of the resting variety, and the starts are those of the base
point."""
for the seeds. At rest the starts are `bases`; with a prime `p` the seeds are resting states solved modulo `p`
at the first of `tries` points uniform modulo `p`, random points of the resting variety."""
run, sys = self.run, self.sys
if self.joint:
segs = sys.chains if run.has_gaps else [[run.tapes[ci]] for ci in sys.equil_conds]
sols = [sys.solve_cond(sc["point0"], PRIMES[0], ci) for ci in sys.equil_conds]
base = [None if s0 is None else np.asarray(s0["ptc"], dtype=np.int64) % PRIMES[0] for s0 in sols]
base = list(bases)
if p is None:
return segs, base, None, 1
n = len(sc["point0"])
Expand Down Expand Up @@ -757,14 +755,24 @@ def _certificate(self, sc):
"""The Lie order per block past which the rank provably stays."""
run = self.run
P1, q = PRIMES[0], verify_prime()
degs, why = self._cert_degrees(sc)
bases, drawn = None, False
if self.joint:
got = self.sys.cert_bases(sc["point0"], P1)
if isinstance(got, str):
sc["order_bound_why"] = got
session.note("limits", f"Lie order certificate: {got}; the order is not proven")
return
bases, drawn = got
degs, why = (None, None) if drawn else self._cert_degrees(sc)
if degs is not None and any(d is None for d in degs):
degs = None
# at rest the generic ranks are taken at a random resting point modulo q, where the draws are uniform
segs, seeds, starts, rest_draws = self._cert_segments(sc, q if self.joint and degs is not None else None)
segs, seeds, starts, rest_draws = self._cert_segments(sc, bases, q if self.joint and degs is not None else None)
if self.joint and degs is not None and any(s is None for s in seeds):
segs, seeds, starts, rest_draws = self._cert_segments(sc)
segs, seeds, starts, rest_draws = self._cert_segments(sc, bases)
degs, why = None, "no resting state modulo the verification prime at the points tried"
if drawn:
why = "a continued condition is ranked at a resting point drawn forward, without an error bound"
own_threads = not run.has_gaps and not self.joint
threads = run.cores if own_threads else 1
mapf = (lambda f, xs: thread_map(f, xs, run.cores)) if threads == 1 and run.cores > 1 else None
Expand Down Expand Up @@ -1128,8 +1136,19 @@ def grows(r2):
return chosen

def _direct_kernel(self, ker_dim):
"""The kernel at a point where all conditions solve without continuation."""
"""The kernel at a point where all conditions solve without continuation, or in curve mode the series kernel
at eps = 1, the kernel at the parameters of the point."""
sc, sys, nz = self.sc, self.sys, self.nz
if sys.curve_mode():
try:
rc = self.kcall4(sc["point0"], PRIMES[0], sc["nt_used"], sc.get("mtot_used") or 0)
except Exception as e:
swallow(e, "curve kernel")
rc = {"ok": False}
if not (ok(rc) and nz - rank_of(rc) == ker_dim):
return False
sc.update(ref=rc, rank=rc["rank"], rank_s=rank_of(rc), pivots=rc["pivots"])
return True
chained = sys.chained
if chained:
sys.unchain()
Expand Down Expand Up @@ -1230,9 +1249,16 @@ def lift(w):
self.N,
modulo=(self.free_cols, self.run.nuis_cols) if self.run.nuis_cols else None,
shifts={str(r["L"]) for r in self.recast or [] if not r.get("inverted")},
unknown=self._curve_states(),
)
return peel["scaling"], peel["Bmat"]

def _curve_states(self):
"""The state columns in curve mode, whose resting values at the kernel point (eps = 1) are not known."""
if not self.joint or not self.sys.curve:
return ()
return [z for z in self.znames if z in self.zsn or "|c" in z]

def _condition_scalings(self, model_lines, obs_lines, keys, keep, known):
"""Exact scalings whose state weights differ between the resting conditions, each checked on every tape with
the state weights of the condition of the tape; those in the span of `known` are left out."""
Expand Down
Loading
Loading